Skip to content

Commit 1870b52

Browse files
committed
Recommit "PR44685: DebugInfo: Handle address-use-invalid type units referencing non-type units"
Originally committed as be3ef93. Reverted by b4bffdb due to bot failures: http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-expensive/17380/testReport/junit/LLVM/DebugInfo_X86/addr_tu_to_non_tu_ll/ http://45.33.8.238/win/22216/step_11.txt MacOS failure due to testing Split DWARF which isn't compatible with MachO. Windows failure due to testing type units which aren't enabled on Windows. Fix both of these by applying an explicit x86 linux triple to the test.
1 parent 84fffa6 commit 1870b52

File tree

4 files changed

+94
-4
lines changed

4 files changed

+94
-4
lines changed

llvm/lib/CodeGen/AsmPrinter/AddressPool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AddressPool {
4848

4949
bool hasBeenUsed() const { return HasBeenUsed; }
5050

51-
void resetUsedFlag() { HasBeenUsed = false; }
51+
void resetUsedFlag(bool HasBeenUsed = false) { this->HasBeenUsed = HasBeenUsed; }
5252

5353
MCSymbol *getLabel() { return AddressTableBaseSym; }
5454
void setLabel(MCSymbol *Sym) { AddressTableBaseSym = Sym; }

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,14 +3305,14 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
33053305

33063306
DwarfDebug::NonTypeUnitContext::NonTypeUnitContext(DwarfDebug *DD)
33073307
: DD(DD),
3308-
TypeUnitsUnderConstruction(std::move(DD->TypeUnitsUnderConstruction)) {
3308+
TypeUnitsUnderConstruction(std::move(DD->TypeUnitsUnderConstruction)), AddrPoolUsed(DD->AddrPool.hasBeenUsed()) {
33093309
DD->TypeUnitsUnderConstruction.clear();
3310-
assert(TypeUnitsUnderConstruction.empty() || !DD->AddrPool.hasBeenUsed());
3310+
DD->AddrPool.resetUsedFlag();
33113311
}
33123312

33133313
DwarfDebug::NonTypeUnitContext::~NonTypeUnitContext() {
33143314
DD->TypeUnitsUnderConstruction = std::move(TypeUnitsUnderConstruction);
3315-
DD->AddrPool.resetUsedFlag();
3315+
DD->AddrPool.resetUsedFlag(AddrPoolUsed);
33163316
}
33173317

33183318
DwarfDebug::NonTypeUnitContext DwarfDebug::enterNonTypeUnitContext() {

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ class DwarfDebug : public DebugHandlerBase {
648648
class NonTypeUnitContext {
649649
DwarfDebug *DD;
650650
decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction;
651+
bool AddrPoolUsed;
651652
friend class DwarfDebug;
652653
NonTypeUnitContext(DwarfDebug *DD);
653654
public:
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
; RUN: llc -filetype=obj -O0 -generate-type-units -mtriple=x86_64-unknown-linux-gnu -split-dwarf-file=x.dwo < %s \
2+
; RUN: | llvm-dwarfdump -debug-info -debug-types - \
3+
; RUN: | FileCheck --implicit-check-not=Unit --implicit-check-not=contents --implicit-check-not=declaration %s
4+
5+
; Test that an address-using-with-Split-DWARF type unit that references a
6+
; non-type unit is handled correctly. A NonTypeUnitContext is used to insulate
7+
; the type construction from being discarded when the prior/outer type has to be
8+
; discarded due to finding it used an address & so can't be type united under
9+
; Split DWARF.
10+
11+
; The intermediate types tu and t2 are here just to test a bit more
12+
; thoroughly/broadly. They also demonstrate one slight limitation/sub-optimality
13+
; since 't2' isn't put in a type unit.
14+
15+
16+
; extern int foo;
17+
; namespace {
18+
; struct t1 {
19+
; };
20+
; }
21+
; template <int *> struct t2 {
22+
; t1 v1;
23+
; };
24+
; struct t3 {
25+
; t2<&foo> v1;
26+
; };
27+
; t3 v1;
28+
29+
; CHECK: .debug_info contents:
30+
; CHECK: Compile Unit:
31+
32+
; CHECK: .debug_info.dwo contents:
33+
; CHECK: Compile Unit:
34+
35+
; FIXME: In theory "t3" could be in a type unit - but at the moment, because it
36+
; references t2, which needs an address, t3 gets non-type-united.
37+
; But the same doesn't happen if t3 referenced an anonymous namespace type.
38+
39+
; CHECK: DW_TAG_structure_type
40+
; CHECK: DW_AT_name ("t3")
41+
; CHECK: DW_TAG_member
42+
; 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")
46+
; CHECK: DW_TAG_structure_type
47+
; CHECK: DW_AT_name ("t2<&foo>")
48+
; CHECK: DW_TAG_member
49+
; CHECK: DW_AT_name ("v1")
50+
; CHECK: DW_AT_type ([[T1]] "t1")
51+
52+
; CHECK: .debug_types contents:
53+
54+
; CHECK-NOT: .debug_types.dwo contents:
55+
56+
57+
%struct.t3 = type { %struct.t2 }
58+
%struct.t2 = type { %"struct.(anonymous namespace)::t1" }
59+
%"struct.(anonymous namespace)::t1" = type { i8 }
60+
61+
@v1 = dso_local global %struct.t3 zeroinitializer, align 1, !dbg !0
62+
@foo = external dso_local global i32, align 4
63+
64+
!llvm.dbg.cu = !{!2}
65+
!llvm.module.flags = !{!18, !19, !20}
66+
!llvm.ident = !{!21}
67+
68+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
69+
!1 = distinct !DIGlobalVariable(name: "v1", scope: !2, file: !3, line: 16, type: !6, isLocal: false, isDefinition: true)
70+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 12.0.0 ([email protected]:llvm/llvm-project.git be646ae2865371c7a4966797e88f355de5653e04)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "test.dwo", emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: GNU)
71+
!3 = !DIFile(filename: "test.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
72+
!4 = !{}
73+
!5 = !{!0}
74+
!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t3", file: !3, line: 12, size: 8, flags: DIFlagTypePassByValue, elements: !7, identifier: "_ZTS2t3")
75+
!7 = !{!8}
76+
!8 = !DIDerivedType(tag: DW_TAG_member, name: "v1", scope: !6, file: !3, line: 13, baseType: !9, size: 8)
77+
!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t2<&foo>", file: !3, line: 8, size: 8, flags: DIFlagTypePassByValue, elements: !10, templateParams: !14, identifier: "_ZTS2t2IXadL_Z3fooEEE")
78+
!10 = !{!11}
79+
!11 = !DIDerivedType(tag: DW_TAG_member, name: "v1", scope: !9, file: !3, line: 9, baseType: !12, size: 8)
80+
!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", scope: !13, file: !3, line: 4, size: 8, flags: DIFlagTypePassByValue, elements: !4)
81+
!13 = !DINamespace(scope: null)
82+
!14 = !{!15}
83+
!15 = !DITemplateValueParameter(type: !16, value: i32* @foo)
84+
!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64)
85+
!17 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
86+
!18 = !{i32 7, !"Dwarf Version", i32 4}
87+
!19 = !{i32 2, !"Debug Info Version", i32 3}
88+
!20 = !{i32 1, !"wchar_size", i32 4}
89+
!21 = !{!"clang version 12.0.0 ([email protected]:llvm/llvm-project.git be646ae2865371c7a4966797e88f355de5653e04)"}

0 commit comments

Comments
 (0)