make: do not evaluate indirect modifiers in parse-only mode

Discovered by sjg.
This commit is contained in:
rillig 2024-02-04 10:03:10 +00:00
parent 86d09a000c
commit 68c43e85ca
3 changed files with 8 additions and 21 deletions

View File

@ -38,12 +38,6 @@ Parsing line 197: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
Global: .MAKEFLAGS = -r -k -d 0 -d pv -d
Global: .MAKEFLAGS = -r -k -d 0 -d pv -d 0
make: "varmod-indirect.mk" line 275: Unknown modifier "Z"
make: "varmod-indirect.mk" line 275: Malformed conditional (0 && ${VAR:${M_invalid}})
make: "varmod-indirect.mk" line 282: Unknown modifier "Z"
make: "varmod-indirect.mk" line 282: Malformed conditional (0 && ${VAR:${M_invalid:S,^,N*,:ts:}})
make: "varmod-indirect.mk" line 288: Unknown modifier "Z"
make: "varmod-indirect.mk" line 288: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1

View File

@ -1,4 +1,4 @@
# $NetBSD: varmod-indirect.mk,v 1.17 2024/02/04 09:56:24 rillig Exp $
# $NetBSD: varmod-indirect.mk,v 1.18 2024/02/04 10:03:10 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
@ -258,7 +258,7 @@ _:= before ${UNDEF:${:UZ}} after
# In parse-only mode, the indirect modifiers must not be evaluated.
#
# Before var.c TODO from 2024-02-04, the expression for an indirect modifier
# Before var.c 1.1098 from 2024-02-04, the expression for an indirect modifier
# was partially evaluated (only the variable value, without applying any
# modifiers) and then interpreted as modifiers to the main expression.
#
@ -270,20 +270,13 @@ _:= before ${UNDEF:${:UZ}} after
# The expression ${M_invalid} starts with the value "Z", which is an unknown
# modifier. Trying to apply this unknown modifier generated a warning.
M_invalid= Z
# expect+2: Unknown modifier "Z"
# expect+1: Malformed conditional (0 && ${VAR:${M_invalid}})
.if 0 && ${VAR:${M_invalid}}
.endif
# The expression ${M_invalid} starts with the value "Z", and if its modifiers
# were evaluated, would result in "N*Z", which is a valid modifier. The
# modifiers were not applied though, keeping the invalid value "Z".
# expect+2: Unknown modifier "Z"
# expect+1: Malformed conditional (0 && ${VAR:${M_invalid:S,^,N*,:ts:}})
# The ':S' modifier does not change the expression value in parse-only mode,
# keeping the "Z", which is then skipped in parse-only mode.
.if 0 && ${VAR:${M_invalid:S,^,N*,:ts:}}
.endif
# The ':@' modifier does not change the expression value in parse-only mode,
# keeping the "Z".
# expect+2: Unknown modifier "Z"
# expect+1: Malformed conditional (0 && ${VAR:${M_invalid:@m@N*$m@:ts:}})
# keeping the "Z", which is then skipped in parse-only mode.
.if 0 && ${VAR:${M_invalid:@m@N*$m@:ts:}}
.endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 rillig Exp $ */
/* $NetBSD: var.c,v 1.1098 2024/02/04 10:03:10 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -139,7 +139,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: var.c,v 1.1097 2024/02/04 09:56:24 rillig Exp $");
MAKE_RCSID("$NetBSD: var.c,v 1.1098 2024/02/04 10:03:10 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@ -3863,7 +3863,7 @@ ApplyModifiersIndirect(ModChain *ch, const char **pp)
DEBUG3(VAR, "Indirect modifier \"%s\" from \"%.*s\"\n",
mods.str, (int)(p - *pp), *pp);
if (mods.str[0] != '\0') {
if (ModChain_ShouldEval(ch) && mods.str[0] != '\0') {
const char *modsp = mods.str;
ApplyModifiers(expr, &modsp, '\0', '\0');
if (Expr_Str(expr) == var_Error || *modsp != '\0') {