[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 13:55:40 PDT 2018


aheejin updated this revision to Diff 168370.
aheejin added a comment.

- Use iterators within constructors / `append`


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,15 @@
   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();
   }
 }


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


More information about the llvm-commits mailing list