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

Author: Kenneth Graunke <kenn...@whitecape.org>
Date:   Tue Jul 20 03:53:47 2010 -0700

ast_to_hir: Fix bug in constant initializers.

Implicit conversions were not being performed, nor was there any
type checking - it was possible to have, say, var->type == float
and var->constant_value->type == int.  Later use of the constant
expression would trigger an assertion.

Fixes piglit test const-implicit-conversion.frag.

---

 src/glsl/ast_to_hir.cpp |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index e9257ee..99a2183 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1804,6 +1804,16 @@ ast_declarator_list::hir(exec_list *instructions,
          * declaration.
          */
         if (this->type->qualifier.constant || this->type->qualifier.uniform) {
+           ir_rvalue *new_rhs = validate_assignment(state, var->type, rhs);
+           if (new_rhs != NULL) {
+              rhs = new_rhs;
+           } 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,

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to