Module Name:    src
Committed By:   rillig
Date:           Thu Jul  2 13:04:09 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: cond-short.exp cond-short.mk

Log Message:
make(1): fix unnecessary evaluation of :M and :N modifiers


To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/make/var.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cond-short.exp
cvs rdiff -u -r1.4 -r1.5 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/var.c
diff -u src/usr.bin/make/var.c:1.226 src/usr.bin/make/var.c:1.227
--- src/usr.bin/make/var.c:1.226	Thu Jul  2 12:34:30 2020
+++ src/usr.bin/make/var.c	Thu Jul  2 13:04:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.226 2020/07/02 12:34:30 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.227 2020/07/02 13:04:09 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.226 2020/07/02 12:34:30 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.227 2020/07/02 13:04:09 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.226 2020/07/02 12:34:30 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.227 2020/07/02 13:04:09 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3290,7 +3290,7 @@ ApplyModifiers(char *nstr, const char *t
 		     * expand it.
 		     */
 		    cp2 = pattern;
-		    pattern = Var_Subst(NULL, cp2, ctxt, flags | VARF_WANTRES);
+		    pattern = Var_Subst(NULL, cp2, ctxt, flags);
 		    free(cp2);
 		}
 		if (DEBUG(VAR))

Index: src/usr.bin/make/unit-tests/cond-short.exp
diff -u src/usr.bin/make/unit-tests/cond-short.exp:1.5 src/usr.bin/make/unit-tests/cond-short.exp:1.6
--- src/usr.bin/make/unit-tests/cond-short.exp:1.5	Thu Jul  2 12:37:18 2020
+++ src/usr.bin/make/unit-tests/cond-short.exp	Thu Jul  2 13:04:09 2020
@@ -3,7 +3,7 @@ expected and exists
 expected and empty
 expected U23 condition
 expected VAR23
-unexpected M pattern
+expected M pattern
 expected or
 expected or exists
 expected or empty

Index: src/usr.bin/make/unit-tests/cond-short.mk
diff -u src/usr.bin/make/unit-tests/cond-short.mk:1.4 src/usr.bin/make/unit-tests/cond-short.mk:1.5
--- src/usr.bin/make/unit-tests/cond-short.mk:1.4	Thu Jul  2 12:37:18 2020
+++ src/usr.bin/make/unit-tests/cond-short.mk	Thu Jul  2 13:04:09 2020
@@ -1,4 +1,4 @@
-# $NetBSD: cond-short.mk,v 1.4 2020/07/02 12:37:18 rillig Exp $
+# $NetBSD: cond-short.mk,v 1.5 2020/07/02 13:04:09 rillig Exp $
 #
 # Demonstrates that in conditions, the right-hand side of an && or ||
 # is only evaluated if it can actually influence the result.
@@ -38,11 +38,16 @@ VAR=	${VAR${:U21${echo "unexpected VAR U
 VAR23=	${VAR${:U22${echo   "expected VAR23" 1>&2 :L:sh}}}
 .if 1 && !empty(VAR${:U23${echo   "expected U23 condition" 1>&2 :L:sh}})
 .endif
+VAR=	# empty again, for the following tests
 
-# FIXME: The :M modifier must only be parsed, not evaluated.
+# The :M modifier is only parsed, not evaluated.
+# Before 2020-07-02, it was wrongly evaluated.
 .if 0 && !empty(VAR:M${:U${echo "unexpected M pattern" 1>&2 :L:sh}})
 .endif
 
+.if 1 && !empty(VAR:M${:U${echo   "expected M pattern" 1>&2 :L:sh}})
+.endif
+
 # The || operator.
 
 .if 1 || ${echo "unexpected or" 1>&2 :L:sh}

Reply via email to