glsl: Completely initialize value member in ir_constant constructor.
[mesa.git] / src / glsl / ir.cpp
index ebb592792ba9488d294e6ddf7c7d742d3d8f1ede..992853c0466a9583f3dc3b4fc5df21470f3362ba 100644 (file)
@@ -21,8 +21,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 #include <string.h>
-#include "main/imports.h"
-#include "main/macros.h"
+#include "main/core.h" /* for MAX2 */
 #include "ir.h"
 #include "ir_visitor.h"
 #include "glsl_types.h"
@@ -184,6 +183,7 @@ ir_expression::get_num_operands(ir_expression_operation op)
       1, /* ir_unop_i2b */
       1, /* ir_unop_b2i */
       1, /* ir_unop_u2f */
+      1, /* ir_unop_any */
 
       1, /* ir_unop_trunc */
       1, /* ir_unop_ceil */
@@ -252,6 +252,7 @@ static const char *const operator_strs[] = {
    "i2b",
    "b2i",
    "u2f",
+   "any",
    "trunc",
    "ceil",
    "floor",
@@ -325,6 +326,9 @@ ir_constant::ir_constant(float f)
    this->ir_type = ir_type_constant;
    this->type = glsl_type::float_type;
    this->value.f[0] = f;
+   for (int i = 1; i < 16; i++)  {
+      this->value.f[i] = 0;
+   }
 }
 
 ir_constant::ir_constant(unsigned int u)
@@ -332,6 +336,9 @@ ir_constant::ir_constant(unsigned int u)
    this->ir_type = ir_type_constant;
    this->type = glsl_type::uint_type;
    this->value.u[0] = u;
+   for (int i = 1; i < 16; i++) {
+      this->value.u[i] = 0;
+   }
 }
 
 ir_constant::ir_constant(int i)
@@ -339,6 +346,9 @@ ir_constant::ir_constant(int i)
    this->ir_type = ir_type_constant;
    this->type = glsl_type::int_type;
    this->value.i[0] = i;
+   for (int i = 1; i < 16; i++) {
+      this->value.i[i] = 0;
+   }
 }
 
 ir_constant::ir_constant(bool b)
@@ -346,6 +356,9 @@ ir_constant::ir_constant(bool b)
    this->ir_type = ir_type_constant;
    this->type = glsl_type::bool_type;
    this->value.b[0] = b;
+   for (int i = 1; i < 16; i++) {
+      this->value.b[i] = false;
+   }
 }
 
 ir_constant::ir_constant(const ir_constant *c, unsigned i)
@@ -396,6 +409,9 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
       return;
    }
 
+   for (unsigned i = 0; i < 16; i++) {
+      this->value.u[i] = 0;
+   }
 
    ir_constant *value = (ir_constant *) (value_list->head);
 
@@ -696,6 +712,20 @@ ir_dereference_record::ir_dereference_record(ir_variable *var,
       ? this->record->type->field_type(field) : glsl_type::error_type;
 }
 
+bool type_contains_sampler(const glsl_type *type)
+{
+   if (type->is_array()) {
+      return type_contains_sampler(type->fields.array);
+   } else if (type->is_record()) {
+      for (unsigned int i = 0; i < type->length; i++) {
+        if (type_contains_sampler(type->fields.structure[i].type))
+           return true;
+      }
+      return false;
+   } else {
+      return type->is_sampler();
+   }
+}
 
 bool
 ir_dereference::is_lvalue()
@@ -710,6 +740,15 @@ ir_dereference::is_lvalue()
    if (this->type->is_array() && !var->array_lvalue)
       return false;
 
+   /* From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
+    *
+    *    "Samplers cannot be treated as l-values; hence cannot be used
+    *     as out or inout function parameters, nor can they be
+    *     assigned into."
+    */
+   if (type_contains_sampler(this->type))
+      return false;
+
    return true;
 }
 
@@ -958,7 +997,6 @@ ir_function_signature::ir_function_signature(const glsl_type *return_type)
    : return_type(return_type), is_defined(false), _function(NULL)
 {
    this->ir_type = ir_type_function_signature;
-   this->is_built_in = false;
 }
 
 
@@ -1010,6 +1048,7 @@ ir_function::ir_function(const char *name)
 {
    this->ir_type = ir_type_function;
    this->name = talloc_strdup(this, name);
+   this->is_builtin = false;
 }