Mesa (7.10): ir_to_mesa: Allocate temporary instructions on the visitor' s ralloc context

Ian Romanick idr at kemper.freedesktop.org
Thu Jul 7 21:18:34 UTC 2011


Module: Mesa
Branch: 7.10
Commit: 7424f9c1fe0ba57db3d4d19f668835fcea300d5c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7424f9c1fe0ba57db3d4d19f668835fcea300d5c

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Jun 24 17:12:31 2011 -0700

ir_to_mesa: Allocate temporary instructions on the visitor's ralloc context

And don't delete them.  Let ralloc clean them up.  Deleting the
temporary IR leaves dangling references in the prog_instruction.  That
results in a bad dereference when printing the IR with MESA_GLSL=dump.

NOTE: This is a candidate for the 7.10 and 7.11 branches.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38584
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
(cherry picked from commit dbda466fc05a6262ba857a7887e16347cf3d3e96)

---

 src/mesa/program/ir_to_mesa.cpp |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index cd97c0a..71b9fd6 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -827,48 +827,44 @@ ir_to_mesa_visitor::visit(ir_loop *ir)
    ir_dereference_variable *counter = NULL;
 
    if (ir->counter != NULL)
-      counter = new(ir) ir_dereference_variable(ir->counter);
+      counter = new(mem_ctx) ir_dereference_variable(ir->counter);
 
    if (ir->from != NULL) {
       assert(ir->counter != NULL);
 
-      ir_assignment *a = new(ir) ir_assignment(counter, ir->from, NULL);
+      ir_assignment *a =
+	new(mem_ctx) ir_assignment(counter, ir->from, NULL);
 
       a->accept(this);
-      delete a;
    }
 
    ir_to_mesa_emit_op0(NULL, OPCODE_BGNLOOP);
 
    if (ir->to) {
       ir_expression *e =
-	 new(ir) ir_expression(ir->cmp, glsl_type::bool_type,
-			       counter, ir->to);
-      ir_if *if_stmt =  new(ir) ir_if(e);
+	 new(mem_ctx) ir_expression(ir->cmp, glsl_type::bool_type,
+					  counter, ir->to);
+      ir_if *if_stmt =  new(mem_ctx) ir_if(e);
 
-      ir_loop_jump *brk = new(ir) ir_loop_jump(ir_loop_jump::jump_break);
+      ir_loop_jump *brk =
+	new(mem_ctx) ir_loop_jump(ir_loop_jump::jump_break);
 
       if_stmt->then_instructions.push_tail(brk);
 
       if_stmt->accept(this);
-
-      delete if_stmt;
-      delete e;
-      delete brk;
    }
 
    visit_exec_list(&ir->body_instructions, this);
 
    if (ir->increment) {
       ir_expression *e =
-	 new(ir) ir_expression(ir_binop_add, counter->type,
-			       counter, ir->increment);
+	 new(mem_ctx) ir_expression(ir_binop_add, counter->type,
+					  counter, ir->increment);
 
-      ir_assignment *a = new(ir) ir_assignment(counter, e, NULL);
+      ir_assignment *a =
+	new(mem_ctx) ir_assignment(counter, e, NULL);
 
       a->accept(this);
-      delete a;
-      delete e;
    }
 
    ir_to_mesa_emit_op0(NULL, OPCODE_ENDLOOP);




More information about the mesa-commit mailing list