Remove references to deleted basic blocks
authorLars Knoll <lars.knoll@digia.com>
Wed, 12 Dec 2012 17:21:36 +0000 (18:21 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 12 Dec 2012 09:05:44 +0000 (10:05 +0100)
When linearizing, we can sometimes remove some basic blocks
that are never being jumped to. In this case we also need to
clean up the back references to these blocks from other
blocks.

This fixes a valgrind error with SHOW_CODE=1

Change-Id: I07d74cef24d6cf2c8bcc1e748e314a3a5b5ed60a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qv4codegen.cpp

index d9ac31d..a16d8c4 100644 (file)
@@ -1490,8 +1490,14 @@ void Codegen::linearize(IR::Function *function)
     trace.append(exitBlock);
 
     foreach (IR::BasicBlock *b, function->basicBlocks)
-        if (!trace.contains(b))
+        if (!trace.contains(b)) {
+            foreach (IR::BasicBlock *out, b->out) {
+                int idx = out->in.indexOf(b);
+                assert(idx >= 0);
+                out->in.remove(idx);
+            }
             delete b;
+        }
     function->basicBlocks = trace;
 
 #ifndef QV4_NO_LIVENESS