Skip to content

Commit 5dca5ef

Browse files
committed
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
1 parent e7211bb commit 5dca5ef

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

llvm/docs/LangRef.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4834,6 +4834,11 @@ after the function prologue. The language frontend is expected to compute
48344834
this property for each DILocalVariable. The flag should be used
48354835
only in optimized code.
48364836

4837+
The `ExportSymbols` flag marks a class, struct or union whose members
4838+
may be referenced as if they were defined in the containing class or
4839+
union. This flag is used to decide whether the DW_AT_export_symbols can
4840+
be used for the structure type.
4841+
48374842
DIObjCProperty
48384843
""""""""""""""
48394844

llvm/include/llvm/IR/DebugInfoFlags.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ HANDLE_DI_FLAG((1 << 11), Vector)
4242
HANDLE_DI_FLAG((1 << 12), StaticMember)
4343
HANDLE_DI_FLAG((1 << 13), LValueReference)
4444
HANDLE_DI_FLAG((1 << 14), RValueReference)
45-
// 15 was formerly ExternalTypeRef, but this was never used.
46-
HANDLE_DI_FLAG((1 << 15), Reserved)
45+
HANDLE_DI_FLAG((1 << 15), ExportSymbols)
4746
HANDLE_DI_FLAG((1 << 16), SingleInheritance)
4847
HANDLE_DI_FLAG((2 << 16), MultipleInheritance)
4948
HANDLE_DI_FLAG((3 << 16), VirtualInheritance)

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ class DIType : public DIScope {
668668
}
669669
bool isBigEndian() const { return getFlags() & FlagBigEndian; }
670670
bool isLittleEndian() const { return getFlags() & FlagLittleEndian; }
671+
bool getExportSymbols() const { return getFlags() & FlagExportSymbols; }
671672

672673
static bool classof(const Metadata *MD) {
673674
switch (MD->getMetadataID()) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; Round trip for the following:
2+
; ```
3+
; struct A {
4+
; struct {
5+
; int y;
6+
; };
7+
; } a;
8+
; ```
9+
; This is the minimum code to generate export symbols flag due to anonymous class in A.
10+
11+
; RUN: llvm-as %s -o - | llvm-dis | llvm-as | llvm-dis | FileCheck %s
12+
13+
%struct.A = type { %struct.anon }
14+
%struct.anon = type { i32 }
15+
16+
@a = global %struct.A zeroinitializer, align 4, !dbg !0
17+
18+
!llvm.module.flags = !{!14, !15}
19+
!llvm.dbg.cu = !{!2}
20+
!llvm.ident = !{!16}
21+
22+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
23+
!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 5, type: !6, isLocal: false, isDefinition: true)
24+
!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)
25+
!3 = !DIFile(filename: "simple_anon_class.cpp", directory: "/dir")
26+
!4 = !{}
27+
!5 = !{!0}
28+
!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !3, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !7, identifier: "_ZTS1A")
29+
!7 = !{!8}
30+
!8 = !DIDerivedType(tag: DW_TAG_member, scope: !6, file: !3, line: 2, baseType: !9, size: 32)
31+
!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !6, file: !3, line: 2, size: 32, flags: DIFlagExportSymbols | DIFlagTypePassByValue, elements: !10, identifier: "_ZTSN1AUt_E")
32+
; CHECK: DIFlagExportSymbols | DIFlagTypePassByValue
33+
!10 = !{!11}
34+
!11 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !9, file: !3, line: 3, baseType: !12, size: 32)
35+
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
36+
!14 = !{i32 2, !"Dwarf Version", i32 4}
37+
!15 = !{i32 2, !"Debug Info Version", i32 3}
38+
!16 = !{!"clang version 10.0.0"}

0 commit comments

Comments
 (0)