make(1): demonstrate wrong return value in CondParser_Termdiff -r1.235 -r1.236 src/usr.bin/make/cond.c
(rillig)
--- src/usr.bin/make/cond.c 2021/01/10 21:20:46 1.235
+++ src/usr.bin/make/cond.c 2021/01/19 17:49:13 1.236
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cond.c,v 1.235 2021/01/10 21:20:46 rillig Exp $ */ | 1 | /* $NetBSD: cond.c,v 1.236 2021/01/19 17:49:13 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.235 2021/01/10 21:20:46 rillig Exp $"); | 98 | MAKE_RCSID("$NetBSD: cond.c,v 1.236 2021/01/19 17:49:13 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 | * E -> F || E | 102 | * E -> F || E | |
103 | * E -> F | 103 | * E -> F | |
104 | * F -> T && F | 104 | * F -> T && F | |
105 | * F -> T | 105 | * F -> T | |
106 | * T -> defined(variable) | 106 | * T -> defined(variable) | |
107 | * T -> make(target) | 107 | * T -> make(target) | |
108 | * T -> exists(file) | 108 | * T -> exists(file) | |
109 | * T -> empty(varspec) | 109 | * T -> empty(varspec) | |
110 | * T -> target(name) | 110 | * T -> target(name) | |
111 | * T -> commands(name) | 111 | * T -> commands(name) | |
@@ -939,26 +939,32 @@ CondParser_Term(CondParser *par, Boolean | @@ -939,26 +939,32 @@ CondParser_Term(CondParser *par, Boolean | |||
939 | if (t != TOK_ERROR) { | 939 | if (t != TOK_ERROR) { | |
940 | if (CondParser_Token(par, doEval) != TOK_RPAREN) { | 940 | if (CondParser_Token(par, doEval) != TOK_RPAREN) { | |
941 | t = TOK_ERROR; | 941 | t = TOK_ERROR; | |
942 | } | 942 | } | |
943 | } | 943 | } | |
944 | } else if (t == TOK_NOT) { | 944 | } else if (t == TOK_NOT) { | |
945 | t = CondParser_Term(par, doEval); | 945 | t = CondParser_Term(par, doEval); | |
946 | if (t == TOK_TRUE) { | 946 | if (t == TOK_TRUE) { | |
947 | t = TOK_FALSE; | 947 | t = TOK_FALSE; | |
948 | } else if (t == TOK_FALSE) { | 948 | } else if (t == TOK_FALSE) { | |
949 | t = TOK_TRUE; | 949 | t = TOK_TRUE; | |
950 | } | 950 | } | |
951 | } | 951 | } | |
952 | ||||
953 | /* | |||
954 | * FIXME: Can at least return TOK_AND, TOK_OR, TOK_RPAREN, maybe | |||
955 | * others as well. | |||
956 | */ | |||
957 | /* TODO: assert(t == TOK_ERROR); */ | |||
952 | return t; | 958 | return t; | |
953 | } | 959 | } | |
954 | 960 | |||
955 | /* | 961 | /* | |
956 | * Parse a conjunctive factor (nice name, wot?) | 962 | * Parse a conjunctive factor (nice name, wot?) | |
957 | * | 963 | * | |
958 | * F -> T && F | T | 964 | * F -> T && F | T | |
959 | * | 965 | * | |
960 | * Results: | 966 | * Results: | |
961 | * TOK_TRUE, TOK_FALSE or TOK_ERROR | 967 | * TOK_TRUE, TOK_FALSE or TOK_ERROR | |
962 | */ | 968 | */ | |
963 | static Token | 969 | static Token | |
964 | CondParser_Factor(CondParser *par, Boolean doEval) | 970 | CondParser_Factor(CondParser *par, Boolean doEval) |
--- src/usr.bin/make/unit-tests/cond-op-not.exp 2020/11/15 14:58:14 1.3
+++ src/usr.bin/make/unit-tests/cond-op-not.exp 2021/01/19 17:49:13 1.4
@@ -1,6 +1,9 @@ | @@ -1,6 +1,9 @@ | |||
1 | make: "cond-op-not.mk" line 29: Not empty evaluates to true. | 1 | make: "cond-op-not.mk" line 29: Not empty evaluates to true. | |
2 | make: "cond-op-not.mk" line 37: Not space evaluates to false. | 2 | make: "cond-op-not.mk" line 37: Not space evaluates to false. | |
3 | make: "cond-op-not.mk" line 41: Not 0 evaluates to true. | 3 | make: "cond-op-not.mk" line 41: Not 0 evaluates to true. | |
4 | make: "cond-op-not.mk" line 49: Not 1 evaluates to false. | 4 | make: "cond-op-not.mk" line 49: Not 1 evaluates to false. | |
5 | make: "cond-op-not.mk" line 55: Not word evaluates to false. | 5 | make: "cond-op-not.mk" line 55: Not word evaluates to false. | |
6 | exit status 0 | 6 | make: "cond-op-not.mk" line 59: Malformed conditional (!) | |
7 | make: Fatal errors encountered -- cannot continue | |||
8 | make: stopped in unit-tests | |||
9 | exit status 1 |
--- src/usr.bin/make/unit-tests/cond-op-parentheses.mk 2020/11/15 14:58:14 1.3
+++ src/usr.bin/make/unit-tests/cond-op-parentheses.mk 2021/01/19 17:49:13 1.4
@@ -1,19 +1,36 @@ | @@ -1,19 +1,36 @@ | |||
1 | # $NetBSD: cond-op-parentheses.mk,v 1.3 2020/11/15 14:58:14 rillig Exp $ | 1 | # $NetBSD: cond-op-parentheses.mk,v 1.4 2021/01/19 17:49:13 rillig Exp $ | |
2 | # | 2 | # | |
3 | # Tests for parentheses in .if conditions. | 3 | # Tests for parentheses in .if conditions. | |
4 | 4 | |||
5 | # TODO: Implementation | 5 | # TODO: Implementation | |
6 | 6 | |||
7 | # Test for deeply nested conditions. | 7 | # Test for deeply nested conditions. | |
8 | .if (((((((((((((((((((((((((((((((((((((((((((((((((((((((( \ | 8 | .if (((((((((((((((((((((((((((((((((((((((((((((((((((((((( \ | |
9 | (((((((((((((((((((((((((((((((((((((((((((((((((((((((( \ | 9 | (((((((((((((((((((((((((((((((((((((((((((((((((((((((( \ | |
10 | 1 \ | 10 | 1 \ | |
11 | )))))))))))))))))))))))))))))))))))))))))))))))))))))))) \ | 11 | )))))))))))))))))))))))))))))))))))))))))))))))))))))))) \ | |
12 | )))))))))))))))))))))))))))))))))))))))))))))))))))))))) | 12 | )))))))))))))))))))))))))))))))))))))))))))))))))))))))) | |
13 | . info Parentheses can be nested at least to depth 112. | 13 | . info Parentheses can be nested at least to depth 112. | |
14 | .else | 14 | .else | |
15 | . error | 15 | . error | |
16 | .endif | 16 | .endif | |
17 | 17 | |||
18 | # An unbalanced opening parenthesis is a parse error. | |||
19 | .if ( | |||
20 | . error | |||
21 | .else | |||
22 | . error | |||
23 | .endif | |||
24 | ||||
25 | # An unbalanced closing parenthesis is a parse error. | |||
26 | # | |||
27 | # As of 2021-01-19, CondParser_Term returned TOK_RPAREN even though this | |||
28 | # function promised to only ever return TOK_TRUE, TOK_FALSE or TOK_ERROR. | |||
29 | .if ) | |||
30 | . error | |||
31 | .else | |||
32 | . error | |||
33 | .endif | |||
34 | ||||
18 | all: | 35 | all: | |
19 | @:; | 36 | @:; |
--- src/usr.bin/make/unit-tests/cond-op-not.mk 2020/11/15 14:58:14 1.6
+++ src/usr.bin/make/unit-tests/cond-op-not.mk 2021/01/19 17:49:13 1.7
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | # $NetBSD: cond-op-not.mk,v 1.6 2020/11/15 14:58:14 rillig Exp $ | 1 | # $NetBSD: cond-op-not.mk,v 1.7 2021/01/19 17:49:13 rillig Exp $ | |
2 | # | 2 | # | |
3 | # Tests for the ! operator in .if conditions, which negates its argument. | 3 | # Tests for the ! operator in .if conditions, which negates its argument. | |
4 | 4 | |||
5 | # The exclamation mark negates its operand. | 5 | # The exclamation mark negates its operand. | |
6 | .if !1 | 6 | .if !1 | |
7 | . error | 7 | . error | |
8 | .endif | 8 | .endif | |
9 | 9 | |||
10 | # Exclamation marks can be chained. | 10 | # Exclamation marks can be chained. | |
11 | # This doesn't happen in practice though. | 11 | # This doesn't happen in practice though. | |
12 | .if !!!1 | 12 | .if !!!1 | |
13 | . error | 13 | . error | |
14 | .endif | 14 | .endif | |
@@ -45,15 +45,22 @@ | @@ -45,15 +45,22 @@ | |||
45 | 45 | |||
46 | .if !${:U1} | 46 | .if !${:U1} | |
47 | . info Not 1 evaluates to true. | 47 | . info Not 1 evaluates to true. | |
48 | .else | 48 | .else | |
49 | . info Not 1 evaluates to false. | 49 | . info Not 1 evaluates to false. | |
50 | .endif | 50 | .endif | |
51 | 51 | |||
52 | .if !${:Uword} | 52 | .if !${:Uword} | |
53 | . info Not word evaluates to true. | 53 | . info Not word evaluates to true. | |
54 | .else | 54 | .else | |
55 | . info Not word evaluates to false. | 55 | . info Not word evaluates to false. | |
56 | .endif | 56 | .endif | |
57 | 57 | |||
58 | # A single exclamation mark is a parse error. | |||
59 | .if ! | |||
60 | . error | |||
61 | .else | |||
62 | . error | |||
63 | .endif | |||
64 | ||||
58 | all: | 65 | all: | |
59 | @:; | 66 | @:; |
--- src/usr.bin/make/unit-tests/cond-op-parentheses.exp 2020/11/15 14:58:14 1.2
+++ src/usr.bin/make/unit-tests/cond-op-parentheses.exp 2021/01/19 17:49:13 1.3
@@ -1,2 +1,6 @@ | @@ -1,2 +1,6 @@ | |||
1 | make: "cond-op-parentheses.mk" line 13: Parentheses can be nested at least to depth 112. | 1 | make: "cond-op-parentheses.mk" line 13: Parentheses can be nested at least to depth 112. | |
2 | exit status 0 | 2 | make: "cond-op-parentheses.mk" line 19: Malformed conditional (() | |
3 | make: "cond-op-parentheses.mk" line 29: Malformed conditional ()) | |||
4 | make: Fatal errors encountered -- cannot continue | |||
5 | make: stopped in unit-tests | |||
6 | exit status 1 |