[PATCH] D52902: [WebAssembly] Don't modify preds/succs iterators while erasing from them

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 4 12:24:36 PDT 2018


aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: llvm-commits, sunfish, jgravelle-google, sbc100.

This caused out-of-bound bugs. Found by
`-DLLVM_ENABLE_EXPENSIVE_CHECKS=ON`.


Repository:
  rL LLVM

https://reviews.llvm.org/D52902

Files:
  lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp


Index: lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
+++ lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
@@ -91,12 +91,17 @@
   SmallVector<MachineBasicBlock *, 8> WL(MBBs.begin(), MBBs.end());
   while (!WL.empty()) {
     MachineBasicBlock *MBB = WL.pop_back_val();
+    SmallVector<MachineBasicBlock *, 4> Preds, Succs;
     for (auto *Pred : MBB->predecessors())
+      Preds.push_back(Pred);
+    for (auto *Pred : Preds)
       Pred->removeSuccessor(MBB);
     for (auto *Succ : MBB->successors()) {
+      Succs.push_back(Succ);
       WL.push_back(Succ);
-      MBB->removeSuccessor(Succ);
     }
+    for (auto *Succ : Succs)
+      MBB->removeSuccessor(Succ);
     MBB->eraseFromParent();
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52902.168349.patch
Type: text/x-patch
Size: 841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181004/58ad7a39/attachment.bin>


More information about the llvm-commits mailing list