Module Name:    src
Committed By:   rillig
Date:           Sun Dec 27 16:31:58 UTC 2020

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

Log Message:
make(1): remove dead code from ApplyModifiersIndirect

At that point, the expression can never be varUndefined.  At the
beginning of ParseVarnameLong, the expression is initialized to a simple
empty string, and that string is only ever converted to varUndefined at
the very end of Var_Parse.


To generate a diff of this commit:
cvs rdiff -u -r1.772 -r1.773 src/usr.bin/make/var.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-indirect.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-indirect.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.772 src/usr.bin/make/var.c:1.773
--- src/usr.bin/make/var.c:1.772	Sun Dec 27 14:41:25 2020
+++ src/usr.bin/make/var.c	Sun Dec 27 16:31:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.772 2020/12/27 14:41:25 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.773 2020/12/27 16:31:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.772 2020/12/27 14:41:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.773 2020/12/27 16:31:58 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -3473,8 +3473,7 @@ ApplyModifiersIndirect(ApplyModifiersSta
 		FStr newVal = ApplyModifiers(&modsp, *inout_value, '\0', '\0',
 		    st->var, &st->exprFlags, st->ctxt, st->eflags);
 		*inout_value = newVal;
-		if (newVal.str == var_Error || newVal.str == varUndefined ||
-		    *modsp != '\0') {
+		if (newVal.str == var_Error || *modsp != '\0') {
 			FStr_Done(&mods);
 			*pp = p;
 			return AMIR_OUT;	/* error already reported */

Index: src/usr.bin/make/unit-tests/varmod-indirect.exp
diff -u src/usr.bin/make/unit-tests/varmod-indirect.exp:1.3 src/usr.bin/make/unit-tests/varmod-indirect.exp:1.4
--- src/usr.bin/make/unit-tests/varmod-indirect.exp:1.3	Sun Dec 20 19:47:34 2020
+++ src/usr.bin/make/unit-tests/varmod-indirect.exp	Sun Dec 27 16:31:58 2020
@@ -1,4 +1,8 @@
 make: "varmod-indirect.mk" line 13: Unknown modifier '$'
+make: "varmod-indirect.mk" line 106: before
+make: "varmod-indirect.mk" line 106: after
+make: "varmod-indirect.mk" line 112: before
+make: "varmod-indirect.mk" line 112: after
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod-indirect.mk
diff -u src/usr.bin/make/unit-tests/varmod-indirect.mk:1.2 src/usr.bin/make/unit-tests/varmod-indirect.mk:1.3
--- src/usr.bin/make/unit-tests/varmod-indirect.mk:1.2	Sun Dec 20 19:29:06 2020
+++ src/usr.bin/make/unit-tests/varmod-indirect.mk	Sun Dec 27 16:31:58 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.2 2020/12/20 19:29:06 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.3 2020/12/27 16:31:58 rillig Exp $
 #
 # Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
 # These can be used for very basic purposes like converting a string to either
@@ -99,4 +99,17 @@ M_NoPrimes=	${PRIMES:${M_ListToSkip}}
 .endif
 .MAKEFLAGS: -d0
 
+
+# In contrast to the .if conditions, the .for loop allows undefined variable
+# expressions.  These expressions expand to empty strings.
+.for var in before ${UNDEF} ${UNDEF:${:US,a,a,}} after
+.  info ${var}
+.endfor
+
+# Even in an indirect modifier based on an undefined variable, the value of
+# the expression in Var_Parse is a simple empty string.
+.for var in before ${UNDEF} ${UNDEF:${:U}} after
+.  info ${var}
+.endfor
+
 all:

Reply via email to