[Mesa-dev] [PATCH] glcpp: Reject garbage after #else and #endif tokens

Ian Romanick idr at freedesktop.org
Tue Nov 6 12:41:13 PST 2012


On 11/06/2012 11:40 AM, Matt Turner wrote:
> Previously we were accepting garbage after #else and #endif tokens when
> the previous preprocessor conditional had 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 entire line containing the #token which means it would
> accept garbage after the token.
>
> To fix this we use a mid-rule, which is executed immediately after the
> #token is parsed.
>
> Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=56442

s/Fixes:/Bugzilla:/  That makes grepping through commit logs for bug 
fixes easier.

Also, is this a candidate for stable branches?

This patch is beyond my bison-fu, so I can really only give

Acked-by: Ian Romanick <ian.d.romanick at intel.com>

> Fixes: preprocess17_frag.test from oglconform
> Reviewed-by: Carl Worth <cworth at cworth.org> (glcpp-parse.y)
> ---
>   src/glsl/glcpp/glcpp-parse.y                       |    8 ++++----
>   src/glsl/glcpp/tests/102-garbage-after-endif.c     |    2 ++
>   .../glcpp/tests/102-garbage-after-endif.c.expected |    2 ++
>   src/glsl/glcpp/tests/103-garbage-after-else.c      |    3 +++
>   .../glcpp/tests/103-garbage-after-else.c.expected  |    4 ++++
>   5 files changed, 15 insertions(+), 4 deletions(-)
>   create mode 100644 src/glsl/glcpp/tests/102-garbage-after-endif.c
>   create mode 100644 src/glsl/glcpp/tests/102-garbage-after-endif.c.expected
>   create mode 100644 src/glsl/glcpp/tests/103-garbage-after-else.c
>   create mode 100644 src/glsl/glcpp/tests/103-garbage-after-else.c.expected
>
> diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
> index ffb48e3..8025c06 100644
> --- a/src/glsl/glcpp/glcpp-parse.y
> +++ b/src/glsl/glcpp/glcpp-parse.y
> @@ -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) {
> diff --git a/src/glsl/glcpp/tests/102-garbage-after-endif.c b/src/glsl/glcpp/tests/102-garbage-after-endif.c
> new file mode 100644
> index 0000000..301779e
> --- /dev/null
> +++ b/src/glsl/glcpp/tests/102-garbage-after-endif.c
> @@ -0,0 +1,2 @@
> +#if 0
> +#endif garbage
> diff --git a/src/glsl/glcpp/tests/102-garbage-after-endif.c.expected b/src/glsl/glcpp/tests/102-garbage-after-endif.c.expected
> new file mode 100644
> index 0000000..d9f3bdc
> --- /dev/null
> +++ b/src/glsl/glcpp/tests/102-garbage-after-endif.c.expected
> @@ -0,0 +1,2 @@
> +0:2(8): preprocessor error: syntax error, unexpected IDENTIFIER, expecting NEWLINE
> +
> diff --git a/src/glsl/glcpp/tests/103-garbage-after-else.c b/src/glsl/glcpp/tests/103-garbage-after-else.c
> new file mode 100644
> index 0000000..c460fea
> --- /dev/null
> +++ b/src/glsl/glcpp/tests/103-garbage-after-else.c
> @@ -0,0 +1,3 @@
> +#if 0
> +#else garbage
> +#endif
> diff --git a/src/glsl/glcpp/tests/103-garbage-after-else.c.expected b/src/glsl/glcpp/tests/103-garbage-after-else.c.expected
> new file mode 100644
> index 0000000..f9f5f19
> --- /dev/null
> +++ b/src/glsl/glcpp/tests/103-garbage-after-else.c.expected
> @@ -0,0 +1,4 @@
> +0:2(7): preprocessor error: syntax error, unexpected IDENTIFIER, expecting NEWLINE
> +0:1(7): preprocessor error: Unterminated #if
> +
> +
>



More information about the mesa-dev mailing list