Fix this code so that it doesn't try to iterate through a std::vector
authorDan Gohman <gohman@apple.com>
Wed, 30 Sep 2009 20:54:16 +0000 (20:54 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 30 Sep 2009 20:54:16 +0000 (20:54 +0000)
while calling changeImmediateDominator, which removes elements from the
vector. This fixes PR5097.

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

lib/Transforms/Utils/LoopSimplify.cpp

index ffa12bfb7f0b500b50312cb9ba0b594f0cbde232..c22708a92b7a6e8096d3b18dc31646636d96af01 100644 (file)
@@ -274,9 +274,10 @@ ReprocessLoop:
       DomTreeNode *Node = DT->getNode(ExitingBlock);
       const std::vector<DomTreeNodeBase<BasicBlock> *> &Children =
         Node->getChildren();
-      for (unsigned k = 0, g = Children.size(); k != g; ++k) {
-        DT->changeImmediateDominator(Children[k], Node->getIDom());
-        if (DF) DF->changeImmediateDominator(Children[k]->getBlock(),
+      while (!Children.empty()) {
+        DomTreeNode *Child = Children.front();
+        DT->changeImmediateDominator(Child, Node->getIDom());
+        if (DF) DF->changeImmediateDominator(Child->getBlock(),
                                              Node->getIDom()->getBlock(),
                                              DT);
       }