@@ -4486,9 +4486,6 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
4486
4486
Value *SrcVal = DestPN.getIncomingValue (Idx);
4487
4487
PHINode *SrcPN = dyn_cast<PHINode>(SrcVal);
4488
4488
4489
- // Remove the entry for the block we are deleting.
4490
- DestPN.removeIncomingValue (Idx, false );
4491
-
4492
4489
bool NeedPHITranslation = SrcPN && SrcPN->getParent () == BB;
4493
4490
for (auto *Pred : predecessors (BB)) {
4494
4491
Value *Incoming =
@@ -4516,12 +4513,15 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
4516
4513
if (pred != BB)
4517
4514
PN.addIncoming (&PN, pred);
4518
4515
PN.moveBefore (InsertPt);
4516
+ // Also, add a dummy incoming value for the original BB itself,
4517
+ // so that the PHI is well-formed until we drop said predecessor.
4518
+ PN.addIncoming (UndefValue::get (PN.getType ()), BB);
4519
4519
}
4520
4520
}
4521
4521
4522
4522
std::vector<DominatorTree::UpdateType> Updates;
4523
4523
4524
- // We use make_early_inc_range here because we may remove some predecessors.
4524
+ // We use make_early_inc_range here because we will remove all predecessors.
4525
4525
for (BasicBlock *PredBB : llvm::make_early_inc_range (predecessors (BB))) {
4526
4526
if (UnwindDest == nullptr ) {
4527
4527
if (DTU) {
@@ -4531,6 +4531,7 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
4531
4531
removeUnwindEdge (PredBB, DTU);
4532
4532
++NumInvokes;
4533
4533
} else {
4534
+ BB->removePredecessor (PredBB);
4534
4535
Instruction *TI = PredBB->getTerminator ();
4535
4536
TI->replaceUsesOfWith (BB, UnwindDest);
4536
4537
if (DTU) {
@@ -4540,12 +4541,10 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
4540
4541
}
4541
4542
}
4542
4543
4543
- if (DTU) {
4544
+ if (DTU)
4544
4545
DTU->applyUpdates (Updates);
4545
- DTU->deleteBB (BB);
4546
- } else
4547
- // The cleanup pad is now unreachable. Zap it.
4548
- BB->eraseFromParent ();
4546
+
4547
+ DeleteDeadBlock (BB, DTU);
4549
4548
4550
4549
return true ;
4551
4550
}
0 commit comments