forked from OSchip/llvm-project
[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:
parent
aa067cb9fb
commit
b68d591475
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue