@@ -441,6 +441,14 @@ 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, DIExpression *Expr) {
445+ DIELoc *Loc = new (DIEValueAllocator) DIELoc;
446+ DIEDwarfExpression DwarfExpr (*Asm, getCU (), *Loc);
447+ DwarfExpr.setMemoryLocationKind ();
448+ DwarfExpr.addExpression (Expr);
449+ addBlock (Die, Attribute, DwarfExpr.finalize ());
450+ }
451+
444452void DwarfUnit::addSourceLine (DIE &Die, unsigned Line, unsigned Column,
445453 const DIFile *File) {
446454 if (Line == 0 )
@@ -824,27 +832,14 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIStringType *STy) {
824832 if (auto *VarDIE = getDIE (Var))
825833 addDIEEntry (Buffer, dwarf::DW_AT_string_length, *VarDIE);
826834 } 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 ());
835+ addBlock (Buffer, dwarf::DW_AT_string_length, Expr);
835836 } else {
836837 uint64_t Size = STy->getSizeInBits () >> 3 ;
837838 addUInt (Buffer, dwarf::DW_AT_byte_size, std::nullopt , Size);
838839 }
839840
840841 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 ());
842+ addBlock (Buffer, dwarf::DW_AT_data_location, Expr);
848843 }
849844
850845 if (STy->getEncoding ()) {
@@ -1207,11 +1202,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
12071202 addDIEEntry (Buffer, dwarf::DW_AT_bit_size, *VarDIE);
12081203 } else if (auto *Exp =
12091204 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 ());
1205+ addBlock (Buffer, dwarf::DW_AT_bit_size, Exp);
12151206 } else {
12161207 uint64_t Size = CTy->getSizeInBits () >> 3 ;
12171208 // Add size if non-zero (derived types might be zero-sized.)
@@ -1607,11 +1598,7 @@ void DwarfUnit::constructSubrangeDIE(DIE &DW_Subrange, const DISubrangeType *SR,
16071598 if (auto *VarDIE = getDIE (BV))
16081599 addDIEEntry (DW_Subrange, Attr, *VarDIE);
16091600 } 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 ());
1601+ addBlock (DW_Subrange, Attr, BE);
16151602 } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
16161603 if (Attr == dwarf::DW_AT_GNU_bias) {
16171604 if (BI->getSExtValue () != 0 )
@@ -1649,11 +1636,7 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR) {
16491636 if (auto *VarDIE = getDIE (BV))
16501637 addDIEEntry (DW_Subrange, Attr, *VarDIE);
16511638 } 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 ());
1639+ addBlock (DW_Subrange, Attr, BE);
16571640 } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
16581641 if (Attr == dwarf::DW_AT_count) {
16591642 if (BI->getSExtValue () != -1 )
@@ -1699,11 +1682,7 @@ void DwarfUnit::constructGenericSubrangeDIE(DIE &Buffer,
16991682 addSInt (DwGenericSubrange, Attr, dwarf::DW_FORM_sdata,
17001683 BE->getElement (1 ));
17011684 } 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 ());
1685+ addBlock (DwGenericSubrange, Attr, BE);
17071686 }
17081687 }
17091688 };
@@ -1770,44 +1749,28 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
17701749 if (auto *VarDIE = getDIE (Var))
17711750 addDIEEntry (Buffer, dwarf::DW_AT_data_location, *VarDIE);
17721751 } 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 ());
1752+ addBlock (Buffer, dwarf::DW_AT_data_location, Expr);
17781753 }
17791754
17801755 if (DIVariable *Var = CTy->getAssociated ()) {
17811756 if (auto *VarDIE = getDIE (Var))
17821757 addDIEEntry (Buffer, dwarf::DW_AT_associated, *VarDIE);
17831758 } 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 ());
1759+ addBlock (Buffer, dwarf::DW_AT_associated, Expr);
17891760 }
17901761
17911762 if (DIVariable *Var = CTy->getAllocated ()) {
17921763 if (auto *VarDIE = getDIE (Var))
17931764 addDIEEntry (Buffer, dwarf::DW_AT_allocated, *VarDIE);
17941765 } 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 ());
1766+ addBlock (Buffer, dwarf::DW_AT_allocated, Expr);
18001767 }
18011768
18021769 if (auto *RankConst = CTy->getRankConst ()) {
18031770 addSInt (Buffer, dwarf::DW_AT_rank, dwarf::DW_FORM_sdata,
18041771 RankConst->getSExtValue ());
18051772 } 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 ());
1773+ addBlock (Buffer, dwarf::DW_AT_rank, RankExpr);
18111774 }
18121775
18131776 if (auto *BitStride = CTy->getBitStrideConst ()) {
@@ -1917,11 +1880,7 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
19171880 if (auto *VarDIE = getDIE (Var))
19181881 addDIEEntry (MemberDie, dwarf::DW_AT_bit_size, *VarDIE);
19191882 } 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 ());
1883+ addBlock (MemberDie, dwarf::DW_AT_bit_size, Exp);
19251884 } else {
19261885 Size = DT->getSizeInBits ();
19271886 FieldSize = DD->getBaseTypeSize (DT);
@@ -1945,11 +1904,7 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
19451904 } else if (auto *Expr =
19461905 dyn_cast_or_null<DIExpression>(DT->getRawOffsetInBits ())) {
19471906 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 ());
1907+ addBlock (MemberDie, dwarf::DW_AT_data_bit_offset, Expr);
19531908 }
19541909 } else {
19551910 uint32_t AlignInBytes = DT->getAlignInBytes ();
0 commit comments