Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make compare_expression: return after fetch lhs and ...



details:   https://anonhg.NetBSD.org/src/rev/e82adf4e37de
branches:  trunk
changeset: 1011760:e82adf4e37de
user:      sjg <sjg%NetBSD.org@localhost>
date:      Thu Jul 09 22:34:08 2020 +0000

description:
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

diffstat:

 usr.bin/make/cond.c                    |  11 +++++-
 usr.bin/make/unit-tests/cond-short.exp |   6 +++
 usr.bin/make/unit-tests/cond-short.mk  |  54 +++++++++++++++++++++++++++++++++-
 3 files changed, 67 insertions(+), 4 deletions(-)

diffs (119 lines):

diff -r 2e78f61edac5 -r e82adf4e37de usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Thu Jul 09 14:08:44 2020 +0000
+++ b/usr.bin/make/cond.c       Thu Jul 09 22:34:08 2020 +0000
@@ -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 @@
     if (!rhs)
        goto done;
 
+    if (!doEval) {
+       t = TOK_FALSE;
+       goto done;
+    }
+
     if (rhsQuoted || lhsQuoted) {
 do_string_compare:
        if (((*op != '!') && (*op != '=')) || (op[1] != '=')) {
diff -r 2e78f61edac5 -r e82adf4e37de usr.bin/make/unit-tests/cond-short.exp
--- a/usr.bin/make/unit-tests/cond-short.exp    Thu Jul 09 14:08:44 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-short.exp    Thu Jul 09 22:34:08 2020 +0000
@@ -7,4 +7,10 @@
 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
diff -r 2e78f61edac5 -r e82adf4e37de usr.bin/make/unit-tests/cond-short.mk
--- a/usr.bin/make/unit-tests/cond-short.mk     Thu Jul 09 14:08:44 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-short.mk     Thu Jul 09 22:34:08 2020 +0000
@@ -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 @@
 .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:
        @:;:



Home | Main Index | Thread Index | Old Index