Skip to content

Commit

Permalink
[WebAssembly] Don't modify preds/succs iterators while erasing from them
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aheejin committed Oct 4, 2018
1 parent aa067cb commit b68d591
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit b68d591

Please sign in to comment.