nir/glsl: Don't allocate a state_slots array for 0 state slots
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 3 Dec 2014 02:07:13 +0000 (18:07 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 15 Jan 2015 15:19:02 +0000 (07:19 -0800)
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/glsl/nir/glsl_to_nir.cpp

index 19bc664961c1627f7ea194672e9f9ad897268546..f29d7fbbb3dff89b879455c8c683cf5af03f83ba 100644 (file)
@@ -330,12 +330,18 @@ nir_visitor::visit(ir_variable *ir)
    var->data.max_array_access = ir->data.max_array_access;
 
    var->num_state_slots = ir->get_num_state_slots();
-   var->state_slots = ralloc_array(var, nir_state_slot, var->num_state_slots);
-   ir_state_slot *state_slots = ir->get_state_slots();
-   for (unsigned i = 0; i < var->num_state_slots; i++) {
-      for (unsigned j = 0; j < 5; j++)
-         var->state_slots[i].tokens[j] = state_slots[i].tokens[j];
-      var->state_slots[i].swizzle = state_slots[i].swizzle;
+   if (var->num_state_slots > 0) {
+      var->state_slots = ralloc_array(var, nir_state_slot,
+                                      var->num_state_slots);
+
+      ir_state_slot *state_slots = ir->get_state_slots();
+      for (unsigned i = 0; i < var->num_state_slots; i++) {
+         for (unsigned j = 0; j < 5; j++)
+            var->state_slots[i].tokens[j] = state_slots[i].tokens[j];
+         var->state_slots[i].swizzle = state_slots[i].swizzle;
+      }
+   } else {
+      var->state_slots = NULL;
    }
 
    var->constant_value = constant_copy(ir->constant_value, var);