glsl2: Also steal the constant components of aggregate-typed ir_constants.
authorEric Anholt <eric@anholt.net>
Tue, 27 Jul 2010 02:26:53 +0000 (19:26 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 27 Jul 2010 02:30:19 +0000 (19:30 -0700)
src/glsl/ir.cpp

index 2fd654e9bfed3e536d321a0d10100a5b04c02f1c..6dccbd806e852ebbd076a39eea0adc74c68bab5d 100644 (file)
@@ -909,8 +909,26 @@ static void
 steal_memory(ir_instruction *ir, void *new_ctx)
 {
    ir_variable *var = ir->as_variable();
+   ir_constant *constant = ir->as_constant();
    if (var != NULL && var->constant_value != NULL)
       talloc_steal(ir, var->constant_value);
+
+   /* The components of aggregate constants are not visited by the normal
+    * visitor, so steal their values by hand.
+    */
+   if (constant != NULL) {
+      if (constant->type->is_record()) {
+        foreach_iter(exec_list_iterator, iter, constant->components) {
+           ir_constant *field = (ir_constant *)iter.get();
+           steal_memory(field, ir);
+        }
+      } else if (constant->type->is_array()) {
+        for (unsigned int i = 0; i < constant->type->length; i++) {
+           steal_memory(constant->array_elements[i], ir);
+        }
+      }
+   }
+
    talloc_steal(new_ctx, ir);
 }