Module Name: src
Committed By: sjg
Date: Thu Jul 9 22:34:09 UTC 2020
Modified Files:
src/usr.bin/make: cond.c
src/usr.bin/make/unit-tests: cond-short.exp cond-short.mk
Log Message:
compare_expression: return after fetch lhs and rhs if !doEval
Otherwise we end up throwing warings/errors for valid
conditionals due to not expanding variables fully.
Add tests to catch this.
Reviewed by: rillig
To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/make/cond.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/cond-short.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/cond-short.mk
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.78 src/usr.bin/make/cond.c:1.79
--- src/usr.bin/make/cond.c:1.78 Fri Jul 3 08:13:23 2020
+++ src/usr.bin/make/cond.c Thu Jul 9 22:34:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.78 2020/07/03 08:13:23 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.79 2020/07/09 22:34:08 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.78 2020/07/03 08:13:23 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.79 2020/07/09 22:34:08 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
#else
-__RCSID("$NetBSD: cond.c,v 1.78 2020/07/03 08:13:23 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.79 2020/07/09 22:34:08 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -736,6 +736,11 @@ compare_expression(Boolean doEval)
if (!rhs)
goto done;
+ if (!doEval) {
+ t = TOK_FALSE;
+ goto done;
+ }
+
if (rhsQuoted || lhsQuoted) {
do_string_compare:
if (((*op != '!') && (*op != '=')) || (op[1] != '=')) {
Index: src/usr.bin/make/unit-tests/cond-short.exp
diff -u src/usr.bin/make/unit-tests/cond-short.exp:1.9 src/usr.bin/make/unit-tests/cond-short.exp:1.10
--- src/usr.bin/make/unit-tests/cond-short.exp:1.9 Thu Jul 2 16:52:34 2020
+++ src/usr.bin/make/unit-tests/cond-short.exp Thu Jul 9 22:34:09 2020
@@ -7,4 +7,10 @@ expected M pattern
expected or
expected or exists
expected or empty
+defined(V42) && 42 > 0: Ok
+defined(V66) && ( "" < 42 ): Ok
+1 || 42 < 42: Ok
+1 || < 42: Ok
+0 || 42 <= 42: Ok
+0 || < 42: Ok
exit status 0
Index: src/usr.bin/make/unit-tests/cond-short.mk
diff -u src/usr.bin/make/unit-tests/cond-short.mk:1.6 src/usr.bin/make/unit-tests/cond-short.mk:1.7
--- src/usr.bin/make/unit-tests/cond-short.mk:1.6 Thu Jul 2 16:37:56 2020
+++ src/usr.bin/make/unit-tests/cond-short.mk Thu Jul 9 22:34:09 2020
@@ -1,4 +1,4 @@
-# $NetBSD: cond-short.mk,v 1.6 2020/07/02 16:37:56 rillig Exp $
+# $NetBSD: cond-short.mk,v 1.7 2020/07/09 22:34:09 sjg Exp $
#
# Demonstrates that in conditions, the right-hand side of an && or ||
# is only evaluated if it can actually influence the result.
@@ -97,5 +97,57 @@ VAR= # empty again, for the following te
.elif ${echo "unexpected nested or" 1>&2 :L:sh}
.endif
+# make sure these do not cause complaint
+#.MAKEFLAGS: -dc
+
+V42 = 42
+iV1 = ${V42}
+iV2 = ${V66}
+
+.if defined(V42) && ${V42} > 0
+x=Ok
+.else
+x=Fail
+.endif
+x!= echo 'defined(V42) && ${V42} > 0: $x' >&2; echo
+# this one throws both String comparison operator and
+# Malformed conditional with cond.c 1.78
+# indirect iV2 would expand to "" and treated as 0
+.if defined(V66) && ( ${iV2} < ${V42} )
+x=Fail
+.else
+x=Ok
+.endif
+x!= echo 'defined(V66) && ( "${iV2}" < ${V42} ): $x' >&2; echo
+# next two thow String comparison operator with cond.c 1.78
+# indirect iV1 would expand to 42
+.if 1 || ${iV1} < ${V42}
+x=Ok
+.else
+x=Fail
+.endif
+x!= echo '1 || ${iV1} < ${V42}: $x' >&2; echo
+.if 1 || ${iV2:U2} < ${V42}
+x=Ok
+.else
+x=Fail
+.endif
+x!= echo '1 || ${iV2:U2} < ${V42}: $x' >&2; echo
+# the same expressions are fine when the lhs is expanded
+# ${iV1} expands to 42
+.if 0 || ${iV1} <= ${V42}
+x=Ok
+.else
+x=Fail
+.endif
+x!= echo '0 || ${iV1} <= ${V42}: $x' >&2; echo
+# ${iV2:U2} expands to 2
+.if 0 || ${iV2:U2} < ${V42}
+x=Ok
+.else
+x=Fail
+.endif
+x!= echo '0 || ${iV2:U2} < ${V42}: $x' >&2; echo
+
all:
@:;: