From 220a6404781ab97596ca6112fe0f8897324c4718 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 1 Aug 2014 19:59:14 +0000 Subject: [PATCH] Fix iterator invalidation issues that are breaking my modules buildbot's bootstrap. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214547 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 13 ++++++++++--- lib/CodeGen/ModuleBuilder.cpp | 9 ++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index a14558f975..55d47060ff 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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); } } diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp index c5d18d3286..52522e69ef 100644 --- a/lib/CodeGen/ModuleBuilder.cpp +++ b/lib/CodeGen/ModuleBuilder.cpp @@ -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; } -- 2.40.0