Fix iterator invalidation problem
authorChris Lattner <sabre@nondot.org>
Sun, 19 Oct 2003 21:48:27 +0000 (21:48 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 19 Oct 2003 21:48:27 +0000 (21:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9272 91177308-0d34-0410-b5e6-96231b3b80d8

tools/bugpoint/CodeGeneratorBug.cpp

index 10f544a69ad35ad967a721177f91792802984639..0aea9b031dad6a3961ba1d46d4754e0399551e45 100644 (file)
@@ -144,8 +144,8 @@ bool ReduceMisCodegenFunctions::TestFuncs(const std::vector<Function*> &Funcs,
         ResolverArgs.push_back(GEP);
 
         // Insert code at the beginning of the function
-        for (Value::use_iterator i=F->use_begin(), e=F->use_end(); i!=e; ++i) {
-          if (Instruction* Inst = dyn_cast<Instruction>(*i)) {
+        while (!F->use_empty())
+          if (Instruction *Inst = dyn_cast<Instruction>(F->use_back())) {
             // call resolver(GetElementPtr...)
             CallInst *resolve = new CallInst(resolverFunc, ResolverArgs, 
                                              "resolver", Inst);
@@ -161,7 +161,6 @@ bool ReduceMisCodegenFunctions::TestFuncs(const std::vector<Function*> &Funcs,
             std::cerr << "Non-instruction is using an external function!\n";
             abort();
           }
-        }
       }
     }
   }