Fix a nasty iterator invalidation problem I introduced yesterday. This
authorChris Lattner <sabre@nondot.org>
Sun, 19 Sep 2004 19:01:06 +0000 (19:01 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 19 Sep 2004 19:01:06 +0000 (19:01 +0000)
unfortunately is the cause of a bunch of failures from tonight, and the
reason the tester is running so slow :(

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

lib/Analysis/IPA/CallGraph.cpp

index e3a60248895251e5f9b69d12fed651a5a705cbd4..dbf5b9f95bdd959ccb31152ee54e059e2ff43734 100644 (file)
@@ -211,10 +211,10 @@ void CallGraphNode::removeCallEdgeTo(CallGraphNode *Callee) {
 // the specified callee function.  This takes more time to execute than
 // removeCallEdgeTo, so it should not be used unless necessary.
 void CallGraphNode::removeAnyCallEdgeTo(CallGraphNode *Callee) {
-  for (std::vector<CallGraphNode*>::iterator I = CalledFunctions.begin(),
-         E = CalledFunctions.end(); I != E; ++I)
-    if (*I == Callee) {
-      CalledFunctions.erase(I);
-      E = CalledFunctions.end();
+  for (unsigned i = 0, e = CalledFunctions.size(); i != e; ++i)
+    if (CalledFunctions[i] == Callee) {
+      CalledFunctions[i] = CalledFunctions.back();
+      CalledFunctions.pop_back();
+      --i; --e;
     }
 }