[WebAssembly] Don't modify preds/succs iterators while erasing from them

Summary:
This caused out-of-bound bugs. Found by
`-DLLVM_ENABLE_EXPENSIVE_CHECKS=ON`.

Reviewers: dschuff

Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits

Differential Revision: https://reviews.llvm.org/D52902

llvm-svn: 343814
This commit is contained in:
Heejin Ahn 2018-10-04 21:03:35 +00:00
parent aa067cb9fb
commit b68d591475
1 changed files with 7 additions and 4 deletions

View File

@ -91,12 +91,15 @@ static void EraseBBsAndChildren(const Container &MBBs) {
SmallVector<MachineBasicBlock *, 8> WL(MBBs.begin(), MBBs.end());
while (!WL.empty()) {
MachineBasicBlock *MBB = WL.pop_back_val();
for (auto *Pred : MBB->predecessors())
SmallVector<MachineBasicBlock *, 4> Preds(MBB->pred_begin(),
MBB->pred_end());
for (auto *Pred : Preds)
Pred->removeSuccessor(MBB);
for (auto *Succ : MBB->successors()) {
WL.push_back(Succ);
SmallVector<MachineBasicBlock *, 4> Succs(MBB->succ_begin(),
MBB->succ_end());
WL.append(MBB->succ_begin(), MBB->succ_end());
for (auto *Succ : Succs)
MBB->removeSuccessor(Succ);
}
MBB->eraseFromParent();
}
}