[llvm] 1870b52 - Recommit "PR44685: DebugInfo: Handle address-use-invalid type units referencing non-type units"

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 13:51:23 PDT 2020


Author: David Blaikie
Date: 2020-08-18T13:43:28-07:00
New Revision: 1870b52f0c0880ad9e40eb01344372c59dbc0fb1

URL: https://github.com/llvm/llvm-project/commit/1870b52f0c0880ad9e40eb01344372c59dbc0fb1
DIFF: https://github.com/llvm/llvm-project/commit/1870b52f0c0880ad9e40eb01344372c59dbc0fb1.diff

LOG: Recommit "PR44685: DebugInfo: Handle address-use-invalid type units referencing non-type units"

Originally committed as be3ef93bf58aa5546c7baadfb21d43b75fbb4e24.
Reverted by b4bffdbadfcceb3959aaf231c1542301944e5812 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.

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

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AddressPool.h
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/AddressPool.h b/llvm/lib/CodeGen/AsmPrinter/AddressPool.h
index f92cf72093ca0..f1edc6c330d51 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AddressPool.h
+++ b/llvm/lib/CodeGen/AsmPrinter/AddressPool.h
@@ -48,7 +48,7 @@ class AddressPool {
 
   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 f70eed32f0b53..cee72120accb7 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 0b943ebe46b66..93e08d1151ff7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -648,6 +648,7 @@ class DwarfDebug : public DebugHandlerBase {
   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 0000000000000..e81cb38c2131b
--- /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 -mtriple=x86_64-unknown-linux-gnu -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 }
+
+ at v1 = dso_local global %struct.t3 zeroinitializer, align 1, !dbg !0
+ at 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 at 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 at github.com:llvm/llvm-project.git be646ae2865371c7a4966797e88f355de5653e04)"}


        


More information about the llvm-commits mailing list