[SV 64815] Recipe lines cannot contain conditional statements

* NEWS: Mention this change.
* src/read.c (eval): Check for ignoring for any line even if not
in a rule context.
* tests/scripts/features/conditionals: Write new tests.
This commit is contained in:
Paul Smith 2023-05-22 23:36:13 -04:00
parent c85b71a396
commit 07fcee35f0
3 changed files with 69 additions and 4 deletions

4
NEWS
View File

@ -53,6 +53,10 @@ https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=111&se
invoked recursively, warnings can be controlled only for the current invoked recursively, warnings can be controlled only for the current
instance of make using the .WARNINGS variable. instance of make using the .WARNINGS variable.
* Conditional statements starting with the recipe prefix were sometimes
interpreted in previous versions. As per the documentation, lines starting
with the recipe prefix are now never considered conditional statements.
* Tests in the regression test suite now are run in their own directory to * Tests in the regression test suite now are run in their own directory to
avoid cross-contamination and allow cleanup if the tests are interrupted. avoid cross-contamination and allow cleanup if the tests are interrupted.
More information is printed about failing tests. More information is printed about failing tests.

View File

@ -666,16 +666,16 @@ eval (struct ebuffer *ebuf, int set_default)
/* Ignore the commands in a rule with no targets. */ /* Ignore the commands in a rule with no targets. */
continue; continue;
if (ignoring)
/* Yep, this is a shell command, and we don't care. */
continue;
/* If there is no preceding rule line, don't treat this line /* If there is no preceding rule line, don't treat this line
as a command, even though it begins with a recipe prefix. as a command, even though it begins with a recipe prefix.
SunOS 4 make appears to behave this way. */ SunOS 4 make appears to behave this way. */
if (filenames != 0) if (filenames != 0)
{ {
if (ignoring)
/* Yep, this is a shell command, and we don't care. */
continue;
if (commands_idx == 0) if (commands_idx == 0)
cmds_started = ebuf->floc.lineno; cmds_started = ebuf->floc.lineno;

View File

@ -153,6 +153,67 @@ endif
', ',
'', "one\n"); '', "one\n");
# SV 64085: Ensure recipe prefixed conditionals are never considered
run_make_test(q!
blah=1
ifdef blah
else
else
endif
all:;
!,
'', "#MAKE#: 'all' is up to date.");
run_make_test(q!
blah=1
ifdef blah
else
endif
endif
all:;
!,
'', "#MAKE#: 'all' is up to date.");
run_make_test(q!
blah=1
ifdef blah
else
ifdef blah
endif
all:;
!,
'', "#MAKE#: 'all' is up to date.");
run_make_test(q!
blah=1
all:;
foo:
ifdef blah
ifdef blah
endif
!,
'', "#MAKE#: 'all' is up to date.");
run_make_test(q!
blah=1
all:;
foo:
ifdef blah
endif
endif
!,
'', "#MAKE#: 'all' is up to date.");
run_make_test(q!
blah=1
all:;
foo:
ifdef blah
else
else
endif
!,
'', "#MAKE#: 'all' is up to date.");
# This tells the test driver that the perl test script executed properly. # This tells the test driver that the perl test script executed properly.
1; 1;