Bug 94188 - define (or undef) defined behaves stupidly
Summary: define (or undef) defined behaves stupidly
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: git
Hardware: All All
: medium minor
Assignee: Ian Romanick
QA Contact: Intel 3D Bugs Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-17 02:24 UTC by Ian Romanick
Modified: 2016-02-19 13:57 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Romanick 2016-02-17 02:24:23 UTC
A shader like

    #define defined gl_Position
    void main()
    {
        defined = vec4(1.0);
    }

should either file to compile at line 1 or it should "just work."  Instead, Mesa produces a fairly obtuse error message:

    0:5(2): error: `defined' undeclared
    0:5(2): error: value of type vec4 cannot be assigned to variable of type error

Apparently some dEQP test expects '#define defined' and '#undef defined' to just work, but glslang generates an error.  See also https://github.com/KhronosGroup/glslang/issues/59.  Either way, Mesa's behavior is wrong.
Comment 1 Matt Turner 2016-02-17 19:45:57 UTC
deqp strikes again with completely absurd tests.

I'm relieved, reading the github issue that C/C++ say that 'defined' is not macro name, and that glslang has merged a patch to reject such stupidity.
Comment 2 Kenneth Graunke 2016-02-18 01:21:20 UTC
I posted a patch to disallow this on mesa-dev:
https://lists.freedesktop.org/archives/mesa-dev/2016-February/108008.html

Given that GCC, Clang, and now glslang disallow it, it seems pretty clear what the right behavior ought to be.  Nothing good can come from making this work.
Comment 3 Kenneth Graunke 2016-02-19 13:57:00 UTC
Fixed in master:

commit 1c694a6c20da21f31c584fd41d28e2f03522617d
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Wed Feb 17 17:15:23 2016 -0800

    glcpp: Disallow "defined" as a macro name.
    
    Both GCC and Clang disallow this, and glslang has recently started
    disallowing it as well.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94188
    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
    Reviewed-by: Matt Turner <mattst88@gmail.com>
    Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>

unless of course we have to make #define defined actually work, but hopefully not, because that would be silly and pointless.  We can always reopen or something if that happens.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct.