[llvm] r252913 - [WinEH] Fix problem with removing an element from a SetVector while iterating.

Andrew Kaylor via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 12 09:36:03 PST 2015


Author: akaylor
Date: Thu Nov 12 11:36:03 2015
New Revision: 252913

URL: http://llvm.org/viewvc/llvm-project?rev=252913&view=rev
Log:
[WinEH] Fix problem with removing an element from a SetVector while iterating.

Patch provided by Yaron Keren. (Thanks!)


Modified:
    llvm/trunk/lib/CodeGen/WinEHPrepare.cpp

Modified: llvm/trunk/lib/CodeGen/WinEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/WinEHPrepare.cpp?rev=252913&r1=252912&r2=252913&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/WinEHPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/WinEHPrepare.cpp Thu Nov 12 11:36:03 2015
@@ -1665,18 +1665,12 @@ void WinEHPrepare::cloneCommonBlocks(
 
         // Remove this block from the FuncletBlocks set of any funclet that
         // isn't the funclet whose color we just selected.
-        for (auto It = BlockColors[BB].begin(), End = BlockColors[BB].end();
-             It != End; ) {
-          // The iterator must be incremented here because we are removing
-          // elements from the set we're walking.
-          auto Temp = It++;
-          BasicBlock *ContainingFunclet = *Temp;
-          if (ContainingFunclet != CorrectColor) {
+        for (BasicBlock *ContainingFunclet : BlockColors[BB])
+          if (ContainingFunclet != CorrectColor)
             FuncletBlocks[ContainingFunclet].erase(BB);
-            BlockColors[BB].remove(ContainingFunclet);
-          }
-        }
-
+        BlockColors[BB].remove_if([&](BasicBlock *ContainingFunclet) {
+          return ContainingFunclet != CorrectColor;
+        });
         // This should leave just one color for BB.
         assert(BlockColors[BB].size() == 1);
         continue;




More information about the llvm-commits mailing list