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());
|
SmallVector<MachineBasicBlock *, 8> WL(MBBs.begin(), MBBs.end());
|
||||||
while (!WL.empty()) {
|
while (!WL.empty()) {
|
||||||
MachineBasicBlock *MBB = WL.pop_back_val();
|
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);
|
Pred->removeSuccessor(MBB);
|
||||||
for (auto *Succ : MBB->successors()) {
|
SmallVector<MachineBasicBlock *, 4> Succs(MBB->succ_begin(),
|
||||||
WL.push_back(Succ);
|
MBB->succ_end());
|
||||||
|
WL.append(MBB->succ_begin(), MBB->succ_end());
|
||||||
|
for (auto *Succ : Succs)
|
||||||
MBB->removeSuccessor(Succ);
|
MBB->removeSuccessor(Succ);
|
||||||
}
|
|
||||||
MBB->eraseFromParent();
|
MBB->eraseFromParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue