glsl: Check array size is const before asserting that no IR was generated.
authorPaul Berry <stereotype441@gmail.com>
Mon, 1 Aug 2011 22:23:07 +0000 (15:23 -0700)
committerPaul Berry <stereotype441@gmail.com>
Mon, 8 Aug 2011 19:43:53 +0000 (12:43 -0700)
process_array_type() contains an assertion to verify that no IR
instructions are generated while processing the expression that
specifies the size of the array.  This assertion needs to happen
_after_ checking whether the expression is constant.  Otherwise we may
crash on an illegal shader rather than reporting an error.

Fixes piglit tests array-size-non-builtin-function.vert and
array-size-with-side-effect.vert.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/ast_to_hir.cpp

index a6a0c328314a8ba8ceac23e8934f093829f7aefe..2025911acd35d2f51e262dac7730b8a804a5c4d0 100644 (file)
@@ -1769,11 +1769,6 @@ process_array_type(YYLTYPE *loc, const glsl_type *base, ast_node *array_size,
       ir_rvalue *const ir = array_size->hir(& dummy_instructions, state);
       YYLTYPE loc = array_size->get_location();
 
-      /* FINISHME: Verify that the grammar forbids side-effects in array
-       * FINISHME: sizes.   i.e., 'vec4 [x = 12] data'
-       */
-      assert(dummy_instructions.is_empty());
-
       if (ir != NULL) {
         if (!ir->type->is_integer()) {
            _mesa_glsl_error(& loc, state, "array size must be integer type");
@@ -1790,6 +1785,14 @@ process_array_type(YYLTYPE *loc, const glsl_type *base, ast_node *array_size,
            } else {
               assert(size->type == ir->type);
               length = size->value.u[0];
+
+               /* If the array size is const (and we've verified that
+                * it is) then no instructions should have been emitted
+                * when we converted it to HIR.  If they were emitted,
+                * then either the array size isn't const after all, or
+                * we are emitting unnecessary instructions.
+                */
+               assert(dummy_instructions.is_empty());
            }
         }
       }