Module Name:    src
Committed By:   rillig
Date:           Tue Dec 14 00:02:57 UTC 2021

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/usr.bin/make: parse.c
        src/usr.bin/make/unit-tests: Makefile dep-wildcards.exp
Added Files:
        src/usr.bin/make/unit-tests: dep-op-missing.exp dep-op-missing.mk

Log Message:
make: remove unreachable code for parsing the dependency operator

At the point where ParseDependencyOp is called, cp is guaranteed to
point to either ':' or '!'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.1177 -r1.1178 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.577 -r1.578 src/usr.bin/make/parse.c
cvs rdiff -u -r1.289 -r1.290 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/dep-op-missing.exp \
    src/usr.bin/make/unit-tests/dep-op-missing.mk
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/dep-wildcards.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1177 src/distrib/sets/lists/tests/mi:1.1178
--- src/distrib/sets/lists/tests/mi:1.1177	Mon Dec 13 23:38:54 2021
+++ src/distrib/sets/lists/tests/mi	Tue Dec 14 00:02:57 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1177 2021/12/13 23:38:54 rillig Exp $
+# $NetBSD: mi,v 1.1178 2021/12/14 00:02:57 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5459,6 +5459,8 @@
 ./usr/tests/usr.bin/make/unit-tests/dep-exclam.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/dep-none.exp				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/dep-none.mk					tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/dep-op-missing.exp				tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/dep-op-missing.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/dep-percent.exp				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/dep-percent.mk				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/dep-var.exp					tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.577 src/usr.bin/make/parse.c:1.578
--- src/usr.bin/make/parse.c:1.577	Mon Dec 13 06:11:34 2021
+++ src/usr.bin/make/parse.c	Tue Dec 14 00:02:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.577 2021/12/13 06:11:34 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.578 2021/12/14 00:02:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.577 2021/12/13 06:11:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.578 2021/12/14 00:02:57 rillig Exp $");
 
 /* types and constants */
 
@@ -1265,34 +1265,15 @@ ParseDependencyCheckSpec(ParseSpecial sp
  * In a dependency line like 'targets: sources' or 'targets! sources', parse
  * the operator ':', '::' or '!' from between the targets and the sources.
  */
-static bool
-ParseDependencyOp(char **pp, const char *lstart, GNodeType *out_op)
+static GNodeType
+ParseDependencyOp(char **pp)
 {
-	const char *cp = *pp;
-
-	if (*cp == '!') {
-		*out_op = OP_FORCE;
-		(*pp)++;
-		return true;
-	}
-
-	if (*cp == ':') {
-		if (cp[1] == ':') {
-			*out_op = OP_DOUBLEDEP;
-			(*pp) += 2;
-		} else {
-			*out_op = OP_DEPENDS;
-			(*pp)++;
-		}
-		return true;
-	}
-
-	{
-		const char *msg = lstart[0] == '.'
-		    ? "Unknown directive" : "Missing dependency operator";
-		Parse_Error(PARSE_FATAL, "%s", msg);
-		return false;
-	}
+	if (**pp == '!')
+		return (*pp)++, OP_FORCE;
+	if ((*pp)[1] == ':')
+		return (*pp) += 2, OP_DOUBLEDEP;
+	else
+		return (*pp)++, OP_DEPENDS;
 }
 
 static void
@@ -1708,16 +1689,11 @@ ParseDependency(char *line)
 		ParseDependencyCheckSpec(specType);
 
 	/*
-	 * Have now parsed all the target names. Must parse the operator next.
-	 */
-	if (!ParseDependencyOp(&cp, lstart, &op))
-		goto out;
-
-	/*
 	 * Apply the operator to the target. This is how we remember which
 	 * operator a target was defined with. It fails if the operator
 	 * used isn't consistent across all references.
 	 */
+	op = ParseDependencyOp(&cp);
 	ApplyDependencyOperator(op);
 
 	/*

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.289 src/usr.bin/make/unit-tests/Makefile:1.290
--- src/usr.bin/make/unit-tests/Makefile:1.289	Mon Dec 13 23:38:54 2021
+++ src/usr.bin/make/unit-tests/Makefile	Tue Dec 14 00:02:57 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.289 2021/12/13 23:38:54 rillig Exp $
+# $NetBSD: Makefile,v 1.290 2021/12/14 00:02:57 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -94,6 +94,7 @@ TESTS+=		dep-double-colon
 TESTS+=		dep-double-colon-indep
 TESTS+=		dep-exclam
 TESTS+=		dep-none
+TESTS+=		dep-op-missing
 TESTS+=		dep-percent
 TESTS+=		dep-var
 TESTS+=		dep-wildcards

Index: src/usr.bin/make/unit-tests/dep-wildcards.exp
diff -u src/usr.bin/make/unit-tests/dep-wildcards.exp:1.5 src/usr.bin/make/unit-tests/dep-wildcards.exp:1.6
--- src/usr.bin/make/unit-tests/dep-wildcards.exp:1.5	Fri Oct 23 19:54:35 2020
+++ src/usr.bin/make/unit-tests/dep-wildcards.exp	Tue Dec 14 00:02:57 2021
@@ -4,6 +4,7 @@ dep-double-colon-indep.mk
 dep-double-colon.mk
 dep-exclam.mk
 dep-none.mk
+dep-op-missing.mk
 dep-percent.mk
 dep-var.mk
 dep-wildcards.mk

Added files:

Index: src/usr.bin/make/unit-tests/dep-op-missing.exp
diff -u /dev/null src/usr.bin/make/unit-tests/dep-op-missing.exp:1.1
--- /dev/null	Tue Dec 14 00:02:57 2021
+++ src/usr.bin/make/unit-tests/dep-op-missing.exp	Tue Dec 14 00:02:57 2021
@@ -0,0 +1,4 @@
+make: "dep-op-missing.tmp" line 1: Invalid line type
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 0
Index: src/usr.bin/make/unit-tests/dep-op-missing.mk
diff -u /dev/null src/usr.bin/make/unit-tests/dep-op-missing.mk:1.1
--- /dev/null	Tue Dec 14 00:02:57 2021
+++ src/usr.bin/make/unit-tests/dep-op-missing.mk	Tue Dec 14 00:02:57 2021
@@ -0,0 +1,13 @@
+# $NetBSD: dep-op-missing.mk,v 1.1 2021/12/14 00:02:57 rillig Exp $
+#
+# Test for a missing dependency operator, in a line with trailing whitespace.
+
+# Before parse.c 1.578 from 2021-12-14, there was some unreachable error
+# handling code in ParseDependencyOp.  This test tried to reach it and failed.
+# To reach that point, there would have to be trailing whitespace in the line,
+# but that is removed in an early stage of parsing.
+
+all: .PHONY
+	@printf 'target ' > dep-op-missing.tmp
+	@${MAKE} -r -f dep-op-missing.tmp || exit 0
+	@rm dep-op-missing.tmp

Reply via email to