[Mesa-stable] [Mesa-dev] [PATCH 04/15] glsl: Add preprocessor error condition for #else directive
Anuj Phogat
anuj.phogat at gmail.com
Mon Jun 9 11:40:12 PDT 2014
On Fri, Jun 6, 2014 at 9:42 PM, Ian Romanick <idr at freedesktop.org> wrote:
> I thought Matt already fixed this bug.
A basic testing shows that below commit fixed the "garbage after #endif" bug
but "#garbage after #else" bug still exists. Absence of tests kept it untested.
>
> commit 060e69679925f171cfcc2a5f84fab1d833a7e804
> Author: Matt Turner <mattst88 at gmail.com>
> Date: Tue Nov 6 10:59:30 2012 -0800
>
> 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 at cworth.org> (glcpp-parse.y)
> Acked-by: Ian Romanick <ian.d.romanick at intel.com>
> Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
>
> On 06/06/2014 04:57 PM, Anuj Phogat wrote:
>> Fixes gles3 Khronos CTS tests:
>> tokens_after_else_vertex
>> tokens_after_else_fragment
>>
>> Cc: <mesa-stable at lists.freedesktop.org>
>> Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
>> ---
>> src/glsl/glcpp/glcpp-lex.l | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l
>> index 188e454..393db81 100644
>> --- a/src/glsl/glcpp/glcpp-lex.l
>> +++ b/src/glsl/glcpp/glcpp-lex.l
>> @@ -221,6 +221,10 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
>> return HASH_ELSE;
>> }
>>
>> +{HASH}else{HSPACE}*[^ \t\n]+ {
>> + glcpp_error(yylloc, yyextra, "illegal tokens after #else");
>> +}
>> +
>> {HASH}endif {
>> yyextra->space_tokens = 0;
>> return HASH_ENDIF;
>>
>
More information about the mesa-stable
mailing list