diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -83,7 +83,7 @@ if (!Base || Base == Label) { unsigned idx = DD->getAddressPool().getIndex(Label); - Die.addValue(DIEValueAllocator, Attribute, + addAttribute(Die, Attribute, DD->getDwarfVersion() >= 5 ? dwarf::DW_FORM_addrx : dwarf::DW_FORM_GNU_addr_index, DIEInteger(idx)); @@ -100,7 +100,7 @@ addPoolOpAddress(*Loc, Label); addBlock(Die, Attribute, dwarf::DW_FORM_exprloc, Loc); } else - Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_LLVM_addrx_offset, + addAttribute(Die, Attribute, dwarf::DW_FORM_LLVM_addrx_offset, new (DIEValueAllocator) DIEAddrOffset( DD->getAddressPool().getIndex(Base), Label, Base)); } @@ -112,11 +112,9 @@ DD->addArangeLabel(SymbolCU(this, Label)); if (Label) - Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr, - DIELabel(Label)); + addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIELabel(Label)); else - Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr, - DIEInteger(0)); + addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIEInteger(0)); } unsigned DwarfCompileUnit::getOrCreateSourceID(const DIFile *File) { @@ -1472,7 +1470,7 @@ dwarf::Form Form = (DD->getDwarfVersion() >= 5) ? dwarf::DW_FORM_loclistx : DD->getDwarfSectionOffsetForm(); - Die.addValue(DIEValueAllocator, Attribute, Form, DIELocList(Index)); + addAttribute(Die, Attribute, Form, DIELocList(Index)); } void DwarfCompileUnit::applyVariableAttributes(const DbgVariable &Var, @@ -1504,7 +1502,7 @@ /// Add a Dwarf expression attribute data and value. void DwarfCompileUnit::addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr) { - Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, Form, DIEExpr(Expr)); + addAttribute(Die, (dwarf::Attribute)0, Form, DIEExpr(Expr)); } void DwarfCompileUnit::applySubprogramAttributesToDefinition( @@ -1538,7 +1536,7 @@ } void DwarfCompileUnit::addBaseTypeRef(DIEValueList &Die, int64_t Idx) { - Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, dwarf::DW_FORM_udata, + addAttribute(Die, (dwarf::Attribute)0, dwarf::DW_FORM_udata, new (DIEValueAllocator) DIEBaseTypeRef(this, Idx)); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -76,6 +76,13 @@ bool isShareableAcrossCUs(const DINode *D) const; + template + void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute, + dwarf::Form Form, T &&Value) { + Die.addValue(DIEValueAllocator, + DIEValue(Attribute, Form, std::forward(Value))); + } + public: // Accessors. AsmPrinter* getAsmPrinter() const { return Asm; } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -219,11 +219,9 @@ void DwarfUnit::addFlag(DIE &Die, dwarf::Attribute Attribute) { if (DD->getDwarfVersion() >= 4) - Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag_present, - DIEInteger(1)); + addAttribute(Die, Attribute, dwarf::DW_FORM_flag_present, DIEInteger(1)); else - Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag, - DIEInteger(1)); + addAttribute(Die, Attribute, dwarf::DW_FORM_flag, DIEInteger(1)); } void DwarfUnit::addUInt(DIEValueList &Die, dwarf::Attribute Attribute, @@ -232,7 +230,7 @@ Form = DIEInteger::BestForm(false, Integer); assert(Form != dwarf::DW_FORM_implicit_const && "DW_FORM_implicit_const is used only for signed integers"); - Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer)); + addAttribute(Die, Attribute, *Form, DIEInteger(Integer)); } void DwarfUnit::addUInt(DIEValueList &Block, dwarf::Form Form, @@ -244,7 +242,7 @@ Optional Form, int64_t Integer) { if (!Form) Form = DIEInteger::BestForm(true, Integer); - Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer)); + addAttribute(Die, Attribute, *Form, DIEInteger(Integer)); } void DwarfUnit::addSInt(DIELoc &Die, Optional Form, @@ -258,7 +256,7 @@ return; if (DD->useInlineStrings()) { - Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_string, + addAttribute(Die, Attribute, dwarf::DW_FORM_string, new (DIEValueAllocator) DIEInlineString(String, DIEValueAllocator)); return; @@ -282,13 +280,12 @@ else if (Index > 0xff) IxForm = dwarf::DW_FORM_strx2; } - Die.addValue(DIEValueAllocator, Attribute, IxForm, - DIEString(StringPoolEntry)); + addAttribute(Die, Attribute, IxForm, DIEString(StringPoolEntry)); } void DwarfUnit::addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label) { - Die.addValue(DIEValueAllocator, Attribute, Form, DIELabel(Label)); + addAttribute(Die, Attribute, Form, DIELabel(Label)); } void DwarfUnit::addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label) { @@ -355,7 +352,7 @@ void DwarfUnit::addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo) { - Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_data4, + addAttribute(Die, Attribute, dwarf::DW_FORM_data4, new (DIEValueAllocator) DIEDelta(Hi, Lo)); } @@ -370,8 +367,8 @@ // and think this is a full definition. addFlag(Die, dwarf::DW_AT_declaration); - Die.addValue(DIEValueAllocator, dwarf::DW_AT_signature, - dwarf::DW_FORM_ref_sig8, DIEInteger(Signature)); + addAttribute(Die, dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8, + DIEInteger(Signature)); } void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute, @@ -383,7 +380,7 @@ CU = getUnitDie().getUnit(); if (!EntryCU) EntryCU = getUnitDie().getUnit(); - Die.addValue(DIEValueAllocator, Attribute, + addAttribute(Die, Attribute, EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr, Entry); } @@ -398,15 +395,14 @@ void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc) { Loc->ComputeSize(Asm); DIELocs.push_back(Loc); // Memoize so we can call the destructor later on. - Die.addValue(DIEValueAllocator, Attribute, - Loc->BestForm(DD->getDwarfVersion()), Loc); + addAttribute(Die, Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc); } void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form, DIEBlock *Block) { Block->ComputeSize(Asm); DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on. - Die.addValue(DIEValueAllocator, Attribute, Form, Block); + addAttribute(Die, Attribute, Form, Block); } void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, @@ -1639,8 +1635,8 @@ // Objective-C properties. if (DINode *PNode = DT->getObjCProperty()) if (DIE *PDie = getDIE(PNode)) - MemberDie.addValue(DIEValueAllocator, dwarf::DW_AT_APPLE_property, - dwarf::DW_FORM_ref4, DIEEntry(*PDie)); + addAttribute(MemberDie, dwarf::DW_AT_APPLE_property, + dwarf::DW_FORM_ref4, DIEEntry(*PDie)); if (DT->isArtificial()) addFlag(MemberDie, dwarf::DW_AT_artificial); @@ -1746,7 +1742,7 @@ void DwarfUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo) { - Die.addValue(DIEValueAllocator, Attribute, DD->getDwarfSectionOffsetForm(), + addAttribute(Die, Attribute, DD->getDwarfSectionOffsetForm(), new (DIEValueAllocator) DIEDelta(Hi, Lo)); }