outlineHandler(Action, &F, LPad, StartBB, FrameVarInfo);
}
- // Replace the landing pad with a new llvm.eh.action based landing pad.
- BasicBlock *NewLPadBB = BasicBlock::Create(Context, "lpad", &F, LPadBB);
- assert(!isa<PHINode>(LPadBB->begin()));
- auto *NewLPad = cast<LandingPadInst>(LPad->clone());
- NewLPadBB->getInstList().push_back(NewLPad);
- while (!pred_empty(LPadBB)) {
- auto *pred = *pred_begin(LPadBB);
- InvokeInst *Invoke = cast<InvokeInst>(pred->getTerminator());
- Invoke->setUnwindDest(NewLPadBB);
- }
-
- // Replace the mapping of any nested landing pad that previously mapped
- // to this landing pad with a referenced to the cloned version.
- for (auto &LPadPair : NestedLPtoOriginalLP) {
- const LandingPadInst *OriginalLPad = LPadPair.second;
- if (OriginalLPad == LPad) {
- LPadPair.second = NewLPad;
- }
- }
+ // Split the block after the landingpad instruction so that it is just a
+ // call to llvm.eh.actions followed by indirectbr.
+ assert(!isa<PHINode>(LPadBB->begin()) && "lpad phi not removed");
+ LPadBB->splitBasicBlock(LPad->getNextNode(),
+ LPadBB->getName() + ".prepsplit");
+ // Erase the branch inserted by the split so we can insert indirectbr.
+ LPadBB->getTerminator()->eraseFromParent();
// Replace all extracted values with undef and ultimately replace the
// landingpad with undef.
ActionArgs.push_back(Action->getHandlerBlockOrFunc());
}
CallInst *Recover =
- CallInst::Create(ActionIntrin, ActionArgs, "recover", NewLPadBB);
+ CallInst::Create(ActionIntrin, ActionArgs, "recover", LPadBB);
// Add an indirect branch listing possible successors of the catch handlers.
SetVector<BasicBlock *> ReturnTargets;
}
}
IndirectBrInst *Branch =
- IndirectBrInst::Create(Recover, ReturnTargets.size(), NewLPadBB);
+ IndirectBrInst::Create(Recover, ReturnTargets.size(), LPadBB);
for (BasicBlock *Target : ReturnTargets)
Branch->addDestination(Target);
} // End for each landingpad
; CHECK: define void @_Z4testv()
; CHECK: entry:
; CHECK: invoke void @_Z9may_throwv()
-; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
; Function Attrs: uwtable
define void @_Z4testv() #0 {
; CHECK: [[I_PTR:\%.+]] = alloca i32, align 4
; CHECK: call void (...) @llvm.frameescape(i32* [[I_PTR]])
; CHECK: invoke void @_Z9may_throwv()
-; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
; Function Attrs: uwtable
define void @_Z4testv() #0 {
; CHECK: [[TMP1:\%.+]] = alloca i32, align 4
; CHECK: call void (...) @llvm.frameescape(i32* [[TMP1]], %class.SomeClass* [[OBJ_PTR]], i32* [[TMP0]])
; CHECK: %call = invoke %class.SomeClass* @"\01??0SomeClass@@QEAA@XZ"(%class.SomeClass* %obj)
-; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
; Function Attrs: uwtable
define void @"\01?test@@YAXXZ"() #0 {
; CHECK: invoke.cont:
; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
-; CHECK: to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]+]]
+; CHECK: to label %invoke.cont2 unwind label %[[LPAD1_LABEL:lpad[0-9]*]]
invoke.cont: ; preds = %entry
invoke void @"\01?may_throw@@YAXXZ"()
; CHECK: invoke.cont2:
; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
-; CHECK: to label %try.cont unwind label %[[LPAD3_LABEL:lpad[0-9]+]]
+; CHECK: to label %try.cont unwind label %[[LPAD3_LABEL:lpad[0-9]*]]
invoke.cont2: ; preds = %invoke.cont
invoke void @"\01?may_throw@@YAXXZ"()
; CHECK: for.body:
; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
-; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
for.body: ; preds = %for.cond
invoke void @"\01?may_throw@@YAXXZ"()
; CHECK: call void @_ZN9SomeClassC1Ev(%class.SomeClass* [[OBJ_PTR]])
; CHECK: call void (...) @llvm.frameescape(%class.SomeClass* [[OBJ_PTR]])
; CHECK: invoke void @_Z9may_throwv()
-; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
; Function Attrs: uwtable
define void @_Z4testv() #0 {
; CHECK: [[I_PTR:\%.+]] = alloca i32, align 4
; CHECK: call void (...) @llvm.frameescape(i32* [[I_PTR]], i64* [[LL_PTR]], %class.SomeClass** [[OBJ_PTR]])
; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
-; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]+]]
+; CHECK: to label %invoke.cont unwind label %[[LPAD_LABEL:lpad[0-9]*]]
; Function Attrs: uwtable
define void @"\01?test@@YAXXZ"() #0 {