[llvm] r343814 - [WebAssembly] Don't modify preds/succs iterators while erasing from them
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 4 14:03:35 PDT 2018
Author: aheejin
Date: Thu Oct 4 14:03:35 2018
New Revision: 343814
URL: http://llvm.org/viewvc/llvm-project?rev=343814&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp?rev=343814&r1=343813&r2=343814&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp Thu Oct 4 14:03:35 2018
@@ -91,12 +91,15 @@ static void EraseBBsAndChildren(const Co
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();
}
}
More information about the llvm-commits
mailing list