[Attributor][NFC] Use indexes instead of iterator
authorLuofan Chen <clfbbn@gmail.com>
Sat, 15 Aug 2020 15:04:11 +0000 (23:04 +0800)
committerLuofan Chen <clfbbn@gmail.com>
Sat, 15 Aug 2020 15:09:46 +0000 (23:09 +0800)
When adding elements when iterating, the iterator will become
valid, which could cause errors. This fixes the issue by using
indexes instead of iterator.

llvm/lib/Transforms/IPO/Attributor.cpp

index 6599ff6..88e0655 100644 (file)
@@ -2204,8 +2204,9 @@ static bool runAttributorOnFunctions(InformationCache &InfoCache,
   // TODO: for now we eagerly internalize functions without calculating the
   //       cost, we need a cost interface to determine whether internalizing
   //       a function is "benefitial"
-  if (AllowDeepWrapper) {
-    for (Function *F : Functions)
+  if (AllowDeepWrapper)
+    for (unsigned u = 0; u < Functions.size(); u ++) {
+      Function *F = Functions[u];
       if (!F->isDeclaration() && !F->isDefinitionExact() && F->getNumUses() &&
           !GlobalValue::isInterposableLinkage(F->getLinkage())) {
         Function *NewF = internalizeFunction(*F);
@@ -2219,7 +2220,7 @@ static bool runAttributorOnFunctions(InformationCache &InfoCache,
             CGUpdater.reanalyzeFunction(*CallerF);
           }
       }
-  }
+    }
 
   for (Function *F : Functions) {
     if (F->hasExactDefinition())