blob: 7bd7ff116eef8ee0528b9104186cb28c3b653824 [file] [log] [blame]
commit be3ef93bf58aa5546c7baadfb21d43b75fbb4e24
Author: David Blaikie <dblaikie@gmail.com>
Date: Mon Aug 17 21:27:19 2020 -0700
PR44685: DebugInfo: Handle address-use-invalid type units referencing non-type units
Theory was that we should never reach a non-type unit (eg: type in an
anonymous namespace) when we're already in the invalid "encountered an
address-use, so stop emitting types for now, until we throw out the
whole type tree to restart emitting in non-type unit" state. But that's
not the case (prior commit cleaned up one reason this wasn't exposed
sooner - but also makes it easier to test/demonstrate this issue)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AddressPool.h b/llvm/lib/CodeGen/AsmPrinter/AddressPool.h
index f92cf72093c..f1edc6c330d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AddressPool.h
+++ b/llvm/lib/CodeGen/AsmPrinter/AddressPool.h
@@ -48,7 +48,7 @@ public:
bool hasBeenUsed() const { return HasBeenUsed; }
- void resetUsedFlag() { HasBeenUsed = false; }
+ void resetUsedFlag(bool HasBeenUsed = false) { this->HasBeenUsed = HasBeenUsed; }
MCSymbol *getLabel() { return AddressTableBaseSym; }
void setLabel(MCSymbol *Sym) { AddressTableBaseSym = Sym; }
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index f70eed32f0b..cee72120acc 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -3305,14 +3305,14 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
DwarfDebug::NonTypeUnitContext::NonTypeUnitContext(DwarfDebug *DD)
: DD(DD),
- TypeUnitsUnderConstruction(std::move(DD->TypeUnitsUnderConstruction)) {
+ TypeUnitsUnderConstruction(std::move(DD->TypeUnitsUnderConstruction)), AddrPoolUsed(DD->AddrPool.hasBeenUsed()) {
DD->TypeUnitsUnderConstruction.clear();
- assert(TypeUnitsUnderConstruction.empty() || !DD->AddrPool.hasBeenUsed());
+ DD->AddrPool.resetUsedFlag();
}
DwarfDebug::NonTypeUnitContext::~NonTypeUnitContext() {
DD->TypeUnitsUnderConstruction = std::move(TypeUnitsUnderConstruction);
- DD->AddrPool.resetUsedFlag();
+ DD->AddrPool.resetUsedFlag(AddrPoolUsed);
}
DwarfDebug::NonTypeUnitContext DwarfDebug::enterNonTypeUnitContext() {
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 0b943ebe46b..93e08d1151f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -648,6 +648,7 @@ public:
class NonTypeUnitContext {
DwarfDebug *DD;
decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction;
+ bool AddrPoolUsed;
friend class DwarfDebug;
NonTypeUnitContext(DwarfDebug *DD);
public:
diff --git a/llvm/test/DebugInfo/X86/addr-tu-to-non-tu.ll b/llvm/test/DebugInfo/X86/addr-tu-to-non-tu.ll
new file mode 100644
index 00000000000..98943b73aef
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/addr-tu-to-non-tu.ll
@@ -0,0 +1,89 @@
+; RUN: llc -filetype=obj -O0 -generate-type-units -split-dwarf-file=x.dwo < %s \
+; RUN: | llvm-dwarfdump -debug-info -debug-types - \
+; RUN: | FileCheck --implicit-check-not=Unit --implicit-check-not=contents --implicit-check-not=declaration %s
+
+; Test that an address-using-with-Split-DWARF type unit that references a
+; non-type unit is handled correctly. A NonTypeUnitContext is used to insulate
+; the type construction from being discarded when the prior/outer type has to be
+; discarded due to finding it used an address & so can't be type united under
+; Split DWARF.
+
+; The intermediate types tu and t2 are here just to test a bit more
+; thoroughly/broadly. They also demonstrate one slight limitation/sub-optimality
+; since 't2' isn't put in a type unit.
+
+
+; extern int foo;
+; namespace {
+; struct t1 {
+; };
+; }
+; template <int *> struct t2 {
+; t1 v1;
+; };
+; struct t3 {
+; t2<&foo> v1;
+; };
+; t3 v1;
+
+; CHECK: .debug_info contents:
+; CHECK: Compile Unit:
+
+; CHECK: .debug_info.dwo contents:
+; CHECK: Compile Unit:
+
+; FIXME: In theory "t3" could be in a type unit - but at the moment, because it
+; references t2, which needs an address, t3 gets non-type-united.
+; But the same doesn't happen if t3 referenced an anonymous namespace type.
+
+; CHECK: DW_TAG_structure_type
+; CHECK: DW_AT_name ("t3")
+; CHECK: DW_TAG_member
+; CHECK: DW_AT_type {{.*}} "t2<&foo>"
+; CHECK: DW_TAG_namespace
+; CHECK: [[T1:0x[0-9a-f]*]]: DW_TAG_structure_type
+; CHECK: DW_AT_name ("t1")
+; CHECK: DW_TAG_structure_type
+; CHECK: DW_AT_name ("t2<&foo>")
+; CHECK: DW_TAG_member
+; CHECK: DW_AT_name ("v1")
+; CHECK: DW_AT_type ([[T1]] "t1")
+
+; CHECK: .debug_types contents:
+
+; CHECK-NOT: .debug_types.dwo contents:
+
+
+%struct.t3 = type { %struct.t2 }
+%struct.t2 = type { %"struct.(anonymous namespace)::t1" }
+%"struct.(anonymous namespace)::t1" = type { i8 }
+
+@v1 = dso_local global %struct.t3 zeroinitializer, align 1, !dbg !0
+@foo = external dso_local global i32, align 4
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!18, !19, !20}
+!llvm.ident = !{!21}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "v1", scope: !2, file: !3, line: 16, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 12.0.0 (git@github.com:llvm/llvm-project.git be646ae2865371c7a4966797e88f355de5653e04)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "test.dwo", emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: GNU)
+!3 = !DIFile(filename: "test.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
+!4 = !{}
+!5 = !{!0}
+!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t3", file: !3, line: 12, size: 8, flags: DIFlagTypePassByValue, elements: !7, identifier: "_ZTS2t3")
+!7 = !{!8}
+!8 = !DIDerivedType(tag: DW_TAG_member, name: "v1", scope: !6, file: !3, line: 13, baseType: !9, size: 8)
+!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")
+!10 = !{!11}
+!11 = !DIDerivedType(tag: DW_TAG_member, name: "v1", scope: !9, file: !3, line: 9, baseType: !12, size: 8)
+!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", scope: !13, file: !3, line: 4, size: 8, flags: DIFlagTypePassByValue, elements: !4)
+!13 = !DINamespace(scope: null)
+!14 = !{!15}
+!15 = !DITemplateValueParameter(type: !16, value: i32* @foo)
+!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64)
+!17 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!18 = !{i32 7, !"Dwarf Version", i32 4}
+!19 = !{i32 2, !"Debug Info Version", i32 3}
+!20 = !{i32 1, !"wchar_size", i32 4}
+!21 = !{!"clang version 12.0.0 (git@github.com:llvm/llvm-project.git be646ae2865371c7a4966797e88f355de5653e04)"}