diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index 2b7eb0093fe..ebdc0542020 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -488,8 +488,20 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, // For an invoke, the normal destination is the only one that is // dominated by the result of the invocation BasicBlock *DefBlock = cast(outputs[out])->getParent(); - if (InvokeInst *Invoke = dyn_cast(outputs[out])) + if (InvokeInst *Invoke = dyn_cast(outputs[out])) { DefBlock = Invoke->getNormalDest(); + + // Make sure we are looking at the original successor block, not + // at a newly inserted exit block, which won't be in the dominator + // info. + for (std::map::iterator I = + ExitBlockMap.begin(), E = ExitBlockMap.end(); I != E; ++I) + if (DefBlock == I->second) { + DefBlock = I->first; + break; + } + } + if (!DS || DS->dominates(DefBlock, TI->getParent())) if (AggregateArgs) { std::vector Indices;