r214547 - Fix iterator invalidation issues that are breaking my modules buildbot's bootstrap.

Richard Smith richard-llvm at metafoo.co.uk
Fri Aug 1 12:59:14 PDT 2014


Author: rsmith
Date: Fri Aug  1 14:59:14 2014
New Revision: 214547

URL: http://llvm.org/viewvc/llvm-project?rev=214547&view=rev
Log:
Fix iterator invalidation issues that are breaking my modules buildbot's bootstrap.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/ModuleBuilder.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=214547&r1=214546&r2=214547&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Aug  1 14:59:14 2014
@@ -3305,9 +3305,16 @@ void CodeGenModule::EmitVersionIdentMeta
 }
 
 void CodeGenModule::EmitTargetMetadata() {
-  for (auto &I : MangledDeclNames) {
-    const Decl *D = I.first.getDecl()->getMostRecentDecl();
-    llvm::GlobalValue *GV = GetGlobalValue(I.second);
+  // Warning, new MangledDeclNames may be appended within this loop.
+  // We rely on MapVector insertions adding new elements to the end
+  // of the container.
+  // FIXME: Move this loop into the one target that needs it, and only
+  // loop over those declarations for which we couldn't emit the target
+  // metadata when we emitted the declaration.
+  for (unsigned I = 0; I != MangledDeclNames.size(); ++I) {
+    auto &Val = *(MangledDeclNames.begin() + I);
+    const Decl *D = Val.first.getDecl()->getMostRecentDecl();
+    llvm::GlobalValue *GV = GetGlobalValue(Val.second);
     getTargetCodeGenInfo().emitTargetMD(D, GV, *this);
   }
 }

Modified: cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ModuleBuilder.cpp?rev=214547&r1=214546&r2=214547&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ModuleBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/ModuleBuilder.cpp Fri Aug  1 14:59:14 2014
@@ -94,10 +94,13 @@ namespace {
       for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
         Builder->EmitTopLevelDecl(*I);
 
-      // Emit any deferred inline method definitions.
-      for (CXXMethodDecl *MD : DeferredInlineMethodDefinitions)
+      // Emit any deferred inline method definitions. Note that more deferred
+      // methods may be added during this loop.
+      while (!DeferredInlineMethodDefinitions.empty()) {
+        CXXMethodDecl *MD = DeferredInlineMethodDefinitions.back();
+        DeferredInlineMethodDefinitions.pop_back();
         Builder->EmitTopLevelDecl(MD);
-      DeferredInlineMethodDefinitions.clear();
+      }
 
       return true;
     }





More information about the cfe-commits mailing list