summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2018-10-04 21:03:35 +0000
committerHeejin Ahn <aheejin@gmail.com>2018-10-04 21:03:35 +0000
commitb68d591475f6deb2abdf65c57b633cb89be253cb (patch)
treed7f144be134a888bffb17029e38b0cfab547b942 /llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
parentaa067cb9fb3ac5771d734296d683a886307a8129 (diff)
downloadbcm5719-llvm-b68d591475f6deb2abdf65c57b633cb89be253cb.tar.gz
bcm5719-llvm-b68d591475f6deb2abdf65c57b633cb89be253cb.zip
[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
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
index 8f40b4cb7a1..936b801a9a0 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
@@ -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();
}
}
OpenPOWER on IntegriCloud