Skip to content

Commit 0893d42

Browse files
committed
Handle catchswitch's unwind
1 parent 0376e58 commit 0893d42

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,26 @@ void llvm::detachDeadBlocks(
9797
if (isa<FuncletPadInst>(I))
9898
replaceFuncletPadsRetWithUnreachable(I);
9999

100-
// Catchswitch instructions have handlers, that must be catchpads.
100+
// Catchswitch instructions have handlers, that must be catchpads and
101+
// an unwind label, that is either a catchpad or catchswitch.
101102
CatchSwitchInst *CSI = dyn_cast<CatchSwitchInst>(&I);
102-
if (CSI) {
103-
BasicBlock *UnwindDest = CSI->getUnwindDest();
103+
if (CSI)
104+
// Iterating over the handlers and the unwind basic block and precssing
105+
// catchpads. If the unwind label is a catchswitch, we just replace the
106+
// label wit poison later on.
104107
for (unsigned I = 0; I < CSI->getNumSuccessors(); I++) {
105108
BasicBlock *SucBlock = CSI->getSuccessor(I);
106-
if (SucBlock != UnwindDest) {
107-
Instruction &PadInstr = *(SucBlock->getFirstNonPHIIt());
108-
replaceFuncletPadsRetWithUnreachable(PadInstr);
109+
Instruction &SucFstInst = *(SucBlock->getFirstNonPHIIt());
110+
if (isa<FuncletPadInst>(SucFstInst)) {
111+
replaceFuncletPadsRetWithUnreachable(SucFstInst);
112+
// There may be catchswitch instructions using the catchpad.
113+
// Just replace those with poison.
114+
if (!SucFstInst.use_empty())
115+
SucFstInst.replaceAllUsesWith(
116+
PoisonValue::get(SucFstInst.getType()));
117+
SucFstInst.eraseFromParent();
109118
}
110119
}
111-
}
112120
// Because control flow can't get here, we don't care what we replace the
113121
// value with. Note that since this block is unreachable, and all values
114122
// contained within it must dominate their uses, that all uses will

0 commit comments

Comments
 (0)