diff --git a/lib/CodeGen/AsmPrinter/DIE.h b/lib/CodeGen/AsmPrinter/DIE.h index a2841fe1ae6..1a1c080c32c 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 Child) { assert(!Child->getParent()); Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes); - Children.push_back(std::unique_ptr(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 c0ce5d2f36e..3bc359425c0 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 &Children) { +DIE *DwarfDebug::createScopeChildrenDIE( + DwarfCompileUnit &TheCU, LexicalScope *Scope, + SmallVectorImpl> &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 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(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 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(Nested)); return ObjectPointer; } @@ -554,7 +556,7 @@ DIE *DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU, DIScope DS(Scope->getScopeNode()); - SmallVector Children; + SmallVector, 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 325e053029e..9038c648af3 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 &Children); + SmallVectorImpl> &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 874e0c051ab..c7d22724ce3 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((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 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 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(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 af5d2d54189..2869841478c 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(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 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 constructVariableDIEImpl(const DbgVariable &DV, + bool isScopeAbstract); /// constructTypeDIE - Construct basic type die from DIBasicType. void constructTypeDIE(DIE &Buffer, DIBasicType BTy); diff --git a/unittests/CodeGen/DIEHashTest.cpp b/unittests/CodeGen/DIEHashTest.cpp index 5876bb38f64..04c5a8ac019 100644 --- a/unittests/CodeGen/DIEHashTest.cpp +++ b/unittests/CodeGen/DIEHashTest.cpp @@ -12,6 +12,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/Format.h" +#include "llvm/ADT/STLExtras.h" #include "gtest/gtest.h" using namespace llvm; @@ -59,7 +60,7 @@ TEST(DIEHashTest, NamedType) { TEST(DIEHashTest, NamespacedType) { DIE CU(dwarf::DW_TAG_compile_unit); - DIE *Space = new DIE(dwarf::DW_TAG_namespace); + auto Space = make_unique(dwarf::DW_TAG_namespace); DIEInteger One(1); DIEString SpaceStr(&One, "space"); Space->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &SpaceStr); @@ -67,15 +68,16 @@ TEST(DIEHashTest, NamespacedType) { Space->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One); // sibling? - DIE *Foo = new DIE(dwarf::DW_TAG_structure_type); + auto Foo = make_unique(dwarf::DW_TAG_structure_type); DIEString FooStr(&One, "foo"); Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); - Space->addChild(Foo); - CU.addChild(Space); + DIE &N = *Foo; + Space->addChild(std::move(Foo)); + CU.addChild(std::move(Space)); - uint64_t MD5Res = DIEHash().computeTypeSignature(*Foo); + uint64_t MD5Res = DIEHash().computeTypeSignature(N); // The exact same hash GCC produces for this DIE. ASSERT_EQ(0x7b80381fd17f1e33ULL, MD5Res); @@ -87,15 +89,6 @@ TEST(DIEHashTest, TypeWithMember) { DIEInteger Four(4); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); - DIE *Member = new DIE(dwarf::DW_TAG_member); - DIEString MemberStr(&Four, "member"); - Member->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemberStr); - DIEInteger Zero(0); - Member->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, - &Zero); - - Unnamed.addChild(Member); - DIE Int(dwarf::DW_TAG_base_type); DIEString IntStr(&Four, "int"); Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &IntStr); @@ -104,8 +97,17 @@ TEST(DIEHashTest, TypeWithMember) { Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five); DIEEntry IntRef(Int); + + auto Member = make_unique(dwarf::DW_TAG_member); + DIEString MemberStr(&Four, "member"); + Member->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemberStr); + DIEInteger Zero(0); + Member->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, + &Zero); Member->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef); + Unnamed.addChild(std::move(Member)); + uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed); ASSERT_EQ(0x5646aa436b7e07c6ULL, MD5Res); @@ -117,24 +119,7 @@ TEST(DIEHashTest, ReusedType) { DIEInteger Eight(8); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight); - DIE *Mem1 = new DIE(dwarf::DW_TAG_member); DIEInteger Four(4); - DIEString Mem1Str(&Four, "mem1"); - Mem1->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem1Str); - DIEInteger Zero(0); - Mem1->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, - &Zero); - - Unnamed.addChild(Mem1); - - DIE *Mem2 = new DIE(dwarf::DW_TAG_member); - DIEString Mem2Str(&Four, "mem2"); - Mem2->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem2Str); - Mem2->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, - &Four); - - Unnamed.addChild(Mem2); - DIE Int(dwarf::DW_TAG_base_type); DIEString IntStr(&Four, "int"); Int.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &IntStr); @@ -143,9 +128,26 @@ TEST(DIEHashTest, ReusedType) { Int.addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Five); DIEEntry IntRef(Int); + + auto Mem1 = make_unique(dwarf::DW_TAG_member); + DIEString Mem1Str(&Four, "mem1"); + Mem1->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem1Str); + DIEInteger Zero(0); + Mem1->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, + &Zero); Mem1->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef); + + Unnamed.addChild(std::move(Mem1)); + + auto Mem2 = make_unique(dwarf::DW_TAG_member); + DIEString Mem2Str(&Four, "mem2"); + Mem2->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &Mem2Str); + Mem2->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, + &Four); Mem2->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntRef); + Unnamed.addChild(std::move(Mem2)); + uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed); ASSERT_EQ(0x3a7dc3ed7b76b2f8ULL, MD5Res); @@ -159,14 +161,14 @@ TEST(DIEHashTest, RecursiveType) { DIEString FooStr(&One, "foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); DIEString MemStr(&One, "mem"); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); DIEEntry FooRef(Foo); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRef); // DW_AT_external and DW_AT_declaration are ignored anyway, so skip them. - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); @@ -181,7 +183,7 @@ TEST(DIEHashTest, Pointer) { DIEString FooStr(&Eight, "foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); DIEString MemStr(&Eight, "mem"); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); DIEInteger Zero(0); @@ -195,7 +197,7 @@ TEST(DIEHashTest, Pointer) { DIEEntry FooPtrRef(FooPtr); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooPtrRef); - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); @@ -210,7 +212,7 @@ TEST(DIEHashTest, Reference) { DIEString FooStr(&Eight, "foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); DIEString MemStr(&Eight, "mem"); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); DIEInteger Zero(0); @@ -228,7 +230,7 @@ TEST(DIEHashTest, Reference) { DIEEntry FooRefConstRef(FooRefConst); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefConstRef); - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); @@ -243,7 +245,7 @@ TEST(DIEHashTest, RValueReference) { DIEString FooStr(&Eight, "foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); DIEString MemStr(&Eight, "mem"); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); DIEInteger Zero(0); @@ -261,7 +263,7 @@ TEST(DIEHashTest, RValueReference) { DIEEntry FooRefConstRef(FooRefConst); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FooRefConstRef); - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); @@ -276,7 +278,7 @@ TEST(DIEHashTest, PtrToMember) { DIEString FooStr(&Eight, "foo"); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); DIEString MemStr(&Eight, "mem"); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); DIEInteger Zero(0); @@ -291,7 +293,7 @@ TEST(DIEHashTest, PtrToMember) { DIEEntry PtrToFooMemRef(PtrToFooMem); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef); - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); @@ -320,7 +322,7 @@ TEST(DIEHashTest, PtrToMemberDeclDefMatch) { Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero); @@ -335,7 +337,7 @@ TEST(DIEHashTest, PtrToMemberDeclDefMatch) { DIEEntry PtrToFooMemRef(PtrToFooMem); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef); - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); MD5ResDecl = DIEHash().computeTypeSignature(Foo); } @@ -349,7 +351,7 @@ TEST(DIEHashTest, PtrToMemberDeclDefMatch) { Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero); @@ -364,7 +366,7 @@ TEST(DIEHashTest, PtrToMemberDeclDefMatch) { DIEEntry PtrToFooMemRef(PtrToFooMem); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef); - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); MD5ResDef = DIEHash().computeTypeSignature(Foo); } @@ -393,7 +395,7 @@ TEST(DIEHashTest, PtrToMemberDeclDefMisMatch) { Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero); @@ -407,7 +409,7 @@ TEST(DIEHashTest, PtrToMemberDeclDefMisMatch) { DIEEntry PtrToFooMemRef(PtrToFooMem); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef); - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); MD5ResDecl = DIEHash().computeTypeSignature(Foo); } @@ -421,7 +423,7 @@ TEST(DIEHashTest, PtrToMemberDeclDefMisMatch) { Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero); @@ -435,7 +437,7 @@ TEST(DIEHashTest, PtrToMemberDeclDefMisMatch) { DIEEntry PtrToFooMemRef(PtrToFooMem); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PtrToFooMemRef); - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); MD5ResDef = DIEHash().computeTypeSignature(Foo); } @@ -463,7 +465,7 @@ TEST(DIEHashTest, RefUnnamedType) { Foo.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Eight); Foo.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); - DIE *Mem = new DIE(dwarf::DW_TAG_member); + auto Mem = make_unique(dwarf::DW_TAG_member); Mem->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &MemStr); Mem->addValue(dwarf::DW_AT_data_member_location, dwarf::DW_FORM_data1, &Zero); @@ -475,7 +477,7 @@ TEST(DIEHashTest, RefUnnamedType) { DIEEntry UnnamedPtrRef(UnnamedPtr); Mem->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &UnnamedPtrRef); - Foo.addChild(Mem); + Foo.addChild(std::move(Mem)); uint64_t MD5Res = DIEHash().computeTypeSignature(Foo); @@ -488,12 +490,12 @@ TEST(DIEHashTest, NestedType) { DIEInteger One(1); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); - DIE *Foo = new DIE(dwarf::DW_TAG_structure_type); + auto Foo = make_unique(dwarf::DW_TAG_structure_type); DIEString FooStr(&One, "foo"); Foo->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FooStr); Foo->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); - Unnamed.addChild(Foo); + Unnamed.addChild(std::move(Foo)); uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed); @@ -507,11 +509,11 @@ TEST(DIEHashTest, MemberFunc) { DIEInteger One(1); Unnamed.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One); - DIE *Func = new DIE(dwarf::DW_TAG_subprogram); + auto Func = make_unique(dwarf::DW_TAG_subprogram); DIEString FuncStr(&One, "func"); Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FuncStr); - Unnamed.addChild(Func); + Unnamed.addChild(std::move(Func)); uint64_t MD5Res = DIEHash().computeTypeSignature(Unnamed); @@ -531,7 +533,7 @@ TEST(DIEHashTest, MemberFuncFlag) { A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One); A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One); - DIE *Func = new DIE(dwarf::DW_TAG_subprogram); + auto Func = make_unique(dwarf::DW_TAG_subprogram); DIEString FuncStr(&One, "func"); DIEString FuncLinkage(&One, "_ZN1A4funcEv"); DIEInteger Two(2); @@ -542,7 +544,7 @@ TEST(DIEHashTest, MemberFuncFlag) { Func->addValue(dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, &FuncLinkage); Func->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One); - A.addChild(Func); + A.addChild(std::move(Func)); uint64_t MD5Res = DIEHash().computeTypeSignature(A); @@ -573,11 +575,11 @@ TEST(DIEHashTest, MemberSdata) { IntTyDIE.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FStr); DIEEntry IntTy(IntTyDIE); - DIE *PITyDIE = new DIE(dwarf::DW_TAG_const_type); + auto PITyDIE = make_unique(dwarf::DW_TAG_const_type); PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &IntTy); DIEEntry PITy(*PITyDIE); - DIE *PI = new DIE(dwarf::DW_TAG_member); + auto PI = make_unique(dwarf::DW_TAG_member); DIEString PIStr(&One, "PI"); DIEInteger Two(2); DIEInteger NegThree(-3); @@ -589,7 +591,7 @@ TEST(DIEHashTest, MemberSdata) { PI->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One); PI->addValue(dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, &NegThree); - A.addChild(PI); + A.addChild(std::move(PI)); uint64_t MD5Res = DIEHash().computeTypeSignature(A); ASSERT_EQ(0x9a216000dd3788a7ULL, MD5Res); @@ -611,17 +613,17 @@ TEST(DIEHashTest, MemberBlock) { DIEInteger Four(4); DIEString FStr(&One, "float"); - DIE *FloatTyDIE = new DIE(dwarf::DW_TAG_base_type); + auto FloatTyDIE = make_unique(dwarf::DW_TAG_base_type); FloatTyDIE->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four); FloatTyDIE->addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Four); FloatTyDIE->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FStr); DIEEntry FloatTy(*FloatTyDIE); - DIE *PITyDIE = new DIE(dwarf::DW_TAG_const_type); + auto PITyDIE = make_unique(dwarf::DW_TAG_const_type); PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FloatTy); DIEEntry PITy(*PITyDIE); - DIE *PI = new DIE(dwarf::DW_TAG_member); + auto PI = make_unique(dwarf::DW_TAG_member); DIEString PIStr(&One, "PI"); DIEInteger Two(2); PI->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &PIStr); @@ -644,7 +646,7 @@ TEST(DIEHashTest, MemberBlock) { PI->addValue(dwarf::DW_AT_const_value, dwarf::DW_FORM_block1, &PIBlock); - A.addChild(PI); + A.addChild(std::move(PI)); uint64_t MD5Res = DIEHash().computeTypeSignature(A); ASSERT_EQ(0x493af53ad3d3f651ULL, MD5Res);