ast_to_hir: Fix bug in constant initializers.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 20 Jul 2010 10:53:47 +0000 (03:53 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 21 Jul 2010 23:38:32 +0000 (16:38 -0700)
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

index e9257eee28914b5d4b3d2c7d337dcfe92376b264..99a2183cf861843d7af4f869479ea331e30e42ca 100644 (file)
@@ -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,