]> granicus.if.org Git - llvm/commitdiff
Debug Info: Support for DW_AT_export_symbols for anonymous structs
authorShafik Yaghmour <syaghmour@apple.com>
Mon, 26 Aug 2019 20:59:44 +0000 (20:59 +0000)
committerShafik Yaghmour <syaghmour@apple.com>
Mon, 26 Aug 2019 20:59:44 +0000 (20:59 +0000)
This implements the DWARF 5 feature described in:

http://dwarfstd.org/ShowIssue.php?issue=141212.1

To support recognizing anonymous structs:

  struct A {
    struct { // Anonymous struct
        int y;
    };
  } a

This patch adds support for the new flag in constructTypeDIE(...) and test to verify this change.

Differential Revision: https://reviews.llvm.org/D66605

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369969 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DwarfUnit.cpp
test/DebugInfo/Generic/export-symbol-anonymous-class.ll [new file with mode: 0644]

index 4990ea66cc1134c39fc8274a2e67c072816b9026..834ea358736fde4922312b3e269eee7fc3cb8227 100644 (file)
@@ -946,6 +946,9 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
     if (CTy->isAppleBlockExtension())
       addFlag(Buffer, dwarf::DW_AT_APPLE_block);
 
+    if (CTy->getExportSymbols())
+      addFlag(Buffer, dwarf::DW_AT_export_symbols);
+
     // This is outside the DWARF spec, but GDB expects a DW_AT_containing_type
     // inside C++ composite types to point to the base class with the vtable.
     // Rust uses DW_AT_containing_type to link a vtable to the type
diff --git a/test/DebugInfo/Generic/export-symbol-anonymous-class.ll b/test/DebugInfo/Generic/export-symbol-anonymous-class.ll
new file mode 100644 (file)
index 0000000..e76e6b5
--- /dev/null
@@ -0,0 +1,43 @@
+; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump -debug-info - | FileCheck %s
+;
+; struct A {
+;  // Anonymous class exports its symbols into A
+;  struct {
+;      int y;
+;  };
+; } a;
+;
+; CHECK: DW_TAG_structure_type
+; CHECK-NEXT: DW_AT_calling_convention (DW_CC_pass_by_value)
+; CHECK-NEXT: DW_AT_name       ("A")
+;
+; CHECK-NOT: NULL
+;
+; CHECK: DW_TAG_structure_type
+; CHECK-NEXT: DW_AT_export_symbols     (true)
+
+%struct.A = type { %struct.anon }
+%struct.anon = type { i32 }
+
+@a = global %struct.A zeroinitializer, align 4, !dbg !0
+
+!llvm.module.flags = !{!14, !15}
+!llvm.dbg.cu = !{!2}
+!llvm.ident = !{!16}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 5, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: GNU)
+!3 = !DIFile(filename: "simple_anon_class.cpp", directory: "/dir")
+!4 = !{}
+!5 = !{!0}
+!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !3, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !7, identifier: "_ZTS1A")
+!7 = !{!8}
+!8 = !DIDerivedType(tag: DW_TAG_member, scope: !6, file: !3, line: 2, baseType: !9, size: 32)
+!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !6, file: !3, line: 2, size: 32, flags: DIFlagExportSymbols | DIFlagTypePassByValue, elements: !10, identifier: "_ZTSN1AUt_E")
+!10 = !{!11}
+!11 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !9, file: !3, line: 3, baseType: !12, size: 32)
+!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!14 = !{i32 2, !"Dwarf Version", i32 4}
+!15 = !{i32 2, !"Debug Info Version", i32 3}
+!16 = !{!"clang version 10.0.0"}