From 5dca5efc0b14c1512cbd8a2902322e1b5b6617cb Mon Sep 17 00:00:00 2001 From: Shafik Yaghmour Date: Fri, 23 Aug 2019 17:19:21 +0000 Subject: [PATCH] Debug Info: Support for DW_AT_export_symbols for anonymous structs 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 a new (DI)flag to LLVM metadata: ExportSymbols Differential Revision: https://reviews.llvm.org/D66352 llvm-svn: 369781 --- llvm/docs/LangRef.rst | 5 +++ llvm/include/llvm/IR/DebugInfoFlags.def | 3 +- llvm/include/llvm/IR/DebugInfoMetadata.h | 1 + .../export-symbol-anonymous-class.ll | 38 +++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 llvm/test/Assembler/export-symbol-anonymous-class.ll diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 880259572aa2..55ba443dddf5 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -4834,6 +4834,11 @@ after the function prologue. The language frontend is expected to compute this property for each DILocalVariable. The flag should be used only in optimized code. +The `ExportSymbols` flag marks a class, struct or union whose members +may be referenced as if they were defined in the containing class or +union. This flag is used to decide whether the DW_AT_export_symbols can +be used for the structure type. + DIObjCProperty """""""""""""" diff --git a/llvm/include/llvm/IR/DebugInfoFlags.def b/llvm/include/llvm/IR/DebugInfoFlags.def index 07e3d6bdc9e5..c6c696523fbb 100644 --- a/llvm/include/llvm/IR/DebugInfoFlags.def +++ b/llvm/include/llvm/IR/DebugInfoFlags.def @@ -42,8 +42,7 @@ HANDLE_DI_FLAG((1 << 11), Vector) HANDLE_DI_FLAG((1 << 12), StaticMember) HANDLE_DI_FLAG((1 << 13), LValueReference) HANDLE_DI_FLAG((1 << 14), RValueReference) -// 15 was formerly ExternalTypeRef, but this was never used. -HANDLE_DI_FLAG((1 << 15), Reserved) +HANDLE_DI_FLAG((1 << 15), ExportSymbols) HANDLE_DI_FLAG((1 << 16), SingleInheritance) HANDLE_DI_FLAG((2 << 16), MultipleInheritance) HANDLE_DI_FLAG((3 << 16), VirtualInheritance) diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h index 9dc6dfbb0f68..1f0533d98f63 100644 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -668,6 +668,7 @@ public: } bool isBigEndian() const { return getFlags() & FlagBigEndian; } bool isLittleEndian() const { return getFlags() & FlagLittleEndian; } + bool getExportSymbols() const { return getFlags() & FlagExportSymbols; } static bool classof(const Metadata *MD) { switch (MD->getMetadataID()) { diff --git a/llvm/test/Assembler/export-symbol-anonymous-class.ll b/llvm/test/Assembler/export-symbol-anonymous-class.ll new file mode 100644 index 000000000000..29fedbd8894b --- /dev/null +++ b/llvm/test/Assembler/export-symbol-anonymous-class.ll @@ -0,0 +1,38 @@ +; Round trip for the following: +; ``` +; struct A { +; struct { +; int y; +; }; +; } a; +; ``` +; This is the minimum code to generate export symbols flag due to anonymous class in A. + +; RUN: llvm-as %s -o - | llvm-dis | llvm-as | llvm-dis | FileCheck %s + +%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") +; CHECK: DIFlagExportSymbols | DIFlagTypePassByValue +!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"} -- 2.34.1