From 36b70b68e8d84cd19391bf919b5530893d90c881 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Wed, 23 Oct 2013 22:53:18 +0200 Subject: [PATCH] Do not generate invalid IR in dgc2stack pass. Branching to a block that starts with a landing pad instruction is illegal. GitHub: Fixes #524. --- gen/passes/GarbageCollect2Stack.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gen/passes/GarbageCollect2Stack.cpp b/gen/passes/GarbageCollect2Stack.cpp index 7b70d678..e6bffde3 100644 --- a/gen/passes/GarbageCollect2Stack.cpp +++ b/gen/passes/GarbageCollect2Stack.cpp @@ -336,7 +336,6 @@ namespace { AU.addRequired(); AU.addPreserved(); - AU.addPreserved(); } }; char GarbageCollect2Stack::ID = 0; @@ -363,20 +362,20 @@ GarbageCollect2Stack::GarbageCollect2Stack() } static void RemoveCall(CallSite CS, const Analysis& A) { + // For an invoke instruction, we insert a branch to the normal target BB + // immediately before it. Ideally, we would find a way to not invalidate + // the dominator tree here. if (CS.isInvoke()) { InvokeInst* Invoke = cast(CS.getInstruction()); - // If this was an invoke instruction, we need to do some extra - // work to preserve the control flow. - // Create a "conditional" branch that -simplifycfg can clean up, so we - // can keep using the DominatorTree without updating it. - BranchInst::Create(Invoke->getNormalDest(), Invoke->getUnwindDest(), - ConstantInt::getTrue(A.M.getContext()), Invoke->getParent()); + BranchInst::Create(Invoke->getNormalDest(), Invoke); + Invoke->getUnwindDest()->removePredecessor(CS->getParent()); } + // Remove the runtime call. if (A.CGNode) A.CGNode->removeCallEdgeFor(CS); - CS.getInstruction()->eraseFromParent(); + CS->eraseFromParent(); } static bool isSafeToStackAllocateArray(Instruction* Alloc, DominatorTree& DT,