]> granicus.if.org Git - clang/commitdiff
Fix iterator invalidation issues that are breaking my modules buildbot's bootstrap.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 1 Aug 2014 19:59:14 +0000 (19:59 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 1 Aug 2014 19:59:14 +0000 (19:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214547 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/ModuleBuilder.cpp

index a14558f975aafbf2d7f44df8c94f3430896b96be..55d47060ff932940cc6ac243098c50002b3bb00e 100644 (file)
@@ -3305,9 +3305,16 @@ void CodeGenModule::EmitVersionIdentMetadata() {
 }
 
 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);
   }
 }
index c5d18d3286a7b820ddc7efcc6872a5877de6055f..52522e69ef3a0b1ce923545cc1f7d296e356e596 100644 (file)
@@ -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;
     }