From 2761c4ceacab2e4f7da2e2a293a895595c02a928 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 13 Dec 2012 15:52:07 +0100 Subject: [PATCH] Fix invalid reads in valgrind during unused basic block collections When clearing cross-references to unused basic blocks blocks, don't delete the block right afterwards because another block might also still reference it. Instead keep track of the ones to be deleted and delete them afterwards in one shot. Also replaces the existance check for the blocks from a linear vector search to a hash set lookup which we already have around. Change-Id: I3bd72359259065ba26bf2116bf849575e4601f32 Reviewed-by: Lars Knoll --- qv4codegen.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/qv4codegen.cpp b/qv4codegen.cpp index 1cbdc84..17b96fe 100644 --- a/qv4codegen.cpp +++ b/qv4codegen.cpp @@ -1520,18 +1520,21 @@ void Codegen::linearize(IR::Function *function) I::trace(function->basicBlocks.first(), &V, &trace); + V.insert(exitBlock); exitBlock->index = trace.size(); trace.append(exitBlock); + QVarLengthArray blocksToDelete; foreach (IR::BasicBlock *b, function->basicBlocks) - if (!trace.contains(b)) { - foreach (IR::BasicBlock *out, b->out) { - int idx = out->in.indexOf(b); - if (idx >= 0) - out->in.remove(idx); + if (!V.contains(b)) { + foreach (IR::BasicBlock *out, b->out) { + int idx = out->in.indexOf(b); + if (idx >= 0) + out->in.remove(idx); + } + blocksToDelete.append(b); } - delete b; - } + qDeleteAll(blocksToDelete); function->basicBlocks = trace; #ifndef QV4_NO_LIVENESS -- 2.7.4