summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-04-25 20:00:34 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-04-25 20:00:34 +0000
commit914046e1e7756aad8273f26302d39677648a3acf (patch)
treee78ee06f3935785439a15301c7ef4f161c702683 /llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
parente68b847fdb347f386e23ebd286dec115996440ee (diff)
downloadbcm5719-llvm-914046e1e7756aad8273f26302d39677648a3acf.tar.gz
bcm5719-llvm-914046e1e7756aad8273f26302d39677648a3acf.zip
DIE: Pass ownership of children via std::unique_ptr rather than raw pointer.
This should reduce the chance of memory leaks like those fixed in r207240. There's still some unclear ownership of DIEs happening in DwarfDebug. Pushing unique_ptr and references through more APIs should help expose the cases where ownership is a bit fuzzy. llvm-svn: 207263
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index c0ce5d2f36e..3bc359425c0 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -506,43 +506,45 @@ DIE *DwarfDebug::constructInlinedScopeDIE(DwarfCompileUnit &TheCU,
return ScopeDIE;
}
-DIE *DwarfDebug::createScopeChildrenDIE(DwarfCompileUnit &TheCU,
- LexicalScope *Scope,
- SmallVectorImpl<DIE *> &Children) {
+DIE *DwarfDebug::createScopeChildrenDIE(
+ DwarfCompileUnit &TheCU, LexicalScope *Scope,
+ SmallVectorImpl<std::unique_ptr<DIE>> &Children) {
DIE *ObjectPointer = nullptr;
// Collect arguments for current function.
if (LScopes.isCurrentFunctionScope(Scope)) {
for (DbgVariable *ArgDV : CurrentFnArguments)
- if (ArgDV)
- if (DIE *Arg =
- TheCU.constructVariableDIE(*ArgDV, Scope->isAbstractScope())) {
- Children.push_back(Arg);
- if (ArgDV->isObjectPointer())
- ObjectPointer = Arg;
- }
+ if (ArgDV) {
+ std::unique_ptr<DIE> Arg =
+ TheCU.constructVariableDIE(*ArgDV, Scope->isAbstractScope());
+ assert(Arg);
+ if (ArgDV->isObjectPointer())
+ ObjectPointer = Arg.get();
+ Children.push_back(std::move(Arg));
+ }
// If this is a variadic function, add an unspecified parameter.
DISubprogram SP(Scope->getScopeNode());
DIArray FnArgs = SP.getType().getTypeArray();
if (FnArgs.getElement(FnArgs.getNumElements() - 1)
.isUnspecifiedParameter()) {
- DIE *Ellipsis = new DIE(dwarf::DW_TAG_unspecified_parameters);
- Children.push_back(Ellipsis);
+ Children.push_back(
+ make_unique<DIE>(dwarf::DW_TAG_unspecified_parameters));
}
}
// Collect lexical scope children first.
- for (DbgVariable *DV : ScopeVariables.lookup(Scope))
- if (DIE *Variable =
- TheCU.constructVariableDIE(*DV, Scope->isAbstractScope())) {
- Children.push_back(Variable);
- if (DV->isObjectPointer())
- ObjectPointer = Variable;
- }
+ for (DbgVariable *DV : ScopeVariables.lookup(Scope)) {
+ std::unique_ptr<DIE> Variable =
+ TheCU.constructVariableDIE(*DV, Scope->isAbstractScope());
+ assert(Variable);
+ Children.push_back(std::move(Variable));
+ if (DV->isObjectPointer())
+ ObjectPointer = Variable.get();
+ }
for (LexicalScope *LS : Scope->getChildren())
if (DIE *Nested = constructScopeDIE(TheCU, LS))
- Children.push_back(Nested);
+ Children.push_back(std::unique_ptr<DIE>(Nested));
return ObjectPointer;
}
@@ -554,7 +556,7 @@ DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
DIScope DS(Scope->getScopeNode());
- SmallVector<DIE *, 8> Children;
+ SmallVector<std::unique_ptr<DIE>, 8> Children;
DIE *ObjectPointer = nullptr;
bool ChildrenCreated = false;
@@ -610,8 +612,8 @@ DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
ObjectPointer = createScopeChildrenDIE(TheCU, Scope, Children);
// Add children
- for (DIE *I : Children)
- ScopeDIE->addChild(I);
+ for (auto &I : Children)
+ ScopeDIE->addChild(std::move(I));
if (DS.isSubprogram() && ObjectPointer != nullptr)
TheCU.addDIEEntry(*ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer);
@@ -862,8 +864,7 @@ void DwarfDebug::collectDeadVariables() {
if (!DV.isVariable())
continue;
DbgVariable NewVar(DV, nullptr, this);
- if (DIE *VariableDIE = SPCU->constructVariableDIE(NewVar, false))
- SPDIE->addChild(VariableDIE);
+ SPDIE->addChild(SPCU->constructVariableDIE(NewVar, false));
}
}
}
OpenPOWER on IntegriCloud