glcpp: Reject garbage after #else and #endif tokens
Previously we were accepting garbage after #else and #endif tokens when the previous preprocessor conditional evaluated to false (eg, #if 0). When the preprocessor hits a false conditional, it switches the lexer into the SKIP state, in which it ignores non-control tokens. The parser pops the SKIP state off the stack when it reaches the associated #elif, #else, or #endif. Unfortunately, that meant that it only left the SKIP state after the lexing the entire line containing the #token and thus would accept garbage after the #token. To fix this we use a mid-rule, which is executed immediately after the #token is parsed. NOTE: This is a candidate for the stable branch Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=56442 Fixes: preprocess17_frag.test from oglconform Reviewed-by: Carl Worth <cworth@cworth.org> (glcpp-parse.y) Acked-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
@@ -327,12 +327,12 @@ control_line:
|
||||
glcpp_warning(& @1, parser, "ignoring illegal #elif without expression");
|
||||
}
|
||||
}
|
||||
| HASH_ELSE NEWLINE {
|
||||
| HASH_ELSE {
|
||||
_glcpp_parser_skip_stack_change_if (parser, & @1, "else", 1);
|
||||
}
|
||||
| HASH_ENDIF NEWLINE {
|
||||
} NEWLINE
|
||||
| HASH_ENDIF {
|
||||
_glcpp_parser_skip_stack_pop (parser, & @1);
|
||||
}
|
||||
} NEWLINE
|
||||
| HASH_VERSION integer_constant NEWLINE {
|
||||
macro_t *macro = hash_table_find (parser->defines, "__VERSION__");
|
||||
if (macro) {
|
||||
|
2
src/glsl/glcpp/tests/102-garbage-after-endif.c
Normal file
2
src/glsl/glcpp/tests/102-garbage-after-endif.c
Normal file
@@ -0,0 +1,2 @@
|
||||
#if 0
|
||||
#endif garbage
|
2
src/glsl/glcpp/tests/102-garbage-after-endif.c.expected
Normal file
2
src/glsl/glcpp/tests/102-garbage-after-endif.c.expected
Normal file
@@ -0,0 +1,2 @@
|
||||
0:2(8): preprocessor error: syntax error, unexpected IDENTIFIER, expecting NEWLINE
|
||||
|
3
src/glsl/glcpp/tests/103-garbage-after-else.c
Normal file
3
src/glsl/glcpp/tests/103-garbage-after-else.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#if 0
|
||||
#else garbage
|
||||
#endif
|
4
src/glsl/glcpp/tests/103-garbage-after-else.c.expected
Normal file
4
src/glsl/glcpp/tests/103-garbage-after-else.c.expected
Normal file
@@ -0,0 +1,4 @@
|
||||
0:2(7): preprocessor error: syntax error, unexpected IDENTIFIER, expecting NEWLINE
|
||||
0:1(7): preprocessor error: Unterminated #if
|
||||
|
||||
|
Reference in New Issue
Block a user