aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/varmod-loop-delete.mk
diff options
context:
space:
mode:
Diffstat (limited to 'unit-tests/varmod-loop-delete.mk')
-rw-r--r--unit-tests/varmod-loop-delete.mk48
1 files changed, 44 insertions, 4 deletions
diff --git a/unit-tests/varmod-loop-delete.mk b/unit-tests/varmod-loop-delete.mk
index 478a25e91f6e..7b7dc0a77b25 100644
--- a/unit-tests/varmod-loop-delete.mk
+++ b/unit-tests/varmod-loop-delete.mk
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-loop-delete.mk,v 1.7 2024/08/29 20:20:36 rillig Exp $
+# $NetBSD: varmod-loop-delete.mk,v 1.9 2026/02/09 22:04:54 rillig Exp $
#
# Tests for the variable modifier ':@', which as a side effect allows to
# delete an arbitrary variable.
@@ -11,6 +11,17 @@
#
# See Var_Parse, comment 'the value of the variable must not change'.
+all: .PHONY
+ ${MAKE} -f ${MAKEFILE} delete-active-variable || true
+ @echo
+ ${MAKE} -f ${MAKEFILE} delete-active-variable-in-target || true
+ @echo
+ # Disabled since the details of the crash depend on the execution
+ # environment.
+ #${MAKE} -f ${MAKEFILE} use-after-free
+
+delete-active-variable: .PHONY
+.if make(delete-active-variable)
# Set up the variable that deletes itself when it is evaluated.
VAR= ${:U:@VAR@@} rest of the value
@@ -18,12 +29,16 @@ VAR= ${:U:@VAR@@} rest of the value
# defined in the global scope, it deletes itself.
# expect+1: Cannot delete variable "VAR" while it is used
EVAL:= ${VAR}
-.if ${EVAL} != " rest of the value"
-. error
+. if ${EVAL} != " rest of the value"
+. error
+. endif
.endif
+delete-active-variable-in-target: .PHONY
+.if make(delete-active-variable-in-target)
VAR= ${:U:@VAR@@} rest of the value
-all: .PHONY
+
+delete-active-variable-in-target:
# In the command that is associated with a target, the scope is the
# one from the target. That scope only contains a few variables like
# '.TARGET', '.ALLSRC', '.IMPSRC'. Make does not expect that these
@@ -32,3 +47,28 @@ all: .PHONY
# There is no variable named 'VAR' in the local scope, so nothing
# happens.
: $@: '${VAR}'
+# expect: : delete-active-variable-in-target: ' rest of the value'
+.endif
+
+
+# On NetBSD 11.99.x with jemalloc and MALLOC_CONF=junk:true, the output is:
+# make: varmod-loop-delete.mk:72: Unknown modifier ":Z2"
+# while evaluating "${:U 333 :@v@...${:Z1}@:Z2}" with value "...${:Z1}"
+# while evaluating variable "INNER.1" with value "${:U 333 :@v@...${:Z1}@:Z2}"
+# while evaluating variable "ZZZZZZZZZZZZ...${:Z1}" with value "ZZZZZZZZ"
+# while evaluating "${:U 111 222 :@v@${v:S,^,${INNER.1},}@}" with value " 111 222 "
+# while evaluating variable "OUTER" with value "${:U 111 222 :@v@${v:S,^,${INNER.1},}@}"
+# in make in directory "<curdir>"
+# Modifier part: ""
+# ModifyWords: split "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" into 1 word
+# Result of ${ZZZZZZZZZZZZ:S,^,${INNER.1},} is "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" (eval-keep-undefined, regular)
+# Segmentation fault (core dumped)
+use-after-free: .PHONY
+.if make(use-after-free)
+OUTER= ${:U 111 222 :@v@${v:S,^,${INNER.1},}@}
+INNER.1= ${:U 333 :@v@...${:Z1}@:Z2}
+
+.MAKEFLAGS: -dcpv
+_:= ${OUTER}
+.MAKEFLAGS: -d0
+.endif