aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
diff options
context:
space:
mode:
authorArthur Eubanks <aeubanks@google.com>2025-09-14 12:58:48 -0700
committerGitHub <noreply@github.com>2025-09-14 19:58:48 +0000
commitb30c29c89381f87562edc34c7813cbd310d1d4b0 (patch)
treeccb0bcd6b6b57f99872ab63c47e07ac5b9604110 /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
parentee3a4f4c94744d296797d1527382a9f060fc241a (diff)
downloadllvm-b30c29c89381f87562edc34c7813cbd310d1d4b0.zip
llvm-b30c29c89381f87562edc34c7813cbd310d1d4b0.tar.gz
llvm-b30c29c89381f87562edc34c7813cbd310d1d4b0.tar.bz2
Revert "[BasicBlockUtils] Handle funclets when detaching EH pad blocks" (#158364)
Reverts llvm/llvm-project#157363 Causes crashes, see https://github.com/llvm/llvm-project/pull/157363#issuecomment-3286783238
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/BasicBlockUtils.cpp44
1 files changed, 1 insertions, 43 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index d2391e1..cad0b4c 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -58,19 +58,6 @@ static cl::opt<unsigned> MaxDeoptOrUnreachableSuccessorCheckDepth(
"is followed by a block that either has a terminating "
"deoptimizing call or is terminated with an unreachable"));
-static void replaceFuncletPadsRetWithUnreachable(Instruction &I) {
- assert(isa<FuncletPadInst>(I) && "Instruction must be a funclet pad!");
- for (User *User : make_early_inc_range(I.users())) {
- Instruction *ReturnInstr = dyn_cast<Instruction>(User);
- if (isa<CatchReturnInst>(ReturnInstr) ||
- isa<CleanupReturnInst>(ReturnInstr)) {
- BasicBlock *ReturnInstrBB = ReturnInstr->getParent();
- ReturnInstr->eraseFromParent();
- new UnreachableInst(ReturnInstrBB->getContext(), ReturnInstrBB);
- }
- }
-}
-
void llvm::detachDeadBlocks(
ArrayRef<BasicBlock *> BBs,
SmallVectorImpl<DominatorTree::UpdateType> *Updates,
@@ -88,36 +75,7 @@ void llvm::detachDeadBlocks(
// Zap all the instructions in the block.
while (!BB->empty()) {
Instruction &I = BB->back();
- // Exception handling funclets need to be explicitly addressed.
- // These funclets must begin with cleanuppad or catchpad and end with
- // cleanupred or catchret. The return instructions can be in different
- // basic blocks than the pad instruction. If we would only delete the
- // first block, the we would have possible cleanupret and catchret
- // instructions with poison arguments, which wouldn't be valid.
- if (isa<FuncletPadInst>(I))
- replaceFuncletPadsRetWithUnreachable(I);
-
- // Catchswitch instructions have handlers, that must be catchpads and
- // an unwind label, that is either a catchpad or catchswitch.
- if (CatchSwitchInst *CSI = dyn_cast<CatchSwitchInst>(&I)) {
- // Iterating over the handlers and the unwind basic block and processing
- // catchpads. If the unwind label is a catchswitch, we just replace the
- // label with poison later on.
- for (unsigned I = 0; I < CSI->getNumSuccessors(); I++) {
- BasicBlock *SucBlock = CSI->getSuccessor(I);
- Instruction &SucFstInst = *(SucBlock->getFirstNonPHIIt());
- if (isa<FuncletPadInst>(SucFstInst)) {
- replaceFuncletPadsRetWithUnreachable(SucFstInst);
- // There may be catchswitch instructions using the catchpad.
- // Just replace those with poison.
- if (!SucFstInst.use_empty())
- SucFstInst.replaceAllUsesWith(
- PoisonValue::get(SucFstInst.getType()));
- SucFstInst.eraseFromParent();
- }
- }
- }
-
+ // If this instruction is used, replace uses with an arbitrary value.
// Because control flow can't get here, we don't care what we replace the
// value with. Note that since this block is unreachable, and all values
// contained within it must dominate their uses, that all uses will