Module: Mesa
Branch: master
Commit: e11757bb896e3dadc54fb3d18adf4b71e3e883b3
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=e11757bb896e3dadc54fb3d18adf4b71e3e883b3

Author: Eric Anholt <[email protected]>
Date:   Mon Aug 23 14:54:06 2010 -0700

glsl: When unable to assign the initializer for a const variable, set it to 0.

This prevents assertion failures or cascading errors after we've
logged the fact that we were unable to handle the initializer.

Fixes unsized-array-non-const-index-2.vert

---

 src/glsl/ast_to_hir.cpp |   34 +++++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 7ac24b0..57e3317 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1827,24 +1827,32 @@ ast_declarator_list::hir(exec_list *instructions,
            ir_rvalue *new_rhs = validate_assignment(state, var->type, rhs);
            if (new_rhs != NULL) {
               rhs = new_rhs;
+
+              ir_constant *constant_value = rhs->constant_expression_value();
+              if (!constant_value) {
+                 _mesa_glsl_error(& initializer_loc, state,
+                                  "initializer of %s variable `%s' must be a "
+                                  "constant expression",
+                                  (this->type->qualifier.constant)
+                                  ? "const" : "uniform",
+                                  decl->identifier);
+                 if (var->type->is_numeric()) {
+                    /* Reduce cascading errors. */
+                    var->constant_value = ir_constant::zero(ctx, var->type);
+                 }
+              } else {
+                 rhs = constant_value;
+                 var->constant_value = constant_value;
+              }
            } else {
               _mesa_glsl_error(&initializer_loc, state,
                                "initializer of type %s cannot be assigned to "
                                "variable of type %s",
                                rhs->type->name, var->type->name);
-           }
-
-           ir_constant *constant_value = rhs->constant_expression_value();
-           if (!constant_value) {
-              _mesa_glsl_error(& initializer_loc, state,
-                               "initializer of %s variable `%s' must be a "
-                               "constant expression",
-                               (this->type->qualifier.constant)
-                               ? "const" : "uniform",
-                               decl->identifier);
-           } else {
-              rhs = constant_value;
-              var->constant_value = constant_value;
+              if (var->type->is_numeric()) {
+                 /* Reduce cascading errors. */
+                 var->constant_value = ir_constant::zero(ctx, var->type);
+              }
            }
         }
 

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to