Fix reference to iterator invalidated by an erase operation. Uncovered
authorDavid Greene <greened@obbligato.org>
Fri, 29 Jun 2007 02:53:16 +0000 (02:53 +0000)
committerDavid Greene <greened@obbligato.org>
Fri, 29 Jun 2007 02:53:16 +0000 (02:53 +0000)
by _GLIBCXX_DEBUG.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37796 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/LoopSimplify.cpp

index 8a3e5251fd692186f82ab3b70854629033b90064..0a5de2b43ed77a7fdd38f48ff4c4083fb275b7e5 100644 (file)
@@ -564,11 +564,12 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
 
   // Scan all of the loop children of L, moving them to OuterLoop if they are
   // not part of the inner loop.
-  for (Loop::iterator I = L->begin(); I != L->end(); )
-    if (BlocksInL.count((*I)->getHeader()))
+  const std::vector<Loop*> &SubLoops = L->getSubLoops();
+  for (size_t I = 0; I != SubLoops.size(); )
+    if (BlocksInL.count(SubLoops[I]->getHeader()))
       ++I;   // Loop remains in L
     else
-      NewOuter->addChildLoop(L->removeChildLoop(I));
+      NewOuter->addChildLoop(L->removeChildLoop(SubLoops.begin() + I));
 
   // Now that we know which blocks are in L and which need to be moved to
   // OuterLoop, move any blocks that need it.