Module Name:    src
Committed By:   rillig
Date:           Wed Sep 30 05:58:22 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: vardebug.exp varmod-l-name-to-value.exp

Log Message:
make(1): fix bug in evaluation of indirect variable modifiers

Since 2020-09-22, when indirect variable modifiers were applied to a
variable expression based on an undefined variable, these modifiers did
not change the state of a variable expression from undefined to defined.
The modifiers that do this are :D, :U, :L, :P.  Minimal example:

        ${VARNAME:${:UL}}

The :L modifier from the inner expression sets the value of the outer
expression to its variable name, in this case "VARNAME".  The outer
expression was not marked as being defined though, which resulted in a
"Malformed conditional" error.

In the commit from 2020-09-22, vardebug.exp had changed a lot, and I had
not inspected the change closely.  The important detail was in lines 56
and 60, where VAR_JUNK|VAR_KEEP changed into VEF_UNDEF, thereby losing
the VEF_DEF bit.


To generate a diff of this commit:
cvs rdiff -u -r1.553 -r1.554 src/usr.bin/make/var.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/vardebug.exp
cvs rdiff -u -r1.2 -r1.3 \
    src/usr.bin/make/unit-tests/varmod-l-name-to-value.exp

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.553 src/usr.bin/make/var.c:1.554
--- src/usr.bin/make/var.c:1.553	Tue Sep 29 19:20:08 2020
+++ src/usr.bin/make/var.c	Wed Sep 30 05:58:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.553 2020/09/29 19:20:08 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.554 2020/09/30 05:58:22 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
 #include    "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.553 2020/09/29 19:20:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.554 2020/09/30 05:58:22 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -3170,7 +3170,7 @@ ApplyModifiers(
 	    if (rval[0] != '\0') {
 		const char *rval_pp = rval;
 		st.val = ApplyModifiers(&rval_pp, st.val, '\0', '\0', v,
-					exprFlags, ctxt, eflags, freePtr);
+					&st.exprFlags, ctxt, eflags, freePtr);
 		if (st.val == var_Error
 		    || (st.val == varUndefined && !(st.eflags & VARE_UNDEFERR))
 		    || *rval_pp != '\0') {

Index: src/usr.bin/make/unit-tests/vardebug.exp
diff -u src/usr.bin/make/unit-tests/vardebug.exp:1.8 src/usr.bin/make/unit-tests/vardebug.exp:1.9
--- src/usr.bin/make/unit-tests/vardebug.exp:1.8	Tue Sep 22 06:13:39 2020
+++ src/usr.bin/make/unit-tests/vardebug.exp	Wed Sep 30 05:58:22 2020
@@ -53,11 +53,11 @@ Var_Parse: ${:UM*e}:Mvalu[e]} with VARE_
 Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
 Result of ${:UM*e} is "M*e" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
 Indirect modifier "M*e" from "${:UM*e}"
-Applying ${:M...} to "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
+Applying ${:M...} to "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
 Pattern[] for [value] is [*e]
 ModifyWords: split "value" into 1 words
 VarMatch [value] [*e]
-Result of ${:M*e} is "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
+Result of ${:M*e} is "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
 Applying ${:M...} to "value" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
 Pattern[] for [value] is [valu[e]]
 ModifyWords: split "value" into 1 words

Index: src/usr.bin/make/unit-tests/varmod-l-name-to-value.exp
diff -u src/usr.bin/make/unit-tests/varmod-l-name-to-value.exp:1.2 src/usr.bin/make/unit-tests/varmod-l-name-to-value.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-l-name-to-value.exp:1.2	Wed Sep 30 05:42:06 2020
+++ src/usr.bin/make/unit-tests/varmod-l-name-to-value.exp	Wed Sep 30 05:58:22 2020
@@ -1,4 +1 @@
-make: "varmod-l-name-to-value.mk" line 34: Malformed conditional (${value:${:UL}} == "")
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-exit status 1
+exit status 0

Reply via email to