From cf08ff50dd35e1a75d3237b2e297683922a9518d 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. llvm-svn: 214547 --- clang/lib/CodeGen/CodeGenModule.cpp | 13 ++++++++++--- clang/lib/CodeGen/ModuleBuilder.cpp | 9 ++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index a14558f..55d4706 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/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/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp index c5d18d3..52522e6 100644 --- a/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/clang/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.7.4