Bug 34374 - [GLSL] fail to redeclare an array using initializer
Summary: [GLSL] fail to redeclare an array using initializer
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: 7.10
Hardware: All Linux (All)
: medium major
Assignee: Ian Romanick
QA Contact:
Depends on:
Reported: 2011-02-16 23:33 UTC by Gordon Jin
Modified: 2011-06-01 18:43 UTC (History)
0 users

See Also:
i915 platform:
i915 features:

new piglit test case (346 bytes, text/plain)
2011-02-16 23:35 UTC, Gordon Jin

Description Gordon Jin 2011-02-16 23:33:27 UTC
This gets wrong result:
    float a[];
    float a[2] = float[2](0,1);
Comment 1 Gordon Jin 2011-02-16 23:35:33 UTC
Created attachment 43475 [details]
new piglit test case
Comment 2 Ian Romanick 2011-03-04 14:46:27 UTC
The IR generated for this shader is clearly bogus.  Note the lack of any assignment to the array 'a'.

(function main
  (signature void
      (declare () (array float 2) a@0x10589f0)
      (if (expression bool all_equal (array_ref (var_ref a@0x10589f0) (constant int (1)) ) (constant float (1.000000)) ) (
        (assign  (xyzw) (var_ref gl_FragColor@0xf120c0)  (constant vec4 (0.000000 1.000000 0.000000 1.000000)) ) 
        (assign  (xyzw) (var_ref gl_FragColor@0xf120c0)  (constant vec4 (1.000000 0.000000 0.000000 1.000000)) ) 


Comment 3 Ian Romanick 2011-03-04 15:16:57 UTC
ast_declarator_list::hir generates a new variable, creates the initializer code, then checks to see of it is a redeclaration.  If it is a redeclaration, the initializer code (which is initializing the new variable), gets thrown away.  This seems fairly straightforward to fix, but it will require some restructuring of the code.
Comment 4 Ian Romanick 2011-03-04 16:35:44 UTC
Fixed on master by the following patch series.  I'm leaving the bug open until the fixes are cherry picked to the stable branches.

commit 09a4ba0fc31fa8fc193dfb7b4fd78e32722b8312
Author: Ian Romanick <ian.d.romanick@intel.com>
Date:   Fri Mar 4 16:15:20 2011 -0800

    glsl: Process redeclarations before initializers
    If an array redeclaration includes an initializer, the initializer
    would previously be dropped on the floor.  Instead, directly apply the
    initializer to the correct ir_variable instance and append the
    generated instructions.
    Fixes bugzilla #34374 and piglit tests glsl-{vs,fs}-array-redeclaration.
    NOTE: This is a candidate for stable release branches.  0292ffb8 and
    8e6cb9fe are also necessary.

commit 0292ffb85c03e9fa15b9395e3875109dd8979292
Author: Ian Romanick <ian.d.romanick@intel.com>
Date:   Fri Mar 4 15:29:33 2011 -0800

    glsl: Refactor AST-to-HIR code handling variable initializers

commit 8e6cb9fe51a2237e51b47198eb7d46b14ad288b5
Author: Ian Romanick <ian.d.romanick@intel.com>
Date:   Fri Mar 4 15:28:40 2011 -0800

    glsl: Refactor AST-to-HIR code handling variable redeclarations
Comment 5 Ian Romanick 2011-03-24 13:58:32 UTC
Fixed in 7.10 (856a661d2fa1936d81c3c2b50f2ee0e796008527).
Comment 6 Gordon Jin 2011-06-01 18:43:56 UTC
verified on 7.10 branch

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.