Module Name:    src
Committed By:   rillig
Date:           Thu Jun  1 06:25:34 UTC 2023

Modified Files:
        src/usr.bin/make: parse.c
        src/usr.bin/make/unit-tests: directive-for-break.exp
            directive-for-break.mk

Log Message:
make: error out on a .break directive with arguments


To generate a diff of this commit:
cvs rdiff -u -r1.698 -r1.699 src/usr.bin/make/parse.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-for-break.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/directive-for-break.mk

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/parse.c
diff -u src/usr.bin/make/parse.c:1.698 src/usr.bin/make/parse.c:1.699
--- src/usr.bin/make/parse.c:1.698	Wed May 10 16:10:02 2023
+++ src/usr.bin/make/parse.c	Thu Jun  1 06:25:34 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.698 2023/05/10 16:10:02 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.699 2023/06/01 06:25:34 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.698 2023/05/10 16:10:02 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.699 2023/06/01 06:25:34 rillig Exp $");
 
 /*
  * A file being read.
@@ -2700,10 +2700,14 @@ ParseLine_ShellCommand(const char *p)
 }
 
 static void
-HandleBreak(void)
+HandleBreak(const char *arg)
 {
 	IncludedFile *curFile = CurFile();
 
+	if (arg[0] != '\0')
+		Parse_Error(PARSE_FATAL,
+		    "The .break directive does not take arguments");
+
 	if (curFile->forLoop != NULL) {
 		/* pretend we reached EOF */
 		For_Break(curFile->forLoop);
@@ -2742,7 +2746,7 @@ ParseDirective(char *line)
 	arg = cp;
 
 	if (Substring_Equals(dir, "break"))
-		HandleBreak();
+		HandleBreak(arg);
 	else if (Substring_Equals(dir, "undef"))
 		Var_Undef(arg);
 	else if (Substring_Equals(dir, "export"))

Index: src/usr.bin/make/unit-tests/directive-for-break.exp
diff -u src/usr.bin/make/unit-tests/directive-for-break.exp:1.2 src/usr.bin/make/unit-tests/directive-for-break.exp:1.3
--- src/usr.bin/make/unit-tests/directive-for-break.exp:1.2	Sat Sep  3 00:50:07 2022
+++ src/usr.bin/make/unit-tests/directive-for-break.exp	Thu Jun  1 06:25:34 2023
@@ -1,4 +1,5 @@
-make: "directive-for-break.mk" line 45: break outside of for loop
+make: "directive-for-break.mk" line 47: break outside of for loop
+make: "directive-for-break.mk" line 67: The .break directive does not take arguments
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/directive-for-break.mk
diff -u src/usr.bin/make/unit-tests/directive-for-break.mk:1.3 src/usr.bin/make/unit-tests/directive-for-break.mk:1.4
--- src/usr.bin/make/unit-tests/directive-for-break.mk:1.3	Sat Sep 24 10:52:05 2022
+++ src/usr.bin/make/unit-tests/directive-for-break.mk	Thu Jun  1 06:25:34 2023
@@ -1,8 +1,10 @@
-# $NetBSD: directive-for-break.mk,v 1.3 2022/09/24 10:52:05 rillig Exp $
+# $NetBSD: directive-for-break.mk,v 1.4 2023/06/01 06:25:34 rillig Exp $
 #
 # Tests for .break in .for loops, which immediately terminates processing of
 # the surrounding .for loop.
 
+# expect-all
+
 
 # .break terminates the loop early.
 # This is usually done within a conditional.
@@ -58,3 +60,9 @@ COMBINED+=	${outer}-${inner}
 .    endfor
 .  endif
 .endif
+
+
+.for i in 1
+# expect+1: The .break directive does not take arguments
+.  break 1
+.endfor

Reply via email to