make(1): demonstrate parse error without error message in conditionaldiff -r1.246 -r1.247 src/usr.bin/make/cond.c
(rillig)
--- 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" */ | |
98 | MAKE_RCSID("$NetBSD: cond.c,v 1.246 2021/01/21 13:51:24 rillig Exp $"); | 98 | MAKE_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 | } |
--- 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 | |||
39 | CondParser_Eval: 0${:Ux01} | 39 | CondParser_Eval: 0${:Ux01} | |
40 | make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions. | 40 | make: "cond-token-plain.mk" line 134: Numbers can be composed from literals and variable expressions. | |
41 | CondParser_Eval: "" == | 41 | CondParser_Eval: "" == | |
42 | make: "cond-token-plain.mk" line 140: warning: Missing right-hand-side of operator | 42 | make: "cond-token-plain.mk" line 140: warning: Missing right-hand-side of operator | |
43 | make: "cond-token-plain.mk" line 140: Malformed conditional ("" ==) | 43 | make: "cond-token-plain.mk" line 140: Malformed conditional ("" ==) | |
44 | CondParser_Eval: == "" | 44 | CondParser_Eval: == "" | |
45 | make: "cond-token-plain.mk" line 148: Malformed conditional (== "") | 45 | make: "cond-token-plain.mk" line 148: Malformed conditional (== "") | |
46 | CondParser_Eval: \\ | 46 | CondParser_Eval: \\ | |
47 | make: "cond-token-plain.mk" line 163: The variable '\\' is not defined. | 47 | make: "cond-token-plain.mk" line 163: The variable '\\' is not defined. | |
48 | CondParser_Eval: \\ | 48 | CondParser_Eval: \\ | |
49 | make: "cond-token-plain.mk" line 168: Now the variable '\\' is defined. | 49 | make: "cond-token-plain.mk" line 168: Now the variable '\\' is defined. | |
50 | CondParser_Eval: "unquoted\"quoted" != unquoted"quoted | 50 | CondParser_Eval: "unquoted\"quoted" != unquoted"quoted | |
51 | lhs = "unquoted"quoted", rhs = "unquoted"quoted", op = != | 51 | lhs = "unquoted"quoted", rhs = "unquoted"quoted", op = != | |
52 | CondParser_Eval: $$$$$$$$ != "" | |||
52 | make: Fatal errors encountered -- cannot continue | 53 | make: Fatal errors encountered -- cannot continue | |
53 | make: stopped in unit-tests | 54 | make: stopped in unit-tests | |
54 | exit status 1 | 55 | exit status 1 |
--- 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 | |||
183 | all: | 191 | all: | |
184 | @:; | 192 | @:; |