aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2026-02-07 18:16:21 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-02-15 08:58:34 +0000
commite661c4c4a3a3aef6645dee66e3c34859766b39be (patch)
tree4f1dd5fd4292cb2326a4f99e3e293caa3d5e0617
parentf207a5cf02264545d8a9a22ef85bb471aef99911 (diff)
m4: Change defn processing order
Currently, defn pushes its arguments on the stack in order, which means they are then processed in reverse order. POSIX does not specify what order they are processed in, which arguably suggests that they should be processed in the order they are listed. Push them in reverse order so they will be processed in their original order. This matches GNU m4. PR: 292937 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: obiwac, imp Differential Revision: https://reviews.freebsd.org/D55116 (cherry picked from commit 25a8168f86a1222388475ce858da405e4d06c1c3)
-rw-r--r--usr.bin/m4/eval.c2
-rw-r--r--usr.bin/m4/tests/Makefile2
-rw-r--r--usr.bin/m4/tests/defn.m45
-rw-r--r--usr.bin/m4/tests/m4_test.sh9
-rw-r--r--usr.bin/m4/tests/regress.defn.out1
5 files changed, 18 insertions, 1 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c
index 3170d52bfe2a..4e45a71874e1 100644
--- a/usr.bin/m4/eval.c
+++ b/usr.bin/m4/eval.c
@@ -490,7 +490,7 @@ expand_builtin(const char *argv[], int argc, int td)
case DEFNTYPE:
if (argc > 2)
- for (n = 2; n < argc; n++)
+ for (n = argc - 1; n >= 2; n--)
dodefn(argv[n]);
break;
diff --git a/usr.bin/m4/tests/Makefile b/usr.bin/m4/tests/Makefile
index c5c0fdba7985..0ac13ddc8ebf 100644
--- a/usr.bin/m4/tests/Makefile
+++ b/usr.bin/m4/tests/Makefile
@@ -6,6 +6,7 @@ ATF_TESTS_SH= m4_test
${PACKAGE}FILES+= args.m4
${PACKAGE}FILES+= args2.m4
${PACKAGE}FILES+= comments.m4
+${PACKAGE}FILES+= defn.m4
${PACKAGE}FILES+= esyscmd.m4
${PACKAGE}FILES+= eval.m4
${PACKAGE}FILES+= ff_after_dnl.m4.uu
@@ -28,6 +29,7 @@ ${PACKAGE}FILES+= translit2.m4
${PACKAGE}FILES+= regress.args.out
${PACKAGE}FILES+= regress.args2.out
${PACKAGE}FILES+= regress.comments.out
+${PACKAGE}FILES+= regress.defn.out
${PACKAGE}FILES+= regress.esyscmd.out
${PACKAGE}FILES+= regress.eval.out
${PACKAGE}FILES+= regress.ff_after_dnl.out
diff --git a/usr.bin/m4/tests/defn.m4 b/usr.bin/m4/tests/defn.m4
new file mode 100644
index 000000000000..6599f95a5f20
--- /dev/null
+++ b/usr.bin/m4/tests/defn.m4
@@ -0,0 +1,5 @@
+dnl Check that our defn processes its arguments in order.
+define(a,1)dnl
+define(b,2)dnl
+define(c,3)dnl
+defn(`a',`b',`c')
diff --git a/usr.bin/m4/tests/m4_test.sh b/usr.bin/m4/tests/m4_test.sh
index 671f25ff4673..aa9be767d1c9 100644
--- a/usr.bin/m4/tests/m4_test.sh
+++ b/usr.bin/m4/tests/m4_test.sh
@@ -70,6 +70,14 @@ comments_body()
m4_test comments
}
+defn_head()
+{
+}
+defn_body()
+{
+ m4_test defn
+}
+
esyscmd_head()
{
}
@@ -219,6 +227,7 @@ atf_init_test_cases()
atf_add_test_case args
atf_add_test_case args2
atf_add_test_case comments
+ atf_add_test_case defn
atf_add_test_case esyscmd
atf_add_test_case eval
atf_add_test_case ff_after_dnl
diff --git a/usr.bin/m4/tests/regress.defn.out b/usr.bin/m4/tests/regress.defn.out
new file mode 100644
index 000000000000..190a18037c64
--- /dev/null
+++ b/usr.bin/m4/tests/regress.defn.out
@@ -0,0 +1 @@
+123