glsl: Avoid calling get_array_element for scalar constants
authorDanylo Piliaiev <danylo.piliaiev@gmail.com>
Mon, 13 Aug 2018 15:57:38 +0000 (18:57 +0300)
committerTapani Pälli <tapani.palli@intel.com>
Wed, 15 Aug 2018 07:01:43 +0000 (10:01 +0300)
Accessing scalar constant as an array in function call or
initializer list triggered assert in get_array_element.
Examples:
   func(0[0]);
   vec2 t = { 0[0], 0 };

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107550

Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
src/compiler/glsl/ir_constant_expression.cpp

index 4a0aff72c6f3c5ddd19bfc92b83bafb55a01c29d..c9788c705351daafd5ba9ecc109bb0e28f2b5dc2 100644 (file)
@@ -826,7 +826,7 @@ ir_dereference_array::constant_expression_value(void *mem_ctx,
          const unsigned component = idx->value.u[0];
 
          return new(mem_ctx) ir_constant(array, component);
-      } else {
+      } else if (array->type->is_array()) {
          const unsigned index = idx->value.u[0];
          return array->get_array_element(index)->clone(mem_ctx, NULL);
       }