Potential bug in RewriteLoopBodyWithConditionConstant: use iterator should not be...
authorStepan Dyatkovskiy <stpworld@narod.ru>
Tue, 29 Nov 2011 20:34:39 +0000 (20:34 +0000)
committerStepan Dyatkovskiy <stpworld@narod.ru>
Tue, 29 Nov 2011 20:34:39 +0000 (20:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145432 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopUnswitch.cpp

index 458949c8444d2a20a9d753af8df8e1eddbd8fe8d..ab70dd5e420bdc53bc1f0e44aeaea0b089ad23ab 100644 (file)
@@ -907,9 +907,13 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
       Instruction *U = dyn_cast<Instruction>(*UI);
       if (!U || !L->contains(U))
         continue;
-      U->replaceUsesOfWith(LIC, Replacement);
       Worklist.push_back(U);
     }
+    
+    for (std::vector<Instruction*>::iterator UI = Worklist.begin();
+         UI != Worklist.end(); ++UI)
+      (*UI)->replaceUsesOfWith(LIC, Replacement);        
+    
     SimplifyCode(Worklist, L);
     return;
   }