Skip to content

Commit b30c29c

Browse files
authored
Revert "[BasicBlockUtils] Handle funclets when detaching EH pad blocks" (#158364)
Reverts #157363 Causes crashes, see #157363 (comment)
1 parent ee3a4f4 commit b30c29c

File tree

2 files changed

+1
-212
lines changed

2 files changed

+1
-212
lines changed

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,6 @@ static cl::opt<unsigned> MaxDeoptOrUnreachableSuccessorCheckDepth(
5858
"is followed by a block that either has a terminating "
5959
"deoptimizing call or is terminated with an unreachable"));
6060

61-
static void replaceFuncletPadsRetWithUnreachable(Instruction &I) {
62-
assert(isa<FuncletPadInst>(I) && "Instruction must be a funclet pad!");
63-
for (User *User : make_early_inc_range(I.users())) {
64-
Instruction *ReturnInstr = dyn_cast<Instruction>(User);
65-
if (isa<CatchReturnInst>(ReturnInstr) ||
66-
isa<CleanupReturnInst>(ReturnInstr)) {
67-
BasicBlock *ReturnInstrBB = ReturnInstr->getParent();
68-
ReturnInstr->eraseFromParent();
69-
new UnreachableInst(ReturnInstrBB->getContext(), ReturnInstrBB);
70-
}
71-
}
72-
}
73-
7461
void llvm::detachDeadBlocks(
7562
ArrayRef<BasicBlock *> BBs,
7663
SmallVectorImpl<DominatorTree::UpdateType> *Updates,
@@ -88,36 +75,7 @@ void llvm::detachDeadBlocks(
8875
// Zap all the instructions in the block.
8976
while (!BB->empty()) {
9077
Instruction &I = BB->back();
91-
// Exception handling funclets need to be explicitly addressed.
92-
// These funclets must begin with cleanuppad or catchpad and end with
93-
// cleanupred or catchret. The return instructions can be in different
94-
// basic blocks than the pad instruction. If we would only delete the
95-
// first block, the we would have possible cleanupret and catchret
96-
// instructions with poison arguments, which wouldn't be valid.
97-
if (isa<FuncletPadInst>(I))
98-
replaceFuncletPadsRetWithUnreachable(I);
99-
100-
// Catchswitch instructions have handlers, that must be catchpads and
101-
// an unwind label, that is either a catchpad or catchswitch.
102-
if (CatchSwitchInst *CSI = dyn_cast<CatchSwitchInst>(&I)) {
103-
// Iterating over the handlers and the unwind basic block and processing
104-
// catchpads. If the unwind label is a catchswitch, we just replace the
105-
// label with poison later on.
106-
for (unsigned I = 0; I < CSI->getNumSuccessors(); I++) {
107-
BasicBlock *SucBlock = CSI->getSuccessor(I);
108-
Instruction &SucFstInst = *(SucBlock->getFirstNonPHIIt());
109-
if (isa<FuncletPadInst>(SucFstInst)) {
110-
replaceFuncletPadsRetWithUnreachable(SucFstInst);
111-
// There may be catchswitch instructions using the catchpad.
112-
// Just replace those with poison.
113-
if (!SucFstInst.use_empty())
114-
SucFstInst.replaceAllUsesWith(
115-
PoisonValue::get(SucFstInst.getType()));
116-
SucFstInst.eraseFromParent();
117-
}
118-
}
119-
}
120-
78+
// If this instruction is used, replace uses with an arbitrary value.
12179
// Because control flow can't get here, we don't care what we replace the
12280
// value with. Note that since this block is unreachable, and all values
12381
// contained within it must dominate their uses, that all uses will

llvm/test/Transforms/SimplifyCFG/unreachable-multi-basic-block-funclet.ll

Lines changed: 0 additions & 169 deletions
This file was deleted.

0 commit comments

Comments
 (0)