Module Name: src Committed By: rillig Date: Tue Feb 14 20:49:09 UTC 2023
Modified Files: src/usr.bin/make: cond.c src/usr.bin/make/unit-tests: cond-token-plain.exp cond-token-plain.mk cond-undef-lint.exp opt-debug-lint.exp Log Message: make: don't interpret the return value of Var_Parse The return value of Var_Parse is largely redundant to the returned string. The idea behind the type VarParseResult was to migrate all call sites to checking this return value instead of the returned string, but that hasn't happened. Instead, the additional type only added more complexity. There was a single place where that return value was actually used, when parsing conditions. And even in that case, ignoring the VarParseResult added back an error message that previously hid bugs, in the test cond-token-plain.mk. Even though these error messages are redundant in the other tests, they don't hurt as they don't happen often. To generate a diff of this commit: cvs rdiff -u -r1.342 -r1.343 src/usr.bin/make/cond.c cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/cond-token-plain.exp cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/cond-token-plain.mk \ src/usr.bin/make/unit-tests/opt-debug-lint.exp cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-undef-lint.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/cond.c diff -u src/usr.bin/make/cond.c:1.342 src/usr.bin/make/cond.c:1.343 --- src/usr.bin/make/cond.c:1.342 Sat Sep 24 16:13:48 2022 +++ src/usr.bin/make/cond.c Tue Feb 14 20:49:09 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.342 2022/09/24 16:13:48 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.343 2023/02/14 20:49:09 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -92,7 +92,7 @@ #include "dir.h" /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: cond.c,v 1.342 2022/09/24 16:13:48 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.343 2023/02/14 20:49:09 rillig Exp $"); /* * Conditional expressions conform to this grammar: @@ -380,7 +380,9 @@ is_separator(char ch) /* * In a quoted or unquoted string literal or a number, parse a variable - * expression. + * expression and add its value to the buffer. + * + * Return whether to continue parsing the leaf. * * Example: .if x${CENTER}y == "${PREFIX}${SUFFIX}" || 0x${HEX} */ @@ -392,7 +394,6 @@ CondParser_StringExpr(CondParser *par, c VarEvalMode emode; const char *p; bool atStart; - VarParseResult parseResult; emode = doEval && quoted ? VARE_WANTRES : doEval ? VARE_UNDEFERR @@ -400,27 +401,10 @@ CondParser_StringExpr(CondParser *par, c p = par->p; atStart = p == start; - parseResult = Var_Parse(&p, SCOPE_CMDLINE, emode, inout_str); + (void)Var_Parse(&p, SCOPE_CMDLINE, emode, inout_str); /* TODO: handle errors */ if (inout_str->str == var_Error) { - if (parseResult == VPR_ERR) { - /* - * FIXME: Even if an error occurs, there is no - * guarantee that it is reported. - * - * See cond-token-plain.mk $$$$$$$$. - */ - par->printedError = true; - } - /* - * XXX: Can there be any situation in which a returned - * var_Error needs to be freed? - */ FStr_Done(inout_str); - /* - * Even if !doEval, we still report syntax errors, which is - * what getting var_Error back with !doEval means. - */ *inout_str = FStr_InitRefer(NULL); return false; } @@ -428,8 +412,8 @@ CondParser_StringExpr(CondParser *par, c /* * If the '$' started the string literal (which means no quotes), and - * the variable expression is followed by a space, looks like a - * comparison operator or is the end of the expression, we are done. + * the expression is followed by a space, a comparison operator or + * the end of the expression, we are done. */ if (atStart && is_separator(par->p[0])) return false; Index: src/usr.bin/make/unit-tests/cond-token-plain.exp diff -u src/usr.bin/make/unit-tests/cond-token-plain.exp:1.17 src/usr.bin/make/unit-tests/cond-token-plain.exp:1.18 --- src/usr.bin/make/unit-tests/cond-token-plain.exp:1.17 Sun Sep 25 12:51:37 2022 +++ src/usr.bin/make/unit-tests/cond-token-plain.exp Tue Feb 14 20:49:09 2023 @@ -49,6 +49,7 @@ make: "cond-token-plain.mk" line 172: No CondParser_Eval: "unquoted\"quoted" != unquoted"quoted Comparing "unquoted"quoted" != "unquoted"quoted" CondParser_Eval: $$$$$$$$ != "" +make: "cond-token-plain.mk" line 186: Malformed conditional ($$$$$$$$ != "") CondParser_Eval: left == right make: "cond-token-plain.mk" line 195: Malformed conditional (left == right) CondParser_Eval: ${0:?:} || left == right Index: src/usr.bin/make/unit-tests/cond-token-plain.mk diff -u src/usr.bin/make/unit-tests/cond-token-plain.mk:1.16 src/usr.bin/make/unit-tests/cond-token-plain.mk:1.17 --- src/usr.bin/make/unit-tests/cond-token-plain.mk:1.16 Sun Sep 25 12:51:37 2022 +++ src/usr.bin/make/unit-tests/cond-token-plain.mk Tue Feb 14 20:49:09 2023 @@ -1,4 +1,4 @@ -# $NetBSD: cond-token-plain.mk,v 1.16 2022/09/25 12:51:37 rillig Exp $ +# $NetBSD: cond-token-plain.mk,v 1.17 2023/02/14 20:49:09 rillig Exp $ # # Tests for plain tokens (that is, string literals without quotes) # in .if conditions. These are also called bare words. @@ -89,7 +89,7 @@ # a coincidence that the '!' is both used in the '!=' comparison operator # as well as for negating a comparison result. # -# The boolean operators '&' and '|' don't terminate a comparison operand. +# The characters '&' and '|' are part of the comparison operand. .if ${:Uvar}&&name != "var&&name" . error .endif @@ -97,8 +97,8 @@ . error .endif -# A bare word may appear alone in a condition, without any comparison -# operator. It is implicitly converted into defined(bare). +# A bare word may occur alone in a condition, without any comparison +# operator. It is interpreted as the function call 'defined(bare)'. .if bare . error .else Index: src/usr.bin/make/unit-tests/opt-debug-lint.exp diff -u src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.16 src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.17 --- src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.16 Sun Mar 14 10:57:12 2021 +++ src/usr.bin/make/unit-tests/opt-debug-lint.exp Tue Feb 14 20:49:09 2023 @@ -1,5 +1,7 @@ make: "opt-debug-lint.mk" line 19: Variable "X" is undefined +make: "opt-debug-lint.mk" line 19: Malformed conditional ($X) make: "opt-debug-lint.mk" line 41: Variable "UNDEF" is undefined +make: "opt-debug-lint.mk" line 41: Malformed conditional (${UNDEF}) make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "L" make: "opt-debug-lint.mk" line 61: Missing delimiter ':' after modifier "P" make: "opt-debug-lint.mk" line 69: Unknown modifier "${" Index: src/usr.bin/make/unit-tests/cond-undef-lint.exp diff -u src/usr.bin/make/unit-tests/cond-undef-lint.exp:1.4 src/usr.bin/make/unit-tests/cond-undef-lint.exp:1.5 --- src/usr.bin/make/unit-tests/cond-undef-lint.exp:1.4 Sun Nov 15 14:58:14 2020 +++ src/usr.bin/make/unit-tests/cond-undef-lint.exp Tue Feb 14 20:49:09 2023 @@ -1,7 +1,10 @@ make: "cond-undef-lint.mk" line 23: Variable "UNDEF" is undefined +make: "cond-undef-lint.mk" line 23: Malformed conditional (${UNDEF}) make: "cond-undef-lint.mk" line 38: Variable "UNDEF" is undefined make: "cond-undef-lint.mk" line 38: Variable "VAR." is undefined +make: "cond-undef-lint.mk" line 38: Malformed conditional (${VAR.${UNDEF}}) make: "cond-undef-lint.mk" line 49: Variable "VAR.defined" is undefined +make: "cond-undef-lint.mk" line 49: Malformed conditional (${VAR.${DEF}}) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1