Thu Jan 21 14:08:09 2021 UTC ()
make(1): demonstrate parse error without error message in conditional


(rillig)
diff -r1.246 -r1.247 src/usr.bin/make/cond.c
diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/cond-token-plain.exp
diff -r1.9 -r1.10 src/usr.bin/make/unit-tests/cond-token-plain.mk

cvs diff -r1.246 -r1.247 src/usr.bin/make/cond.c (expand / switch to unified diff)

--- src/usr.bin/make/cond.c 2021/01/21 13:51:24 1.246
+++ src/usr.bin/make/cond.c 2021/01/21 14:08:09 1.247
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cond.c,v 1.246 2021/01/21 13:51:24 rillig Exp $ */ 1/* $NetBSD: cond.c,v 1.247 2021/01/21 14:08:09 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -85,27 +85,27 @@ @@ -85,27 +85,27 @@
85 * Cond_restore_depth 85 * Cond_restore_depth
86 * Save and restore the nesting of the conditions, at 86 * Save and restore the nesting of the conditions, at
87 * the start and end of including another makefile, to 87 * the start and end of including another makefile, to
88 * ensure that in each makefile the conditional 88 * ensure that in each makefile the conditional
89 * directives are well-balanced. 89 * directives are well-balanced.
90 */ 90 */
91 91
92#include <errno.h> 92#include <errno.h>
93 93
94#include "make.h" 94#include "make.h"
95#include "dir.h" 95#include "dir.h"
96 96
97/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ 97/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
98MAKE_RCSID("$NetBSD: cond.c,v 1.246 2021/01/21 13:51:24 rillig Exp $"); 98MAKE_RCSID("$NetBSD: cond.c,v 1.247 2021/01/21 14:08:09 rillig Exp $");
99 99
100/* 100/*
101 * The parsing of conditional expressions is based on this grammar: 101 * The parsing of conditional expressions is based on this grammar:
102 * Or -> And '||' Or 102 * Or -> And '||' Or
103 * Or -> And 103 * Or -> And
104 * And -> Term '&&' And 104 * And -> Term '&&' And
105 * And -> Term 105 * And -> Term
106 * Term -> Function '(' Argument ')' 106 * Term -> Function '(' Argument ')'
107 * Term -> Leaf Operator Leaf 107 * Term -> Leaf Operator Leaf
108 * Term -> Leaf 108 * Term -> Leaf
109 * Term -> '(' Or ')' 109 * Term -> '(' Or ')'
110 * Term -> '!' Term 110 * Term -> '!' Term
111 * Leaf -> "string" 111 * Leaf -> "string"
@@ -457,28 +457,36 @@ CondParser_String(CondParser *par, Boole @@ -457,28 +457,36 @@ CondParser_String(CondParser *par, Boole
457 case '$': 457 case '$':
458 /* if we are in quotes, an undefined variable is ok */ 458 /* if we are in quotes, an undefined variable is ok */
459 eflags = 459 eflags =
460 doEval && !quoted ? VARE_WANTRES | VARE_UNDEFERR : 460 doEval && !quoted ? VARE_WANTRES | VARE_UNDEFERR :
461 doEval ? VARE_WANTRES : 461 doEval ? VARE_WANTRES :
462 VARE_NONE; 462 VARE_NONE;
463 463
464 nested_p = par->p; 464 nested_p = par->p;
465 atStart = nested_p == start; 465 atStart = nested_p == start;
466 parseResult = Var_Parse(&nested_p, VAR_CMDLINE, eflags, 466 parseResult = Var_Parse(&nested_p, VAR_CMDLINE, eflags,
467 &str); 467 &str);
468 /* TODO: handle errors */ 468 /* TODO: handle errors */
469 if (str.str == var_Error) { 469 if (str.str == var_Error) {
470 if (parseResult == VPR_ERR) 470 if (parseResult == VPR_ERR) {
 471 /*
 472 * FIXME: Even if an error occurs,
 473 * there is no guarantee that it is
 474 * reported.
 475 *
 476 * See cond-token-plain.mk $$$$$$$$.
 477 */
471 par->printedError = TRUE; 478 par->printedError = TRUE;
 479 }
472 /* 480 /*
473 * XXX: Can there be any situation in which 481 * XXX: Can there be any situation in which
474 * a returned var_Error requires freeIt? 482 * a returned var_Error requires freeIt?
475 */ 483 */
476 FStr_Done(&str); 484 FStr_Done(&str);
477 /* 485 /*
478 * Even if !doEval, we still report syntax 486 * Even if !doEval, we still report syntax
479 * errors, which is what getting var_Error 487 * errors, which is what getting var_Error
480 * back with !doEval means. 488 * back with !doEval means.
481 */ 489 */
482 str = FStr_InitRefer(NULL); 490 str = FStr_InitRefer(NULL);
483 goto cleanup; 491 goto cleanup;
484 } 492 }

cvs diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/cond-token-plain.exp (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/cond-token-plain.exp 2021/01/21 13:52:32 1.6
+++ src/usr.bin/make/unit-tests/cond-token-plain.exp 2021/01/21 14:08:09 1.7
@@ -39,16 +39,17 @@ make: "cond-token-plain.mk" line 130: Nu @@ -39,16 +39,17 @@ make: "cond-token-plain.mk" line 130: Nu
39CondParser_Eval: 0${:Ux01} 39CondParser_Eval: 0${:Ux01}
40make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions. 40make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions.
41CondParser_Eval: "" == 41CondParser_Eval: "" ==
42make: "cond-token-plain.mk" line 140: warning: Missing right-hand-side of operator 42make: "cond-token-plain.mk" line 140: warning: Missing right-hand-side of operator
43make: "cond-token-plain.mk" line 140: Malformed conditional ("" ==) 43make: "cond-token-plain.mk" line 140: Malformed conditional ("" ==)
44CondParser_Eval: == "" 44CondParser_Eval: == ""
45make: "cond-token-plain.mk" line 148: Malformed conditional (== "") 45make: "cond-token-plain.mk" line 148: Malformed conditional (== "")
46CondParser_Eval: \\ 46CondParser_Eval: \\
47make: "cond-token-plain.mk" line 163: The variable '\\' is not defined. 47make: "cond-token-plain.mk" line 163: The variable '\\' is not defined.
48CondParser_Eval: \\ 48CondParser_Eval: \\
49make: "cond-token-plain.mk" line 168: Now the variable '\\' is defined. 49make: "cond-token-plain.mk" line 168: Now the variable '\\' is defined.
50CondParser_Eval: "unquoted\"quoted" != unquoted"quoted 50CondParser_Eval: "unquoted\"quoted" != unquoted"quoted
51lhs = "unquoted"quoted", rhs = "unquoted"quoted", op = != 51lhs = "unquoted"quoted", rhs = "unquoted"quoted", op = !=
 52CondParser_Eval: $$$$$$$$ != ""
52make: Fatal errors encountered -- cannot continue 53make: Fatal errors encountered -- cannot continue
53make: stopped in unit-tests 54make: stopped in unit-tests
54exit status 1 55exit status 1

cvs diff -r1.9 -r1.10 src/usr.bin/make/unit-tests/cond-token-plain.mk (expand / switch to unified diff)

--- src/usr.bin/make/unit-tests/cond-token-plain.mk 2021/01/21 13:52:32 1.9
+++ src/usr.bin/make/unit-tests/cond-token-plain.mk 2021/01/21 14:08:09 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: cond-token-plain.mk,v 1.9 2021/01/21 13:52:32 rillig Exp $ 1# $NetBSD: cond-token-plain.mk,v 1.10 2021/01/21 14:08:09 rillig Exp $
2# 2#
3# Tests for plain tokens (that is, string literals without quotes) 3# Tests for plain tokens (that is, string literals without quotes)
4# in .if conditions. 4# in .if conditions.
5 5
6.MAKEFLAGS: -dc 6.MAKEFLAGS: -dc
7 7
8.if ${:Uvalue} != value 8.if ${:Uvalue} != value
9. error 9. error
10.endif 10.endif
11 11
12# Malformed condition since comment parsing is done in an early phase 12# Malformed condition since comment parsing is done in an early phase
13# and removes the '#' and everything behind it long before the condition 13# and removes the '#' and everything behind it long before the condition
14# parser gets to see it. 14# parser gets to see it.
@@ -167,18 +167,26 @@ ${:U\\\\}= backslash @@ -167,18 +167,26 @@ ${:U\\\\}= backslash
167.if \\ 167.if \\
168. info Now the variable '\\' is defined. 168. info Now the variable '\\' is defined.
169.else 169.else
170. error 170. error
171.endif 171.endif
172 172
173# Anything that doesn't start with a double quote is considered a "bare word". 173# Anything that doesn't start with a double quote is considered a "bare word".
174# Strangely, a bare word may contain double quotes inside. Nobody should ever 174# Strangely, a bare word may contain double quotes inside. Nobody should ever
175# depend on this since it may well be unintended. See CondParser_String. 175# depend on this since it may well be unintended. See CondParser_String.
176.if "unquoted\"quoted" != unquoted"quoted 176.if "unquoted\"quoted" != unquoted"quoted
177. error 177. error
178.endif 178.endif
179 179
 180# FIXME: In CondParser_String, Var_Parse returns var_Error without a
 181# corresponding error message.
 182.if $$$$$$$$ != ""
 183. error
 184.else
 185. error
 186.endif
 187
180# See cond-token-string.mk for similar tests where the condition is enclosed 188# See cond-token-string.mk for similar tests where the condition is enclosed
181# in "quotes". 189# in "quotes".
182 190
183all: 191all:
184 @:; 192 @:;