summaryrefslogtreecommitdiff
path: root/lib/CodeGen/AsmPrinter
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
commit12d5224df6df05dc1189788591c381f467f5ff25 (patch)
treebad04f40bd47ad13a98b05e748fc1e4de4dfb23f /lib/CodeGen/AsmPrinter
parent172515f0be61f91c3a67206c6627c5e2572bdb26 (diff)
downloadllvm-12d5224df6df05dc1189788591c381f467f5ff25.tar.gz
llvm-12d5224df6df05dc1189788591c381f467f5ff25.tar.bz2
llvm-12d5224df6df05dc1189788591c381f467f5ff25.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207263 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/AsmPrinter')
-rw-r--r--lib/CodeGen/AsmPrinter/DIE.h4
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfDebug.cpp51
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfDebug.h2
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfUnit.cpp11
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfUnit.h8
5 files changed, 40 insertions, 36 deletions
diff --git a/lib/CodeGen/AsmPrinter/DIE.h b/lib/CodeGen/AsmPrinter/DIE.h
index a2841fe1ae..1a1c080c32 100644
--- a/lib/CodeGen/AsmPrinter/DIE.h
+++ b/lib/CodeGen/AsmPrinter/DIE.h
@@ -172,11 +172,11 @@ public:
/// addChild - Add a child to the DIE.
///
- void addChild(DIE *Child) {
+ void addChild(std::unique_ptr<DIE> Child) {
assert(!Child->getParent());
Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
- Children.push_back(std::unique_ptr<DIE>(Child));
Child->Parent = this;
+ Children.push_back(std::move(Child));
}
/// findAttribute - Find a value in the DIE with the attribute given,
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index c0ce5d2f36..3bc359425c 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/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));
}
}
}
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 325e053029..9038c648af 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -367,7 +367,7 @@ class DwarfDebug : public AsmPrinterHandler {
DIE *constructScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope);
/// A helper function to create children of a Scope DIE.
DIE *createScopeChildrenDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope,
- SmallVectorImpl<DIE *> &Children);
+ SmallVectorImpl<std::unique_ptr<DIE>> &Children);
/// \brief Emit initial Dwarf sections with a label at the start of each one.
void emitSectionLabels();
diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 874e0c051a..c7d22724ce 100644
--- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -383,7 +383,7 @@ void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,
DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, DIDescriptor N) {
assert(Tag != dwarf::DW_TAG_auto_variable &&
Tag != dwarf::DW_TAG_arg_variable);
- Parent.addChild(new DIE((dwarf::Tag)Tag));
+ Parent.addChild(make_unique<DIE>((dwarf::Tag)Tag));
DIE &Die = *Parent.getChildren().back();
if (N)
insertDIE(N, &Die);
@@ -1793,18 +1793,19 @@ void DwarfUnit::constructContainingTypeDIEs() {
}
/// constructVariableDIE - Construct a DIE for the given DbgVariable.
-DIE *DwarfUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract) {
+std::unique_ptr<DIE> DwarfUnit::constructVariableDIE(DbgVariable &DV,
+ bool isScopeAbstract) {
auto D = constructVariableDIEImpl(DV, isScopeAbstract);
DV.setDIE(*D);
return D;
}
-DIE *DwarfUnit::constructVariableDIEImpl(const DbgVariable &DV,
- bool isScopeAbstract) {
+std::unique_ptr<DIE> DwarfUnit::constructVariableDIEImpl(const DbgVariable &DV,
+ bool isScopeAbstract) {
StringRef Name = DV.getName();
// Define variable debug information entry.
- DIE *VariableDie = new DIE(DV.getTag());
+ auto VariableDie = make_unique<DIE>(DV.getTag());
DbgVariable *AbsVar = DV.getAbstractVariable();
DIE *AbsDIE = AbsVar ? AbsVar->getDIE() : nullptr;
if (AbsDIE)
diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.h b/lib/CodeGen/AsmPrinter/DwarfUnit.h
index af5d2d5418..2869841478 100644
--- a/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -270,7 +270,7 @@ public:
/// addDie - Adds or interns the DIE to the compile unit.
///
- void addDie(DIE *Buffer) { UnitDie->addChild(Buffer); }
+ void addDie(DIE *Buffer) { UnitDie->addChild(std::unique_ptr<DIE>(Buffer)); }
/// addFlag - Add a flag that is true to the DIE.
void addFlag(DIE &Die, dwarf::Attribute Attribute);
@@ -425,7 +425,8 @@ public:
void constructContainingTypeDIEs();
/// constructVariableDIE - Construct a DIE for the given DbgVariable.
- DIE *constructVariableDIE(DbgVariable &DV, bool isScopeAbstract);
+ std::unique_ptr<DIE> constructVariableDIE(DbgVariable &DV,
+ bool isScopeAbstract);
/// constructSubprogramArguments - Construct function argument DIEs.
void constructSubprogramArguments(DIE &Buffer, DIArray Args);
@@ -459,7 +460,8 @@ protected:
private:
/// \brief Construct a DIE for the given DbgVariable without initializing the
/// DbgVariable's DIE reference.
- DIE *constructVariableDIEImpl(const DbgVariable &DV, bool isScopeAbstract);
+ std::unique_ptr<DIE> constructVariableDIEImpl(const DbgVariable &DV,
+ bool isScopeAbstract);
/// constructTypeDIE - Construct basic type die from DIBasicType.
void constructTypeDIE(DIE &Buffer, DIBasicType BTy);