Bug 94188

Summary: define (or undef) defined behaves stupidly
Product: Mesa Reporter: Ian Romanick <idr>
Component: glsl-compilerAssignee: Ian Romanick <idr>
Status: RESOLVED FIXED QA Contact: Intel 3D Bugs Mailing List <intel-3d-bugs>
Severity: minor    
Priority: medium    
Version: git   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:

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. How we collect and use information is described in our Privacy Policy.