summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-06-01 06:25:34 +0000
committerrillig <rillig@NetBSD.org>2023-06-01 06:25:34 +0000
commite6daf4007f491cdb2e78246de1b1592052cfe60d (patch)
tree5bb3a8386620ff7754f117eb95cbf123d8c4edd5 /usr.bin/make
parent631ce5757e5becc51b456334549b5fa019a46692 (diff)
make: error out on a .break directive with arguments
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/parse.c12
-rw-r--r--usr.bin/make/unit-tests/directive-for-break.exp3
-rw-r--r--usr.bin/make/unit-tests/directive-for-break.mk10
3 files changed, 19 insertions, 6 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index 955ad333706..3daa3c536ba 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -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"))
diff --git a/usr.bin/make/unit-tests/directive-for-break.exp b/usr.bin/make/unit-tests/directive-for-break.exp
index b036ebfeb66..94549576668 100644
--- a/usr.bin/make/unit-tests/directive-for-break.exp
+++ b/usr.bin/make/unit-tests/directive-for-break.exp
@@ -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
diff --git a/usr.bin/make/unit-tests/directive-for-break.mk b/usr.bin/make/unit-tests/directive-for-break.mk
index a86acfa8bde..f9d1b527475 100644
--- a/usr.bin/make/unit-tests/directive-for-break.mk
+++ b/usr.bin/make/unit-tests/directive-for-break.mk
@@ -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