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
This commit is contained in:
Duncan P. N. Exon Smith 2015-04-10 18:01:58 +00:00
parent f52cd1c1a3
commit 139eb5f512
2 changed files with 15 additions and 14 deletions

View File

@ -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

View File

@ -93,11 +93,11 @@ void DIBuilder::finalize() {
TempSubprograms->replaceAllUsesWith(SPs.get());
for (unsigned i = 0, e = SPs.size(); i != e; ++i) {
DISubprogram SP = cast<MDSubprogram>(SPs[i]);
if (MDNode *Temp = SP.getVariables().get()) {
if (MDTuple *Temp = SP.getVariables().get()) {
const auto &PV = PreservedVariables.lookup(SP);
SmallVector<Metadata *, 4> 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