@@ -441,6 +441,15 @@ void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute,
441441 addBlock (Die, Attribute, Block->BestForm (), Block);
442442}
443443
444+ void DwarfUnit::addBlock (DIE &Die, dwarf::Attribute Attribute,
445+ const DIExpression *Expr) {
446+ DIELoc *Loc = new (DIEValueAllocator) DIELoc;
447+ DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
448+ DwarfExpr.setMemoryLocationKind ();
449+ DwarfExpr.addExpression (Expr);
450+ addBlock (Die, Attribute, DwarfExpr.finalize ());
451+ }
452+
444453void DwarfUnit::addSourceLine (DIE &Die, unsigned Line, unsigned Column,
445454 const DIFile *File) {
446455 if (Line == 0 )
@@ -824,27 +833,14 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIStringType *STy) {
824833 if (auto *VarDIE = getDIE (Var))
825834 addDIEEntry (Buffer, dwarf::DW_AT_string_length, *VarDIE);
826835 } else if (DIExpression *Expr = STy->getStringLengthExp ()) {
827- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
828- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
829- // This is to describe the memory location of the
830- // length of a Fortran deferred length string, so
831- // lock it down as such.
832- DwarfExpr.setMemoryLocationKind ();
833- DwarfExpr.addExpression (Expr);
834- addBlock (Buffer, dwarf::DW_AT_string_length, DwarfExpr.finalize ());
836+ addBlock (Buffer, dwarf::DW_AT_string_length, Expr);
835837 } else {
836838 uint64_t Size = STy->getSizeInBits () >> 3 ;
837839 addUInt (Buffer, dwarf::DW_AT_byte_size, std::nullopt , Size);
838840 }
839841
840842 if (DIExpression *Expr = STy->getStringLocationExp ()) {
841- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
842- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
843- // This is to describe the memory location of the
844- // string, so lock it down as such.
845- DwarfExpr.setMemoryLocationKind ();
846- DwarfExpr.addExpression (Expr);
847- addBlock (Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize ());
843+ addBlock (Buffer, dwarf::DW_AT_data_location, Expr);
848844 }
849845
850846 if (STy->getEncoding ()) {
@@ -1207,11 +1203,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
12071203 addDIEEntry (Buffer, dwarf::DW_AT_bit_size, *VarDIE);
12081204 } else if (auto *Exp =
12091205 dyn_cast_or_null<DIExpression>(CTy->getRawSizeInBits ())) {
1210- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1211- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1212- DwarfExpr.setMemoryLocationKind ();
1213- DwarfExpr.addExpression (Exp);
1214- addBlock (Buffer, dwarf::DW_AT_bit_size, DwarfExpr.finalize ());
1206+ addBlock (Buffer, dwarf::DW_AT_bit_size, Exp);
12151207 } else {
12161208 uint64_t Size = CTy->getSizeInBits () >> 3 ;
12171209 // Add size if non-zero (derived types might be zero-sized.)
@@ -1607,11 +1599,7 @@ void DwarfUnit::constructSubrangeDIE(DIE &DW_Subrange, const DISubrangeType *SR,
16071599 if (auto *VarDIE = getDIE (BV))
16081600 addDIEEntry (DW_Subrange, Attr, *VarDIE);
16091601 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
1610- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1611- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1612- DwarfExpr.setMemoryLocationKind ();
1613- DwarfExpr.addExpression (BE);
1614- addBlock (DW_Subrange, Attr, DwarfExpr.finalize ());
1602+ addBlock (DW_Subrange, Attr, BE);
16151603 } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
16161604 if (Attr == dwarf::DW_AT_GNU_bias) {
16171605 if (BI->getSExtValue () != 0 )
@@ -1649,11 +1637,7 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR) {
16491637 if (auto *VarDIE = getDIE (BV))
16501638 addDIEEntry (DW_Subrange, Attr, *VarDIE);
16511639 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
1652- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1653- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1654- DwarfExpr.setMemoryLocationKind ();
1655- DwarfExpr.addExpression (BE);
1656- addBlock (DW_Subrange, Attr, DwarfExpr.finalize ());
1640+ addBlock (DW_Subrange, Attr, BE);
16571641 } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
16581642 if (Attr == dwarf::DW_AT_count) {
16591643 if (BI->getSExtValue () != -1 )
@@ -1699,11 +1683,7 @@ void DwarfUnit::constructGenericSubrangeDIE(DIE &Buffer,
16991683 addSInt (DwGenericSubrange, Attr, dwarf::DW_FORM_sdata,
17001684 BE->getElement (1 ));
17011685 } else {
1702- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1703- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1704- DwarfExpr.setMemoryLocationKind ();
1705- DwarfExpr.addExpression (BE);
1706- addBlock (DwGenericSubrange, Attr, DwarfExpr.finalize ());
1686+ addBlock (DwGenericSubrange, Attr, BE);
17071687 }
17081688 }
17091689 };
@@ -1770,44 +1750,28 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
17701750 if (auto *VarDIE = getDIE (Var))
17711751 addDIEEntry (Buffer, dwarf::DW_AT_data_location, *VarDIE);
17721752 } else if (DIExpression *Expr = CTy->getDataLocationExp ()) {
1773- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1774- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1775- DwarfExpr.setMemoryLocationKind ();
1776- DwarfExpr.addExpression (Expr);
1777- addBlock (Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize ());
1753+ addBlock (Buffer, dwarf::DW_AT_data_location, Expr);
17781754 }
17791755
17801756 if (DIVariable *Var = CTy->getAssociated ()) {
17811757 if (auto *VarDIE = getDIE (Var))
17821758 addDIEEntry (Buffer, dwarf::DW_AT_associated, *VarDIE);
17831759 } else if (DIExpression *Expr = CTy->getAssociatedExp ()) {
1784- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1785- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1786- DwarfExpr.setMemoryLocationKind ();
1787- DwarfExpr.addExpression (Expr);
1788- addBlock (Buffer, dwarf::DW_AT_associated, DwarfExpr.finalize ());
1760+ addBlock (Buffer, dwarf::DW_AT_associated, Expr);
17891761 }
17901762
17911763 if (DIVariable *Var = CTy->getAllocated ()) {
17921764 if (auto *VarDIE = getDIE (Var))
17931765 addDIEEntry (Buffer, dwarf::DW_AT_allocated, *VarDIE);
17941766 } else if (DIExpression *Expr = CTy->getAllocatedExp ()) {
1795- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1796- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1797- DwarfExpr.setMemoryLocationKind ();
1798- DwarfExpr.addExpression (Expr);
1799- addBlock (Buffer, dwarf::DW_AT_allocated, DwarfExpr.finalize ());
1767+ addBlock (Buffer, dwarf::DW_AT_allocated, Expr);
18001768 }
18011769
18021770 if (auto *RankConst = CTy->getRankConst ()) {
18031771 addSInt (Buffer, dwarf::DW_AT_rank, dwarf::DW_FORM_sdata,
18041772 RankConst->getSExtValue ());
18051773 } else if (auto *RankExpr = CTy->getRankExp ()) {
1806- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1807- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1808- DwarfExpr.setMemoryLocationKind ();
1809- DwarfExpr.addExpression (RankExpr);
1810- addBlock (Buffer, dwarf::DW_AT_rank, DwarfExpr.finalize ());
1774+ addBlock (Buffer, dwarf::DW_AT_rank, RankExpr);
18111775 }
18121776
18131777 if (auto *BitStride = CTy->getBitStrideConst ()) {
@@ -1917,11 +1881,7 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
19171881 if (auto *VarDIE = getDIE (Var))
19181882 addDIEEntry (MemberDie, dwarf::DW_AT_bit_size, *VarDIE);
19191883 } else if (auto *Exp = dyn_cast<DIExpression>(DT->getRawSizeInBits ())) {
1920- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1921- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1922- DwarfExpr.setMemoryLocationKind ();
1923- DwarfExpr.addExpression (Exp);
1924- addBlock (MemberDie, dwarf::DW_AT_bit_size, DwarfExpr.finalize ());
1884+ addBlock (MemberDie, dwarf::DW_AT_bit_size, Exp);
19251885 } else {
19261886 Size = DT->getSizeInBits ();
19271887 FieldSize = DD->getBaseTypeSize (DT);
@@ -1945,11 +1905,7 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
19451905 } else if (auto *Expr =
19461906 dyn_cast_or_null<DIExpression>(DT->getRawOffsetInBits ())) {
19471907 if (!Asm->TM .Options .DebugStrictDwarf || DD->getDwarfVersion () >= 6 ) {
1948- DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1949- DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
1950- DwarfExpr.setMemoryLocationKind ();
1951- DwarfExpr.addExpression (Expr);
1952- addBlock (MemberDie, dwarf::DW_AT_data_bit_offset, DwarfExpr.finalize ());
1908+ addBlock (MemberDie, dwarf::DW_AT_data_bit_offset, Expr);
19531909 }
19541910 } else {
19551911 uint32_t AlignInBytes = DT->getAlignInBytes ();
0 commit comments