[Mesa-dev] [PATCH] glsl: empty declarations should be valid

Chia-I Wu olvaffe at gmail.com
Sat Aug 6 21:18:42 PDT 2011


On Sat, Aug 6, 2011 at 5:35 AM, Ian Romanick <idr at freedesktop.org> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 08/05/2011 12:41 AM, Chia-I Wu wrote:
>> On Fri, Aug 5, 2011 at 1:48 PM, Chad Versace <chad at chad-versace.us> wrote:
>>> On 08/04/2011 06:18 PM, Chad Versace wrote:
>>>> On 08/04/2011 01:29 PM, Eric Anholt wrote:
>>>>> On Thu,  4 Aug 2011 12:59:35 +0900, Chia-I Wu <olvaffe at gmail.com> wrote:
>>>>>> From: Chia-I Wu <olv at lunarg.com>
>>>>>>
>>>>>> Unlike C++, empty declarations such as
>>>>>>
>>>>>>   float;
>>>>>>
>>>>>> should be valid.  The spec is not explicit about this actually.
>>>>>>
>>>>>> Some apps that generate their shader sources may rely on this.  This was
>>>>>> noted when porting one of them to Linux from Windows.
>>>>>
>>>>> Ew.  Looking the GLSL 1.20 spec, I see:
>>>>>
>>>>> statement:
>>>>>         declaration_statement
>>>>>
>>>>> declaration_statement:
>>>>>         declaration
>>>>>
>>>>> declaration:
>>>>>         init_declarator_list SEMICOLON
>>>>>
>>>>> init_declarator_list:
>>>>>         single_declaration
>>>>>
>>>>> single_declaration:
>>>>>         fully_specified_type
>>>>>         fully_specified_type IDENTIFIER
>>>>>
>>>>> so it looks like that is actually valid code.  That's awful.
>>>>
>>>> I first suspected that this was a spec grammar bug. But it is still present in
>>>> the GLSL 4.10 spec, so it's unlikely to be a bug.
>>>>
>>>> Surprisingly, C also allows empty declarations. Compiling this
>>>>     float;
>>>>     int main() { return 0; }
>>>> with `gcc --std=c99` succeeds and emits this warning:
>>>>      warning: useless type name in empty declaration [enabled by default]
>>>>
>>>> I hate to say this, but I believe the spec grammar intentionally allows empty
>>>> declarations. C allows it, and GLSL tries to mimic C.
>>>>
>>>> Even though I don't like empty declarations, this patch is
>>>> Reviewed-by: Chad Versace <chad at chad-versace.us>
>>>
>>> Also, please update the commit message to say that `gcc --std=c99` allows empty
>>> declrations and include the appropriate quotation from the GLSL 1.20 spec's
>>> grammar. Without that extra info, someone may stumble onto this commit and say WTF.
>> Oops.  I've already committed it...
>
> You have to give a little more time for review.  I would like to have
> had an opportunity to weigh in, but it's a bit late now.
Yes, I should have given it more time...  Sorry about that.

Maybe we can test how the other proprietary drivers work with regard
to this and decide whether to revert it or not?  I was told that it is
what the other drivers do on Windows, but I could not verify.

> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk48VBQACgkQX1gOwKyEAw9ZFACdHy2gnNLdszGp5PbDu84Luay1
> tpoAoIcgM2pemUdDINNiAvxc/wWw3J8T
> =X0eZ
> -----END PGP SIGNATURE-----
>



-- 
olv at LunarG.com


More information about the mesa-dev mailing list