From ede487cdb44ee9acb25369f0b0d8b6ab3556c869 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Fri, 28 Feb 2014 21:27:57 +0000 Subject: [PATCH] Fix a crasher where when we're attempting to replace a type during the finalization for CGDebugInfo in clang we would RAUW a type and it would result in a corrupted MDNode for an imported declaration. Testcase pending as reducing has been difficult. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202540 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DIBuilder.h | 2 +- lib/IR/DIBuilder.cpp | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/llvm/DIBuilder.h b/include/llvm/DIBuilder.h index d47bae5fc60..ba7bca7ac5d 100644 --- a/include/llvm/DIBuilder.h +++ b/include/llvm/DIBuilder.h @@ -72,7 +72,7 @@ namespace llvm { SmallVector, 4> AllRetainTypes; SmallVector AllSubprograms; SmallVector AllGVs; - SmallVector AllImportedModules; + SmallVector, 4> AllImportedModules; // Private use for multiple types of template parameters. DITemplateValueParameter diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index 4bb75bdb0df..f5ccd5f2b68 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -69,7 +69,10 @@ void DIBuilder::finalize() { DIArray GVs = getOrCreateArray(AllGVs); DIType(TempGVs).replaceAllUsesWith(GVs); - DIArray IMs = getOrCreateArray(AllImportedModules); + SmallVector RetainValuesI; + for (unsigned I = 0, E = AllImportedModules.size(); I < E; I++) + RetainValuesI.push_back(AllImportedModules[I]); + DIArray IMs = getOrCreateArray(RetainValuesI); DIType(TempImportedModules).replaceAllUsesWith(IMs); } @@ -145,7 +148,7 @@ DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename, static DIImportedEntity createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS, unsigned Line, StringRef Name, - SmallVectorImpl &AllImportedModules) { + SmallVectorImpl> &AllImportedModules) { const MDNode *R; if (Name.empty()) { Value *Elts[] = { @@ -167,7 +170,7 @@ createImportedModule(LLVMContext &C, DIScope Context, DIDescriptor NS, } DIImportedEntity M(R); assert(M.Verify() && "Imported module should be valid"); - AllImportedModules.push_back(M); + AllImportedModules.push_back(TrackingVH(M)); return M; } @@ -197,7 +200,7 @@ DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context, }; DIImportedEntity M(MDNode::get(VMContext, Elts)); assert(M.Verify() && "Imported module should be valid"); - AllImportedModules.push_back(M); + AllImportedModules.push_back(TrackingVH(M)); return M; } -- 2.11.0