Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit ab8e654

Browse files
committed
Emit the DW_AT_type for a C++ static member definition
if it is more specific than the one in its DW_AT_specification. If a static member is an array, the translation unit containing the member definition may have a more specific type (including its length) than TUs only seeing the class declaration. This patch adds a DW_AT_type to the member's DW_TAG_variable in addition to the DW_AT_specification in these cases. The member type in the DW_AT_specification still shows the more generic type (without the length) to avoid defeating type uniquing. The DWARF standard discourages “duplicating” a DW_AT_type in a member variable definition but doesn’t explicitly forbid it. Having the more specific type (with the array length) available is what allows the debugger to print the contents of a static array member variable. https://reviews.llvm.org/D26368 rdar://problem/28706946 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286302 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit bb82f0a)
1 parent 07eb96d commit ab8e654

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
9999
// We need the declaration DIE that is in the static member's class.
100100
DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl);
101101
addDIEEntry(*VariableDIE, dwarf::DW_AT_specification, *VariableSpecDIE);
102+
// If the global variable's type is different from the one in the class
103+
// member type, assume that it's more specific and also emit it.
104+
if (GTy != DD->resolve(SDMDecl->getBaseType()))
105+
addType(*VariableDIE, GTy);
102106
} else {
103107
DeclContext = GV->getScope();
104108
// Add name and type.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
; RUN: %llc_dwarf %s -filetype=obj -o - | llvm-dwarfdump -debug-dump=info - | FileCheck %s
2+
; Generated from:
3+
;
4+
; struct A {
5+
; static int fully_specified;
6+
; static int smem[];
7+
; };
8+
;
9+
; int A::fully_specified;
10+
; int A::smem[] = { 0, 1, 2, 3 };
11+
;
12+
; CHECK: DW_TAG_variable
13+
; CHECK-NEXT: DW_AT_specification{{.*}}"fully_specified"
14+
; CHECK-NOT: DW_AT_type
15+
; CHECK: DW_TAG_structure_type
16+
; CHECK: DW_TAG_member
17+
; CHECK: DW_TAG_member
18+
; CHECK-NEXT: DW_AT_name {{.*}} "smem"
19+
; CHECK-NEXT: DW_AT_type {{.*}} {0x[[GENERIC:[0-9]+]]}
20+
;
21+
; CHECK: 0x[[GENERIC]]: DW_TAG_array_type
22+
; CHECK-NOT: DW_TAG
23+
; CHECK-NOT: NULL
24+
; CHECK: DW_TAG_subrange_type
25+
; CHECK-NOT: DW_AT_count
26+
; CHECK: NULL
27+
;
28+
; CHECK: DW_TAG_variable
29+
; CHECK-NEXT: DW_AT_specification {{.*}}"smem"
30+
; CHECK-NEXT: DW_AT_type {{.*}} {0x[[SPECIFIC:[0-9]+]]}
31+
;
32+
; CHECK: 0x[[SPECIFIC]]: DW_TAG_array_type
33+
; CHECK-NOT: DW_TAG
34+
; CHECK-NOT: NULL
35+
; CHECK: DW_TAG_subrange_type
36+
; CHECK-NOT: DW_TAG
37+
; CHECK-NOT: NULL
38+
; CHECK: DW_AT_count {{.*}} (0x04)
39+
40+
source_filename = "static_member_array.cpp"
41+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
42+
target triple = "x86_64-apple-macosx10.12.0"
43+
44+
@_ZN1A15fully_specifiedE = global i32 0, align 4, !dbg !0
45+
@_ZN1A4smemE = global [4 x i32] [i32 0, i32 1, i32 2, i32 3], align 16, !dbg !5
46+
47+
!llvm.dbg.cu = !{!1}
48+
!llvm.module.flags = !{!17, !18, !19}
49+
!llvm.ident = !{!20}
50+
51+
!0 = distinct !DIGlobalVariable(name: "fully_specified", linkageName: "_ZN1A15fully_specifiedE", scope: !1, file: !2, line: 7, type: !7, isLocal: false, isDefinition: true, declaration: !13)
52+
!1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 4.0.0 (trunk 286129) (llvm/trunk 286128)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
53+
!2 = !DIFile(filename: "static_member_array.cpp", directory: "/Volumes/Data/radar/28706946")
54+
!3 = !{}
55+
!4 = !{!0, !5}
56+
!5 = distinct !DIGlobalVariable(name: "smem", linkageName: "_ZN1A4smemE", scope: !1, file: !2, line: 8, type: !6, isLocal: false, isDefinition: true, declaration: !10)
57+
!6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 128, elements: !8)
58+
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
59+
!8 = !{!9}
60+
!9 = !DISubrange(count: 4)
61+
!10 = !DIDerivedType(tag: DW_TAG_member, name: "smem", scope: !11, file: !2, line: 4, baseType: !14, flags: DIFlagStaticMember)
62+
!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !2, line: 1, size: 8, elements: !12, identifier: "_ZTS1A")
63+
!12 = !{!13, !10}
64+
!13 = !DIDerivedType(tag: DW_TAG_member, name: "fully_specified", scope: !11, file: !2, line: 3, baseType: !7, flags: DIFlagStaticMember)
65+
!14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, elements: !15)
66+
!15 = !{!16}
67+
!16 = !DISubrange(count: -1)
68+
!17 = !{i32 2, !"Dwarf Version", i32 4}
69+
!18 = !{i32 2, !"Debug Info Version", i32 3}
70+
!19 = !{i32 1, !"PIC Level", i32 2}
71+
!20 = !{!"clang version 4.0.0 (trunk 286129) (llvm/trunk 286128)"}

0 commit comments

Comments
 (0)