Tue Apr 23 22:51:28 2024 UTC (38d)
make: clean up comments, code and tests


(rillig)
diff -r1.362 -r1.363 src/usr.bin/make/cond.c
diff -r1.330 -r1.331 src/usr.bin/make/make.h
diff -r1.720 -r1.721 src/usr.bin/make/parse.c
diff -r1.1104 -r1.1105 src/usr.bin/make/var.c
diff -r1.5 -r1.6 src/usr.bin/make/unit-tests/cmd-errors-jobs.exp
diff -r1.5 -r1.6 src/usr.bin/make/unit-tests/cmd-errors-lint.exp
diff -r1.5 -r1.6 src/usr.bin/make/unit-tests/cmd-errors.mk
diff -r1.3 -r1.4 src/usr.bin/make/unit-tests/cmd-errors-jobs.mk
diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/cmd-errors-lint.mk
diff -r1.8 -r1.9 src/usr.bin/make/unit-tests/cmd-errors.exp
diff -r1.8 -r1.9 src/usr.bin/make/unit-tests/cond-func-defined.exp
diff -r1.4 -r1.5 src/usr.bin/make/unit-tests/cmdline-undefined.mk
diff -r1.4 -r1.5 src/usr.bin/make/unit-tests/cmdline.mk
diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/comment.mk
diff -r1.18 -r1.19 src/usr.bin/make/unit-tests/cond-cmp-string.mk
diff -r1.11 -r1.12 src/usr.bin/make/unit-tests/cond-func-defined.mk
diff -r1.27 -r1.28 src/usr.bin/make/unit-tests/varmod-ifelse.mk
diff -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-match.exp
diff -r1.21 -r1.22 src/usr.bin/make/unit-tests/varmod-match.mk

cvs diff -r1.362 -r1.363 src/usr.bin/make/cond.c (expand / switch to context diff)
--- src/usr.bin/make/cond.c 2024/02/07 07:21:22 1.362
+++ src/usr.bin/make/cond.c 2024/04/23 22:51:28 1.363
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.362 2024/02/07 07:21:22 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.363 2024/04/23 22:51:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -91,7 +91,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.362 2024/02/07 07:21:22 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.363 2024/04/23 22:51:28 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -424,13 +424,12 @@
  * Parse a string from an expression or an optionally quoted string,
  * on the left-hand and right-hand sides of comparisons.
  *
- * Results:
- *	Returns the string without any enclosing quotes, or NULL on error.
- *	Sets out_quoted if the leaf was a quoted string literal.
+ * Return the string without any enclosing quotes, or NULL on error.
+ * Sets out_quoted if the leaf was a quoted string literal.
  */
-static void
+static FStr
 CondParser_Leaf(CondParser *par, bool doEval, bool unquotedOK,
-		  FStr *out_str, bool *out_quoted)
+		bool *out_quoted)
 {
 	Buffer buf;
 	FStr str;
@@ -492,7 +491,7 @@
 	buf.data = NULL;
 return_str:
 	Buf_Done(&buf);
-	*out_str = str;
+	return str;
 }
 
 /*
@@ -602,7 +601,7 @@
 	ComparisonOp op;
 	bool lhsQuoted, rhsQuoted;
 
-	CondParser_Leaf(par, doEval, par->leftUnquotedOK, &lhs, &lhsQuoted);
+	lhs = CondParser_Leaf(par, doEval, par->leftUnquotedOK, &lhsQuoted);
 	if (lhs.str == NULL)
 		goto done_lhs;
 
@@ -622,7 +621,7 @@
 		goto done_lhs;
 	}
 
-	CondParser_Leaf(par, doEval, true, &rhs, &rhsQuoted);
+	rhs = CondParser_Leaf(par, doEval, true, &rhsQuoted);
 	t = rhs.str == NULL ? TOK_ERROR
 	    : !doEval ? TOK_FALSE
 	    : EvalCompare(par, lhs.str, lhsQuoted, op, rhs.str, rhsQuoted);

cvs diff -r1.330 -r1.331 src/usr.bin/make/make.h (expand / switch to context diff)
--- src/usr.bin/make/make.h 2024/04/20 10:18:55 1.330
+++ src/usr.bin/make/make.h 2024/04/23 22:51:28 1.331
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.330 2024/04/20 10:18:55 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.331 2024/04/23 22:51:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -399,7 +399,7 @@
 
 /*
  * A graph node represents a target that can possibly be made, including its
- * relation to other targets and a lot of other details.
+ * relation to other targets.
  */
 typedef struct GNode {
 	/* The target's name, such as "clean" or "make.c" */
@@ -581,8 +581,8 @@
 extern GNode *SCOPE_CMDLINE;
 
 /*
- * Value returned by Var_Parse when an error is encountered. It actually
- * points to an empty string, so naive callers needn't worry about it.
+ * Value returned by Var_Parse when an error is encountered. It points to an
+ * empty string, so naive callers needn't worry about it.
  */
 extern char var_Error[];
 
@@ -678,11 +678,11 @@
 
 /* Command line options */
 typedef struct CmdOpts {
-	/* -B: whether we are make compatible */
+	/* -B: whether to be compatible to traditional make */
 	bool compatMake;
 
 	/*
-	 * -d: debug control: There is one bit per module.  It is up to the
+	 * -d: debug control: There is one flag per module.  It is up to the
 	 * module what debug information to print.
 	 */
 	DebugFlags debug;

cvs diff -r1.720 -r1.721 src/usr.bin/make/parse.c (expand / switch to context diff)
--- src/usr.bin/make/parse.c 2024/04/20 10:18:55 1.720
+++ src/usr.bin/make/parse.c 2024/04/23 22:51:28 1.721
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.720 2024/04/20 10:18:55 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.721 2024/04/23 22:51:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.720 2024/04/20 10:18:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.721 2024/04/23 22:51:28 rillig Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -1622,10 +1622,10 @@
  * Transformation rules such as '.c.o' are also handled here, see
  * Suff_AddTransform.
  *
- * Upon return, the value of the line is unspecified.
+ * Upon return, the value of expandedLine is unspecified.
  */
 static void
-ParseDependency(char *line, const char *unexpanded_line)
+ParseDependency(char *expandedLine, const char *unexpandedLine)
 {
 	char *p;
 	SearchPathList *paths;	/* search paths to alter when parsing a list
@@ -1636,14 +1636,14 @@
 				 * vice versa */
 	GNodeType op;
 
-	DEBUG1(PARSE, "ParseDependency(%s)\n", line);
-	p = line;
+	DEBUG1(PARSE, "ParseDependency(%s)\n", expandedLine);
+	p = expandedLine;
 	paths = NULL;
 	targetAttr = OP_NONE;
 	special = SP_NOT;
 
-	if (!ParseDependencyTargets(&p, line, &special, &targetAttr, &paths,
-	    unexpanded_line))
+	if (!ParseDependencyTargets(&p, expandedLine, &special, &targetAttr,
+	    &paths, unexpandedLine))
 		goto out;
 
 	if (!Lst_IsEmpty(targets))
@@ -1651,7 +1651,7 @@
 
 	op = ParseDependencyOp(&p);
 	if (op == OP_NONE) {
-		InvalidLineType(line, unexpanded_line);
+		InvalidLineType(expandedLine, unexpandedLine);
 		goto out;
 	}
 	ApplyDependencyOperator(op);

cvs diff -r1.1104 -r1.1105 src/usr.bin/make/var.c (expand / switch to context diff)
--- src/usr.bin/make/var.c 2024/04/21 21:59:48 1.1104
+++ src/usr.bin/make/var.c 2024/04/23 22:51:28 1.1105
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1104 2024/04/21 21:59:48 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1105 2024/04/23 22:51:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -81,8 +81,7 @@
  *	Var_End		Clean up the module.
  *
  *	Var_Set
- *	Var_SetExpand
- *			Set the value of the variable, creating it if
+ *	Var_SetExpand	Set the value of the variable, creating it if
  *			necessary.
  *
  *	Var_Append
@@ -102,8 +101,7 @@
  *
  *	Var_Parse	Parse an expression such as ${VAR:Mpattern}.
  *
- *	Var_Delete
- *			Delete a variable.
+ *	Var_Delete	Delete a variable.
  *
  *	Var_ReexportVars
  *			Export some or even all variables to the environment
@@ -118,9 +116,6 @@
  *	Var_Stats	Print out hashing statistics if in -dh mode.
  *
  *	Var_Dump	Print out all variables defined in the given scope.
- *
- * XXX: There's a lot of almost duplicate code in these functions that only
- *  differs in subtle details that are not mentioned in the manual page.
  */
 
 #include <sys/stat.h>
@@ -137,7 +132,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1104 2024/04/21 21:59:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1105 2024/04/23 22:51:28 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -147,7 +142,7 @@
  * There are 3 kinds of variables: scope variables, environment variables,
  * undefined variables.
  *
- * Scope variables are stored in a GNode.scope.  The only way to undefine
+ * Scope variables are stored in GNode.vars.  The only way to undefine
  * a scope variable is using the .undef directive.  In particular, it must
  * not be possible to undefine a variable during the evaluation of an
  * expression, or Var.name might point nowhere.  (There is another,
@@ -182,7 +177,7 @@
 
 	/*
 	 * The variable comes from the environment.
-	 * Appending to its value moves the variable to the global scope.
+	 * Appending to its value depends on the scope, see var-op-append.mk.
 	 */
 	bool fromEnvironment:1;
 
@@ -485,11 +480,8 @@
 	}
 
 	if (var == NULL) {
-		FStr envName;
-		const char *envValue;
-
-		envName = Substring_Str(name);
-		envValue = getenv(envName.str);
+		FStr envName = Substring_Str(name);
+		const char *envValue = getenv(envName.str);
 		if (envValue != NULL)
 			return VarNew(envName, envValue, true, true, false);
 		FStr_Done(&envName);
@@ -1004,9 +996,10 @@
 	if (v == NULL) {
 		if (scope == SCOPE_CMDLINE && !(flags & VAR_SET_NO_EXPORT)) {
 			/*
-			 * This var would normally prevent the same name being
-			 * added to SCOPE_GLOBAL, so delete it from there if
-			 * needed. Otherwise -V name may show the wrong value.
+			 * This variable would normally prevent the same name
+			 * being added to SCOPE_GLOBAL, so delete it from
+			 * there if needed. Otherwise -V name may show the
+			 * wrong value.
 			 *
 			 * See ExistsInCmdline.
 			 */
@@ -4716,10 +4709,9 @@
  * given string.
  *
  * Input:
- *	str		The string in which the expressions are
- *			expanded.
- *	scope		The scope in which to start searching for
- *			variables.  The other scopes are searched as well.
+ *	str		The string in which the expressions are expanded.
+ *	scope		The scope in which to start searching for variables.
+ *			The other scopes are searched as well.
  *	emode		The mode for parsing or evaluating subexpressions.
  */
 char *

cvs diff -r1.5 -r1.6 src/usr.bin/make/unit-tests/cmd-errors-jobs.exp (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cmd-errors-jobs.exp 2024/04/20 10:18:55 1.5
+++ src/usr.bin/make/unit-tests/cmd-errors-jobs.exp 2024/04/23 22:51:28 1.6
@@ -1,6 +1,6 @@
 : undefined--eol
-make: in target "unclosed-variable": Unclosed variable "UNCLOSED"
-: unclosed-variable-
+make: in target "unclosed-expression": Unclosed variable "UNCLOSED"
+: unclosed-expression-
 make: Unclosed expression, expecting '}' for "UNCLOSED"
 : unclosed-modifier-
 make: in target "unknown-modifier": while evaluating variable "UNKNOWN": Unknown modifier "Z"

cvs diff -r1.5 -r1.6 src/usr.bin/make/unit-tests/cmd-errors-lint.exp (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cmd-errors-lint.exp 2024/04/20 10:18:55 1.5
+++ src/usr.bin/make/unit-tests/cmd-errors-lint.exp 2024/04/23 22:51:28 1.6
@@ -1,6 +1,6 @@
 : undefined 
-make: in target "unclosed-variable": Unclosed variable "UNCLOSED"
-: unclosed-variable 
+make: in target "unclosed-expression": Unclosed variable "UNCLOSED"
+: unclosed-expression 
 make: Unclosed expression, expecting '}' for "UNCLOSED"
 : unclosed-modifier 
 make: in target "unknown-modifier": while evaluating variable "UNKNOWN": Unknown modifier "Z"

cvs diff -r1.5 -r1.6 src/usr.bin/make/unit-tests/cmd-errors.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cmd-errors.mk 2022/09/25 12:51:37 1.5
+++ src/usr.bin/make/unit-tests/cmd-errors.mk 2024/04/23 22:51:28 1.6
@@ -1,17 +1,18 @@
-# $NetBSD: cmd-errors.mk,v 1.5 2022/09/25 12:51:37 rillig Exp $
+# $NetBSD: cmd-errors.mk,v 1.6 2024/04/23 22:51:28 rillig Exp $
 #
-# Demonstrate how errors in variable expansions affect whether the commands
+# Demonstrate how errors in expressions affect whether the commands
 # are actually executed in compat mode.
 
-all: undefined unclosed-variable unclosed-modifier unknown-modifier end
+all: undefined unclosed-expression unclosed-modifier unknown-modifier end
 
-# Undefined variables are not an error.  They expand to empty strings.
+# Undefined variables in expressions are not an error.  They expand to empty
+# strings.
 undefined:
 	: $@-${UNDEFINED}-eol
 
 # XXX: As of 2020-11-01, this command is executed even though it contains
 # parse errors.
-unclosed-variable:
+unclosed-expression:
 	: $@-${UNCLOSED
 
 # XXX: As of 2020-11-01, this command is executed even though it contains

cvs diff -r1.3 -r1.4 src/usr.bin/make/unit-tests/cmd-errors-jobs.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cmd-errors-jobs.mk 2024/04/20 10:18:55 1.3
+++ src/usr.bin/make/unit-tests/cmd-errors-jobs.mk 2024/04/23 22:51:28 1.4
@@ -1,21 +1,22 @@
-# $NetBSD: cmd-errors-jobs.mk,v 1.3 2024/04/20 10:18:55 rillig Exp $
+# $NetBSD: cmd-errors-jobs.mk,v 1.4 2024/04/23 22:51:28 rillig Exp $
 #
-# Demonstrate how errors in variable expansions affect whether the commands
+# Demonstrate how errors in expressions affect whether the commands
 # are actually executed in jobs mode.
 
 .MAKEFLAGS: -j1
 
-all: undefined unclosed-variable unclosed-modifier unknown-modifier end
+all: undefined unclosed-expression unclosed-modifier unknown-modifier end
 
-# Undefined variables are not an error.  They expand to empty strings.
+# Undefined variables in expressions are not an error.  They expand to empty
+# strings.
 # expect: : undefined--eol
 undefined:
 	: $@-${UNDEFINED}-eol
 
 # XXX: This command is executed even though it contains parse errors.
-# expect: make: in target "unclosed-variable": Unclosed variable "UNCLOSED"
-# expect: : unclosed-variable-
-unclosed-variable:
+# expect: make: in target "unclosed-expression": Unclosed variable "UNCLOSED"
+# expect: : unclosed-expression-
+unclosed-expression:
 	: $@-${UNCLOSED
 
 # XXX: This command is executed even though it contains parse errors.

cvs diff -r1.1 -r1.2 src/usr.bin/make/unit-tests/cmd-errors-lint.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cmd-errors-lint.mk 2020/11/02 20:43:27 1.1
+++ src/usr.bin/make/unit-tests/cmd-errors-lint.mk 2024/04/23 22:51:28 1.2
@@ -1,20 +1,21 @@
-# $NetBSD: cmd-errors-lint.mk,v 1.1 2020/11/02 20:43:27 rillig Exp $
+# $NetBSD: cmd-errors-lint.mk,v 1.2 2024/04/23 22:51:28 rillig Exp $
 #
-# Demonstrate how errors in variable expansions affect whether the commands
+# Demonstrate how errors in expressions affect whether the commands
 # are actually executed.
 
 .MAKEFLAGS: -dL
 
-all: undefined unclosed-variable unclosed-modifier unknown-modifier end
+all: undefined unclosed-expression unclosed-modifier unknown-modifier end
 
-# Undefined variables are not an error.  They expand to empty strings.
+# Undefined variables in expressions are not an error.  They expand to empty
+# strings.
 undefined:
 	: $@ ${UNDEFINED}
 
 # XXX: As of 2020-11-01, this obvious syntax error is not detected.
 # XXX: As of 2020-11-01, this command is executed even though it contains
 # parse errors.
-unclosed-variable:
+unclosed-expression:
 	: $@ ${UNCLOSED
 
 # XXX: As of 2020-11-01, this obvious syntax error is not detected.

cvs diff -r1.8 -r1.9 src/usr.bin/make/unit-tests/cmd-errors.exp (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cmd-errors.exp 2024/04/20 10:18:55 1.8
+++ src/usr.bin/make/unit-tests/cmd-errors.exp 2024/04/23 22:51:28 1.9
@@ -1,6 +1,6 @@
 : undefined--eol
-make: in target "unclosed-variable": Unclosed variable "UNCLOSED"
-: unclosed-variable-
+make: in target "unclosed-expression": Unclosed variable "UNCLOSED"
+: unclosed-expression-
 make: Unclosed expression, expecting '}' for "UNCLOSED"
 : unclosed-modifier-
 make: in target "unknown-modifier": while evaluating variable "UNKNOWN": Unknown modifier "Z"

cvs diff -r1.8 -r1.9 src/usr.bin/make/unit-tests/cond-func-defined.exp (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cond-func-defined.exp 2023/11/19 21:47:52 1.8
+++ src/usr.bin/make/unit-tests/cond-func-defined.exp 2024/04/23 22:51:28 1.9
@@ -1,8 +1,5 @@
 make: "cond-func-defined.mk" line 24: Missing closing parenthesis for defined()
 make: "cond-func-defined.mk" line 34: Missing closing parenthesis for defined()
-make: "cond-func-defined.mk" line 47: In .for loops, expressions for the loop variables are
-make: "cond-func-defined.mk" line 49: substituted at evaluation time.  There is no actual variable
-make: "cond-func-defined.mk" line 51: involved, even if it feels like it.
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

cvs diff -r1.4 -r1.5 src/usr.bin/make/unit-tests/cmdline-undefined.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cmdline-undefined.mk 2023/11/19 21:47:52 1.4
+++ src/usr.bin/make/unit-tests/cmdline-undefined.mk 2024/04/23 22:51:28 1.5
@@ -1,6 +1,6 @@
-# $NetBSD: cmdline-undefined.mk,v 1.4 2023/11/19 21:47:52 rillig Exp $
+# $NetBSD: cmdline-undefined.mk,v 1.5 2024/04/23 22:51:28 rillig Exp $
 #
-# Tests for undefined expressions in the command line.
+# Tests for undefined variables in expressions in the command line.
 
 all:
 	# When the command line is parsed, variable assignments using the

cvs diff -r1.4 -r1.5 src/usr.bin/make/unit-tests/cmdline.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cmdline.mk 2022/06/10 18:58:07 1.4
+++ src/usr.bin/make/unit-tests/cmdline.mk 2024/04/23 22:51:28 1.5
@@ -1,4 +1,4 @@
-# $NetBSD: cmdline.mk,v 1.4 2022/06/10 18:58:07 rillig Exp $
+# $NetBSD: cmdline.mk,v 1.5 2024/04/23 22:51:28 rillig Exp $
 #
 # Tests for command line parsing and related special variables.
 
@@ -24,7 +24,7 @@
 	@${MAKE_CMD} MAKEOBJDIR=${DIR2} show-objdir
 
 # The .OBJDIR can be set via the MAKEOBJDIR command line variable,
-# and that variable could even contain the usual modifiers.
+# and expressions based on that variable can contain the usual modifiers.
 # Since the .OBJDIR=MAKEOBJDIR assignment happens very early,
 # the SUB2 variable in the modifier is not defined yet and is therefore empty.
 # The SUB1 in the resulting path comes from the environment variable TMPBASE,

cvs diff -r1.6 -r1.7 src/usr.bin/make/unit-tests/comment.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/comment.mk 2023/11/19 21:47:52 1.6
+++ src/usr.bin/make/unit-tests/comment.mk 2024/04/23 22:51:28 1.7
@@ -1,4 +1,4 @@
-# $NetBSD: comment.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $
+# $NetBSD: comment.mk,v 1.7 2024/04/23 22:51:28 rillig Exp $
 #
 # Demonstrate how comments are written in makefiles.
 
@@ -53,9 +53,9 @@
 .  error
 .endif
 
-# Since 2012-03-24 the variable modifier :[#] does not need to be escaped.
-# To keep the parsing code simple, any "[#" does not start a comment, even
-# outside of an expression.
+# Since 2012-03-24 the modifier :[#] does not need to be escaped.
+# To keep the parsing code simple, the "#" in "[#" does not start a comment,
+# regardless of the syntactical context it appears in.
 WORDS=	${VAR:[#]} [#
 .if ${WORDS} != "1 [#"
 .  error

cvs diff -r1.18 -r1.19 src/usr.bin/make/unit-tests/cond-cmp-string.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cond-cmp-string.mk 2023/11/19 21:47:52 1.18
+++ src/usr.bin/make/unit-tests/cond-cmp-string.mk 2024/04/23 22:51:28 1.19
@@ -1,4 +1,4 @@
-# $NetBSD: cond-cmp-string.mk,v 1.18 2023/11/19 21:47:52 rillig Exp $
+# $NetBSD: cond-cmp-string.mk,v 1.19 2024/04/23 22:51:28 rillig Exp $
 #
 # Tests for string comparisons in .if conditions.
 
@@ -20,12 +20,12 @@
 .  error
 .endif
 
-# The left-hand side of the comparison requires that any expression
-# is defined.
+# An expression that occurs on the left-hand side of the comparison must be
+# defined.
 #
 # The variable named "" is never defined, nevertheless it can be used as a
-# starting point for expressions.  Applying the :U modifier to such
-# an undefined expression turns it into a defined expression.
+# starting point for an expression.  Applying the :U modifier to such an
+# undefined expression turns it into a defined expression.
 #
 # See ApplyModifier_Defined and DEF_DEFINED.
 .if ${:Ustr} != "str"
@@ -69,8 +69,9 @@
 .endif
 
 # Between 2003-01-01 (maybe even earlier) and 2020-10-30, adding one of the
-# characters " \t!=><" directly after an expression resulted in a
-# "Malformed conditional", even though the string was well-formed.
+# characters " \t!=><" directly after an expression in a string literal
+# resulted in a "Malformed conditional", even though the string was
+# well-formed.
 .if ${:Uword } != "${:Uword} "
 .  error
 .endif
@@ -94,8 +95,7 @@
 .  error
 .endif
 
-# Adding a space at the beginning of the quoted expression works
-# though.
+# Adding a space at the beginning of the quoted expression works though.
 .if ${:U word } != " ${:Uword} "
 .  error
 .endif
@@ -145,7 +145,7 @@
 .  error
 .endif
 
-# Two variables with different values compare unequal.
+# Two expressions with different values compare unequal.
 VAR1=	value1
 VAR2=	value2
 .if ${VAR1} != ${VAR2}

cvs diff -r1.11 -r1.12 src/usr.bin/make/unit-tests/cond-func-defined.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/cond-func-defined.mk 2023/11/19 21:47:52 1.11
+++ src/usr.bin/make/unit-tests/cond-func-defined.mk 2024/04/23 22:51:28 1.12
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-defined.mk,v 1.11 2023/11/19 21:47:52 rillig Exp $
+# $NetBSD: cond-func-defined.mk,v 1.12 2024/04/23 22:51:28 rillig Exp $
 #
 # Tests for the defined() function in .if conditions.
 
@@ -43,12 +43,9 @@
 .  if defined(var)
 .    error
 .  else
-# expect+1: In .for loops, expressions for the loop variables are
-.    info In .for loops, expressions for the loop variables are
-# expect+1: substituted at evaluation time.  There is no actual variable
-.    info substituted at evaluation time.  There is no actual variable
-# expect+1: involved, even if it feels like it.
-.    info involved, even if it feels like it.
+# In .for loops, expressions based on the loop variables are substituted at
+# evaluation time.  There is no actual variable involved, even if the code in
+# the makefiles looks like it.
 .  endif
 .endfor
 

cvs diff -r1.27 -r1.28 src/usr.bin/make/unit-tests/varmod-ifelse.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/varmod-ifelse.mk 2024/04/20 10:18:55 1.27
+++ src/usr.bin/make/unit-tests/varmod-ifelse.mk 2024/04/23 22:51:28 1.28
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.27 2024/04/20 10:18:55 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.28 2024/04/23 22:51:28 rillig Exp $
 #
 # Tests for the ${cond:?then:else} variable modifier, which evaluates either
 # the then-expression or the else-expression, depending on the condition.
@@ -294,7 +294,7 @@
 
 
 # In the modifier parts for the 'then' and 'else' branches, subexpressions are
-# parsed in by inspecting the actual modifiers.  In 2008, 2015, 2020, 2022 and
+# parsed by inspecting the actual modifiers.  In 2008, 2015, 2020, 2022 and
 # 2023, the exact parsing algorithm switched a few times, counting balanced
 # braces instead of proper subexpressions, which meant that unbalanced braces
 # were parsed differently, depending on whether the branch was active or not.

cvs diff -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-match.exp (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/varmod-match.exp 2024/04/20 10:18:55 1.15
+++ src/usr.bin/make/unit-tests/varmod-match.exp 2024/04/23 22:51:28 1.16
@@ -1,14 +1,14 @@
-make: "varmod-match.mk" line 289: while evaluating variable "WORDS": warning: Unfinished character list in pattern 'a[' of modifier ':M'
-make: "varmod-match.mk" line 297: while evaluating variable "WORDS": warning: Unfinished character list in pattern 'a[^' of modifier ':M'
-make: "varmod-match.mk" line 305: while evaluating variable "WORDS": warning: Unfinished character list in pattern '[-x1-3' of modifier ':M'
-make: "varmod-match.mk" line 313: while evaluating variable "WORDS": warning: Unfinished character list in pattern '*[-x1-3' of modifier ':M'
-make: "varmod-match.mk" line 322: while evaluating variable "WORDS": warning: Unfinished character list in pattern '[^-x1-3' of modifier ':M'
-make: "varmod-match.mk" line 336: while evaluating variable "WORDS": warning: Unfinished character list in pattern '?[\' of modifier ':M'
-make: "varmod-match.mk" line 344: while evaluating variable "WORDS": warning: Unfinished character range in pattern '[x-' of modifier ':M'
-make: "varmod-match.mk" line 356: while evaluating variable "WORDS": warning: Unfinished character range in pattern '[^x-' of modifier ':M'
-make: "varmod-match.mk" line 364: while evaluating variable " : :: ": warning: Unfinished character list in pattern '[' of modifier ':M'
-make: "varmod-match.mk" line 364: while evaluating variable " : :: ": Unknown modifier "]"
-make: "varmod-match.mk" line 364: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":")
+make: "varmod-match.mk" line 290: while evaluating variable "WORDS": warning: Unfinished character list in pattern 'a[' of modifier ':M'
+make: "varmod-match.mk" line 298: while evaluating variable "WORDS": warning: Unfinished character list in pattern 'a[^' of modifier ':M'
+make: "varmod-match.mk" line 306: while evaluating variable "WORDS": warning: Unfinished character list in pattern '[-x1-3' of modifier ':M'
+make: "varmod-match.mk" line 314: while evaluating variable "WORDS": warning: Unfinished character list in pattern '*[-x1-3' of modifier ':M'
+make: "varmod-match.mk" line 323: while evaluating variable "WORDS": warning: Unfinished character list in pattern '[^-x1-3' of modifier ':M'
+make: "varmod-match.mk" line 337: while evaluating variable "WORDS": warning: Unfinished character list in pattern '?[\' of modifier ':M'
+make: "varmod-match.mk" line 345: while evaluating variable "WORDS": warning: Unfinished character range in pattern '[x-' of modifier ':M'
+make: "varmod-match.mk" line 357: while evaluating variable "WORDS": warning: Unfinished character range in pattern '[^x-' of modifier ':M'
+make: "varmod-match.mk" line 365: while evaluating variable " : :: ": warning: Unfinished character list in pattern '[' of modifier ':M'
+make: "varmod-match.mk" line 365: while evaluating variable " : :: ": Unknown modifier "]"
+make: "varmod-match.mk" line 365: Malformed conditional (${ ${:U\:} ${:U\:\:} :L:M[:]} != ":")
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

cvs diff -r1.21 -r1.22 src/usr.bin/make/unit-tests/varmod-match.mk (expand / switch to context diff)
--- src/usr.bin/make/unit-tests/varmod-match.mk 2024/04/20 10:18:55 1.21
+++ src/usr.bin/make/unit-tests/varmod-match.mk 2024/04/23 22:51:28 1.22
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-match.mk,v 1.21 2024/04/20 10:18:55 rillig Exp $
+# $NetBSD: varmod-match.mk,v 1.22 2024/04/23 22:51:28 rillig Exp $
 #
 # Tests for the ':M' modifier, which keeps only those words that match the
 # given pattern.
@@ -33,22 +33,22 @@
 # The pattern character '?' matches exactly 1 character, the pattern character
 # '*' matches 0 or more characters.  The whole pattern matches all words that
 # start with 's' and have 3 or more characters.
-.if ${One Two Three Four five six seven:L:Ms??*} != "six seven"
+.if ${One Two Three Four five six seven so s:L:Ms??*} != "six seven"
 .  error
 .endif
 
-# Ensure that a pattern without placeholders only matches itself.
+# A pattern without placeholders only matches itself.
 .if ${a aa aaa b ba baa bab:L:Ma} != "a"
 .  error
 .endif
 
-# Ensure that a pattern that ends with '*' is properly anchored at the
+# A pattern that ends with '*' is anchored at the
 # beginning.
 .if ${a aa aaa b ba baa bab:L:Ma*} != "a aa aaa"
 .  error
 .endif
 
-# Ensure that a pattern that starts with '*' is properly anchored at the end.
+# A pattern that starts with '*' is anchored at the end.
 .if ${a aa aaa b ba baa bab:L:M*a} != "a aa aaa ba baa"
 .  error
 .endif
@@ -257,8 +257,9 @@
 .  error
 .endif
 
-# Without the modifier ':tW', the string is split into words.  All whitespace
-# around and between the words is normalized to a single space.
+# Without the modifier ':tW', the string is split into words.  Whitespace
+# around the words is discarded, and whitespace between the words is
+# normalized to a single space.
 .if ${   plain    string   :L:M*} != "plain string"
 .  error
 .endif
@@ -372,9 +373,16 @@
 
 # Before var.c 1.1031 from 2022-08-24, the following expressions caused an
 # out-of-bounds read beyond the indirect ':M' modifiers.
-.if ${:U:${:UM\\}}		# The ':M' pattern need not be unescaped, the
+#
-.  error			# resulting pattern is '\', it never matches
+# The argument to the inner ':U' is unescaped to 'M\'.
-.endif				# anything.
+# This 'M\' becomes an # indirect modifier ':M' with the pattern '\'.
-.if ${:U:${:UM\\\:\\}}		# The ':M' pattern must be unescaped, the
+# The pattern '\' never matches.
-.  error			# resulting pattern is ':\', it never matches
+.if ${:U:${:UM\\}}
-.endif				# anything.
+.  error
+.endif
+# The argument to the inner ':U' is unescaped to 'M\:\'.
+# This 'M\:\' becomes an indirect modifier ':M' with the pattern ':\'.
+# The pattern ':\' never matches.
+.if ${:U:${:UM\\\:\\}}
+.  error
+.endif