From 139eb5f5122e89d6e5f9febb880f4997ee7da330 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 10 Apr 2015 18:01:58 +0000 Subject: [PATCH] DebugInfo: Stop leaking temporaries in DIBuilder::createCompileUnit() Stop leaking temporary nodes from `DIBuilder::createCompileUnit()`. `replaceAllUsesWith()` doesn't delete the nodes, so we need to delete them "manually" (well, `TempMDTuple` does that for us). Similarly, stop leaking the temporary nodes used for variables of subprograms. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234617 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DIBuilder.h | 10 +++++----- lib/IR/DIBuilder.cpp | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/llvm/IR/DIBuilder.h b/include/llvm/IR/DIBuilder.h index 260cd827a04..eb5cdd60427 100644 --- a/include/llvm/IR/DIBuilder.h +++ b/include/llvm/IR/DIBuilder.h @@ -57,11 +57,11 @@ namespace llvm { Module &M; LLVMContext &VMContext; - MDTuple *TempEnumTypes; - MDTuple *TempRetainTypes; - MDTuple *TempSubprograms; - MDTuple *TempGVs; - MDTuple *TempImportedModules; + TempMDTuple TempEnumTypes; + TempMDTuple TempRetainTypes; + TempMDTuple TempSubprograms; + TempMDTuple TempGVs; + TempMDTuple TempImportedModules; Function *DeclareFn; // llvm.dbg.declare Function *ValueFn; // llvm.dbg.value diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index 9ba20109168..f3b4997efb7 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -93,11 +93,11 @@ void DIBuilder::finalize() { TempSubprograms->replaceAllUsesWith(SPs.get()); for (unsigned i = 0, e = SPs.size(); i != e; ++i) { DISubprogram SP = cast(SPs[i]); - if (MDNode *Temp = SP.getVariables().get()) { + if (MDTuple *Temp = SP.getVariables().get()) { const auto &PV = PreservedVariables.lookup(SP); SmallVector Variables(PV.begin(), PV.end()); DIArray AV = getOrCreateArray(Variables); - Temp->replaceAllUsesWith(AV.get()); + TempMDTuple(Temp)->replaceAllUsesWith(AV.get()); } } @@ -143,18 +143,19 @@ DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename, // TODO: Once we make MDCompileUnit distinct, stop using temporaries here // (just start with operands assigned to nullptr). - TempEnumTypes = MDTuple::getTemporary(VMContext, None).release(); - TempRetainTypes = MDTuple::getTemporary(VMContext, None).release(); - TempSubprograms = MDTuple::getTemporary(VMContext, None).release(); - TempGVs = MDTuple::getTemporary(VMContext, None).release(); - TempImportedModules = MDTuple::getTemporary(VMContext, None).release(); + TempEnumTypes = MDTuple::getTemporary(VMContext, None); + TempRetainTypes = MDTuple::getTemporary(VMContext, None); + TempSubprograms = MDTuple::getTemporary(VMContext, None); + TempGVs = MDTuple::getTemporary(VMContext, None); + TempImportedModules = MDTuple::getTemporary(VMContext, None); // TODO: Switch to getDistinct(). We never want to merge compile units based // on contents. MDCompileUnit *CUNode = MDCompileUnit::get( VMContext, Lang, MDFile::get(VMContext, Filename, Directory), Producer, - isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes, - TempRetainTypes, TempSubprograms, TempGVs, TempImportedModules); + isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes.get(), + TempRetainTypes.get(), TempSubprograms.get(), TempGVs.get(), + TempImportedModules.get()); // Create a named metadata so that it is easier to find cu in a module. // Note that we only generate this when the caller wants to actually -- 2.34.1