Skip to content

Commit a5032b2

Browse files
committed
DebugInfo: Don't allow type units to references types in the CU
We could only do this in limited ways (since we emit the TUs first, we can't use ref_addr (& we can't use that in Split DWARF either) - so we had to synthesize declarations into the TUs) and they were ambiguous in some cases (if the CU type had internal linkage, parsing the TU would require knowing which CU was referencing the TU to know which type the declaration was for, which seems not-ideal). So to avoid all that, let's just not reference types defined in the CU from TUs - instead moving the TU type into the CU (recursively). This does increase debug info size (by pulling more things out of type units, into the compile unit) - about 2% of uncompressed dwp file size for clang -O0 -g -gsplit-dwarf. (5% .debug_info.dwo section size increase in the .dwp)
1 parent 16eaa52 commit a5032b2

File tree

7 files changed

+141
-161
lines changed

7 files changed

+141
-161
lines changed

cross-project-tests/debuginfo-tests/clang_llvm_roundtrip/simplified_template_names.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,21 @@ void t8::mem() {
333333
f1<t7>();
334334
f1<decltype(&t8::mem)>();
335335
}
336+
namespace complex_type_units {
337+
void external_function();
338+
namespace {
339+
struct internal_type;
340+
}
341+
template <void (*)() = external_function> struct t2;
342+
template <typename = t2<>> class t3 {};
343+
template <typename = internal_type, typename = t3<>>
344+
struct t4 {
345+
};
346+
struct t5 {
347+
t4<> v1;
348+
};
349+
void f1() {
350+
t5 v1;
351+
t3<> v2;
352+
}
353+
}

llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
using namespace llvm;
1818

1919
unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
20-
HasBeenUsed = true;
20+
resetUsedFlag(true);
2121
auto IterBool =
2222
Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
2323
return IterBool.first->second.Number;

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,22 +3444,6 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
34443444
CU.addDIETypeSignature(RefDie, Signature);
34453445
}
34463446

3447-
DwarfDebug::NonTypeUnitContext::NonTypeUnitContext(DwarfDebug *DD)
3448-
: DD(DD),
3449-
TypeUnitsUnderConstruction(std::move(DD->TypeUnitsUnderConstruction)), AddrPoolUsed(DD->AddrPool.hasBeenUsed()) {
3450-
DD->TypeUnitsUnderConstruction.clear();
3451-
DD->AddrPool.resetUsedFlag();
3452-
}
3453-
3454-
DwarfDebug::NonTypeUnitContext::~NonTypeUnitContext() {
3455-
DD->TypeUnitsUnderConstruction = std::move(TypeUnitsUnderConstruction);
3456-
DD->AddrPool.resetUsedFlag(AddrPoolUsed);
3457-
}
3458-
3459-
DwarfDebug::NonTypeUnitContext DwarfDebug::enterNonTypeUnitContext() {
3460-
return NonTypeUnitContext(this);
3461-
}
3462-
34633447
// Add the Name along with its companion DIE to the appropriate accelerator
34643448
// table (for AccelTableKind::Dwarf it's always AccelDebugNames, for
34653449
// AccelTableKind::Apple, we use the table we got as an argument). If

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -665,19 +665,6 @@ class DwarfDebug : public DebugHandlerBase {
665665
void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
666666
DIE &Die, const DICompositeType *CTy);
667667

668-
class NonTypeUnitContext {
669-
DwarfDebug *DD;
670-
decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction;
671-
bool AddrPoolUsed;
672-
friend class DwarfDebug;
673-
NonTypeUnitContext(DwarfDebug *DD);
674-
public:
675-
NonTypeUnitContext(NonTypeUnitContext&&) = default;
676-
~NonTypeUnitContext();
677-
};
678-
679-
NonTypeUnitContext enterNonTypeUnitContext();
680-
681668
/// Add a label so that arange data can be generated for it.
682669
void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
683670

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,8 @@ DIE *DwarfUnit::createTypeDIE(const DIScope *Context, DIE &ContextDIE,
592592
// Skip updating the accelerator tables since this is not the full type.
593593
if (MDString *TypeId = CTy->getRawIdentifier())
594594
DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
595-
else {
596-
auto X = DD->enterNonTypeUnitContext();
595+
else
597596
finishNonUnitTypeDIE(TyDIE, CTy);
598-
}
599597
return &TyDIE;
600598
}
601599
constructTypeDIE(TyDIE, CTy);
@@ -1843,11 +1841,5 @@ void DwarfUnit::addRnglistsBase() {
18431841
}
18441842

18451843
void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
1846-
addFlag(D, dwarf::DW_AT_declaration);
1847-
StringRef Name = CTy->getName();
1848-
if (!Name.empty())
1849-
addString(D, dwarf::DW_AT_name, Name);
1850-
if (Name.startswith("_STN") || !Name.contains('<'))
1851-
addTemplateParams(D, CTy->getTemplateParams());
1852-
getCU().createTypeDIE(CTy);
1844+
DD->getAddressPool().resetUsedFlag(true);
18531845
}

llvm/test/DebugInfo/X86/addr-tu-to-non-tu.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
; CHECK: DW_AT_name ("t3")
4141
; CHECK: DW_TAG_member
4242
; CHECK: DW_AT_type {{.*}} "t2<&foo>"
43-
; CHECK: DW_TAG_namespace
44-
; CHECK: [[T1:0x[0-9a-f]*]]: DW_TAG_structure_type
45-
; CHECK: DW_AT_name ("t1")
4643
; CHECK: DW_TAG_structure_type
4744
; CHECK: DW_AT_name ("t2<&foo>")
4845
; CHECK: DW_TAG_member
4946
; CHECK: DW_AT_name ("v1")
50-
; CHECK: DW_AT_type ([[T1]] "(anonymous namespace)::t1")
47+
; CHECK: DW_AT_type ([[T1:0x[0-9a-f]*]] "(anonymous namespace)::t1")
48+
; CHECK: DW_TAG_namespace
49+
; CHECK: [[T1]]: DW_TAG_structure_type
50+
; CHECK: DW_AT_name ("t1")
5151

5252
; CHECK: .debug_types contents:
5353

0 commit comments

Comments
 (0)