1; RUN: llc -mtriple=x86_64-pc-linux-gnu -generate-gnu-dwarf-pub-sections < %s | FileCheck -check-prefix=ASM %s
2; RUN: llc -mtriple=x86_64-pc-linux-gnu -generate-gnu-dwarf-pub-sections -filetype=obj < %s | llvm-dwarfdump - | FileCheck %s
3; ModuleID = 'dwarf-public-names.cpp'
4;
5; Generated from:
6;
7; struct C {
8;   void member_function();
9;   static int static_member_function();
10;   static int static_member_variable;
11; };
12;
13; int C::static_member_variable = 0;
14;
15; void C::member_function() {
16;   static_member_variable = 0;
17; }
18;
19; int C::static_member_function() {
20;   return static_member_variable;
21; }
22;
23; C global_variable;
24;
25; int global_function() {
26;   return -1;
27; }
28;
29; namespace ns {
30;   void global_namespace_function() {
31;     global_variable.member_function();
32;   }
33;   int global_namespace_variable = 1;
34;   struct D {
35;     int A;
36;   } d;
37; }
38
39; ASM: .section        .debug_gnu_pubnames
40; ASM: .byte   32                      # Kind: VARIABLE, EXTERNAL
41; ASM-NEXT: .asciz  "global_variable"       # External Name
42
43; ASM: .section        .debug_gnu_pubtypes
44; ASM: .byte   16                      # Kind: TYPE, EXTERNAL
45; ASM-NEXT: .asciz  "C"                     # External Name
46
47; CHECK: .debug_info contents:
48; CHECK: Compile Unit:
49; CHECK: DW_AT_GNU_pubnames [DW_FORM_flag_present]   (true)
50; CHECK-NOT: DW_AT_GNU_pubtypes [
51
52; CHECK: [[STATIC_MEM_VAR:0x[0-9a-f]+]]: DW_TAG_variable
53; CHECK-NEXT: DW_AT_specification {{.*}} "static_member_variable"
54
55; CHECK: [[C:0x[0-9a-f]+]]: DW_TAG_structure_type
56; CHECK-NEXT: DW_AT_name {{.*}} "C"
57
58; CHECK: DW_TAG_member
59; CHECK-NEXT: DW_AT_name {{.*}} "static_member_variable"
60
61; CHECK: DW_TAG_subprogram
62; CHECK-NEXT: DW_AT_MIPS_linkage_name
63; CHECK-NEXT: DW_AT_name {{.*}} "member_function"
64
65; CHECK: DW_TAG_subprogram
66; CHECK-NEXT: DW_AT_MIPS_linkage_name
67; CHECK-NEXT: DW_AT_name {{.*}} "static_member_function"
68
69; CHECK: [[INT:0x[0-9a-f]+]]: DW_TAG_base_type
70; CHECK-NEXT: DW_AT_name {{.*}} "int"
71
72; CHECK: [[GLOB_VAR:0x[0-9a-f]+]]: DW_TAG_variable
73; CHECK-NEXT: DW_AT_name {{.*}} "global_variable"
74
75; CHECK: [[NS:0x[0-9a-f]+]]: DW_TAG_namespace
76; CHECK-NEXT: DW_AT_name {{.*}} "ns"
77
78; CHECK: [[GLOB_NS_VAR:0x[0-9a-f]+]]: DW_TAG_variable
79; CHECK-NEXT: DW_AT_name {{.*}} "global_namespace_variable"
80; CHECK-NOT: DW_AT_specification
81; CHECK: DW_AT_location
82; CHECK-NOT: DW_AT_specification
83
84; CHECK: [[D_VAR:0x[0-9a-f]+]]: DW_TAG_variable
85; CHECK-NEXT: DW_AT_name {{.*}} "d"
86; CHECK-NOT: DW_AT_specification
87; CHECK: DW_AT_location
88; CHECK-NOT: DW_AT_specification
89
90; CHECK: [[D:0x[0-9a-f]+]]: DW_TAG_structure_type
91; CHECK-NEXT: DW_AT_name {{.*}} "D"
92
93; CHECK: [[GLOB_NS_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
94; CHECK-NOT: DW_TAG
95; CHECK: DW_AT_MIPS_linkage_name
96; CHECK-NOT: DW_TAG
97; CHECK: DW_AT_name {{.*}} "global_namespace_function"
98
99; CHECK: DW_TAG_subprogram
100; CHECK-NOT: DW_TAG
101; CHECK:   DW_AT_name {{.*}} "f3"
102; CHECK-NOT: {{DW_TAG|NULL}}
103; CHECK: [[F3_Z:.*]]:   DW_TAG_variable
104; CHECK-NOT: DW_TAG
105; CHECK:     DW_AT_name {{.*}} "z"
106; CHECK-NOT: {{DW_TAG|NULL}}
107; CHECK:     DW_AT_location
108; CHECK-NOT: {{DW_TAG|NULL}}
109; CHECK:   NULL
110; CHECK-NOT: {{DW_TAG|NULL}}
111
112; CHECK: [[OUTER:.*]]: DW_TAG_namespace
113; CHECK-NOT: DW_TAG
114; CHECK:   DW_AT_name {{.*}} "outer"
115; CHECK-NOT: {{DW_TAG|NULL}}
116; CHECK: [[OUTER_ANON:.*]]:  DW_TAG_namespace
117; CHECK-NOT: {{DW_TAG|NULL}}
118; CHECK-NOT:     DW_AT_name
119; CHECK: [[OUTER_ANON_C:.*]]: DW_TAG_variable
120; CHECK-NOT: DW_TAG
121; CHECK:       DW_AT_name {{.*}} "c"
122; CHECK-NOT: {{DW_TAG|NULL}}
123; CHECK:     NULL
124; CHECK-NOT: {{DW_TAG|NULL}}
125; FIXME: We probably shouldn't bother describing the implicit
126; import of the preceding anonymous namespace. This should be fixed
127; in clang.
128; CHECK:     DW_TAG_imported_module
129; CHECK-NOT: {{DW_TAG|NULL}}
130; CHECK:   NULL
131; CHECK-NOT: {{DW_TAG|NULL}}
132
133; CHECK: [[ANON:.*]]: DW_TAG_namespace
134; CHECK-NOT:   DW_AT_name
135; CHECK: [[ANON_INNER:.*]]:  DW_TAG_namespace
136; CHECK-NOT: DW_TAG
137; CHECK:     DW_AT_name {{.*}} "inner"
138; CHECK-NOT: {{DW_TAG|NULL}}
139; CHECK: [[ANON_INNER_B:.*]]: DW_TAG_variable
140; CHECK-NOT: DW_TAG
141; CHECK:       DW_AT_name {{.*}} "b"
142; CHECK-NOT: {{DW_TAG|NULL}}
143; CHECK:     NULL
144; CHECK-NOT: {{DW_TAG|NULL}}
145; CHECK: [[ANON_I:.*]]: DW_TAG_variable
146; CHECK-NOT: DW_TAG
147; CHECK:     DW_AT_name {{.*}} "i"
148; CHECK-NOT: {{DW_TAG|NULL}}
149; CHECK:   NULL
150; CHECK-NOT: {{DW_TAG|NULL}}
151
152; CHECK: [[MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
153; CHECK-NOT: DW_TAG
154; CHECK: DW_AT_specification {{.*}} "_ZN1C15member_functionEv"
155
156; CHECK: [[STATIC_MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
157; CHECK-NOT: DW_TAG
158; CHECK: DW_AT_specification {{.*}} "_ZN1C22static_member_functionEv"
159
160; CHECK: [[GLOBAL_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
161; CHECK-NOT: DW_TAG
162; CHECK: DW_AT_MIPS_linkage_name
163; CHECK-NOT: DW_TAG
164; CHECK: DW_AT_name {{.*}} "global_function"
165
166; CHECK-LABEL: .debug_gnu_pubnames contents:
167; CHECK-NEXT: length = {{.*}} version = 0x0002 unit_offset = 0x00000000 unit_size = {{.*}}
168; CHECK-NEXT: Offset     Linkage  Kind     Name
169; CHECK-DAG:  [[GLOBAL_FUNC]] EXTERNAL FUNCTION "global_function"
170; CHECK-DAG:  [[NS]] EXTERNAL TYPE     "ns"
171; CHECK-DAG:  [[MEM_FUNC]] EXTERNAL FUNCTION "C::member_function"
172; CHECK-DAG:  [[GLOB_VAR]] EXTERNAL VARIABLE "global_variable"
173; CHECK-DAG:  [[GLOB_NS_VAR]] EXTERNAL VARIABLE "ns::global_namespace_variable"
174; CHECK-DAG:  [[GLOB_NS_FUNC]] EXTERNAL FUNCTION "ns::global_namespace_function"
175; CHECK-DAG:  [[D_VAR]] EXTERNAL VARIABLE "ns::d"
176; CHECK-DAG:  [[STATIC_MEM_VAR]] EXTERNAL VARIABLE "C::static_member_variable"
177; CHECK-DAG:  [[STATIC_MEM_FUNC]] EXTERNAL FUNCTION "C::static_member_function"
178; CHECK-DAG:  [[ANON]] EXTERNAL TYPE "(anonymous namespace)"
179; CHECK-DAG:  [[ANON_INNER]] EXTERNAL TYPE "(anonymous namespace)::inner"
180; CHECK-DAG:  [[OUTER]] EXTERNAL TYPE "outer"
181; CHECK-DAG:  [[OUTER_ANON]] EXTERNAL TYPE "outer::(anonymous namespace)"
182; CHECK-DAG:  [[ANON_I]] STATIC VARIABLE "(anonymous namespace)::i"
183; CHECK-DAG:  [[ANON_INNER_B]] STATIC VARIABLE "(anonymous namespace)::inner::b"
184; CHECK-DAG:  [[OUTER_ANON_C]] STATIC VARIABLE "outer::(anonymous namespace)::c"
185
186; GCC Doesn't put local statics in pubnames, but it seems not unreasonable and
187; comes out naturally from LLVM's implementation, so I'm OK with it for now. If
188; it's demonstrated that this is a major size concern or degrades debug info
189; consumer behavior, feel free to change it.
190
191; CHECK-DAG:  [[F3_Z]] STATIC VARIABLE "f3::z"
192
193
194; CHECK-LABEL: debug_gnu_pubtypes contents:
195; CHECK: Offset     Linkage  Kind     Name
196; CHECK-DAG:  [[C]] EXTERNAL TYPE     "C"
197; CHECK-DAG:  [[D]] EXTERNAL TYPE     "ns::D"
198; CHECK-DAG:  [[INT]] STATIC   TYPE     "int"
199
200%struct.C = type { i8 }
201%"struct.ns::D" = type { i32 }
202
203@_ZN1C22static_member_variableE = global i32 0, align 4
204@global_variable = global %struct.C zeroinitializer, align 1
205@_ZN2ns25global_namespace_variableE = global i32 1, align 4
206@_ZN2ns1dE = global %"struct.ns::D" zeroinitializer, align 4
207@_ZZ2f3vE1z = internal global i32 0, align 4
208@_ZN12_GLOBAL__N_11iE = internal global i32 0, align 4
209@_ZN12_GLOBAL__N_15inner1bE = internal global i32 0, align 4
210@_ZN5outer12_GLOBAL__N_11cE = internal global i32 0, align 4
211
212; Function Attrs: nounwind uwtable
213define void @_ZN1C15member_functionEv(%struct.C* %this) #0 align 2 {
214entry:
215  %this.addr = alloca %struct.C*, align 8
216  store %struct.C* %this, %struct.C** %this.addr, align 8
217  call void @llvm.dbg.declare(metadata %struct.C** %this.addr, metadata !50, metadata !{!"0x102"}), !dbg !52
218  %this1 = load %struct.C** %this.addr
219  store i32 0, i32* @_ZN1C22static_member_variableE, align 4, !dbg !53
220  ret void, !dbg !54
221}
222
223; Function Attrs: nounwind readnone
224declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
225
226; Function Attrs: nounwind uwtable
227define i32 @_ZN1C22static_member_functionEv() #0 align 2 {
228entry:
229  %0 = load i32* @_ZN1C22static_member_variableE, align 4, !dbg !55
230  ret i32 %0, !dbg !55
231}
232
233; Function Attrs: nounwind uwtable
234define i32 @_Z15global_functionv() #0 {
235entry:
236  ret i32 -1, !dbg !56
237}
238
239; Function Attrs: nounwind uwtable
240define void @_ZN2ns25global_namespace_functionEv() #0 {
241entry:
242  call void @_ZN1C15member_functionEv(%struct.C* @global_variable), !dbg !57
243  ret void, !dbg !58
244}
245
246; Function Attrs: nounwind uwtable
247define i32* @_Z2f3v() #0 {
248entry:
249  ret i32* @_ZZ2f3vE1z, !dbg !59
250}
251
252; Function Attrs: nounwind uwtable
253define i32 @_Z2f7v() #0 {
254entry:
255  %0 = load i32* @_ZN12_GLOBAL__N_11iE, align 4, !dbg !60
256  %call = call i32* @_Z2f3v(), !dbg !60
257  %1 = load i32* %call, align 4, !dbg !60
258  %add = add nsw i32 %0, %1, !dbg !60
259  %2 = load i32* @_ZN12_GLOBAL__N_15inner1bE, align 4, !dbg !60
260  %add1 = add nsw i32 %add, %2, !dbg !60
261  %3 = load i32* @_ZN5outer12_GLOBAL__N_11cE, align 4, !dbg !60
262  %add2 = add nsw i32 %add1, %3, !dbg !60
263  ret i32 %add2, !dbg !60
264}
265
266attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
267attributes #1 = { nounwind readnone }
268
269!llvm.dbg.cu = !{!0}
270!llvm.module.flags = !{!47, !48}
271!llvm.ident = !{!49}
272
273!0 = !{!"0x11\004\00clang version 3.5.0 \000\00\000\00\001", !1, !2, !3, !19, !32, !45} ; [ DW_TAG_compile_unit ] [/tmp/dbginfo/pubnames.cpp] [DW_LANG_C_plus_plus]
274!1 = !{!"pubnames.cpp", !"/tmp/dbginfo"}
275!2 = !{}
276!3 = !{!4, !15}
277!4 = !{!"0x13\00C\001\008\008\000\000\000", !1, null, null, !5, null, null, !"_ZTS1C"} ; [ DW_TAG_structure_type ] [C] [line 1, size 8, align 8, offset 0] [def] [from ]
278!5 = !{!6, !8, !12}
279!6 = !{!"0xd\00static_member_variable\004\000\000\000\004096", !1, !"_ZTS1C", !7, null} ; [ DW_TAG_member ] [static_member_variable] [line 4, size 0, align 0, offset 0] [static] [from int]
280!7 = !{!"0x24\00int\000\0032\0032\000\000\005", null, null} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
281!8 = !{!"0x2e\00member_function\00member_function\00_ZN1C15member_functionEv\002\000\000\000\006\00256\000\002", !1, !"_ZTS1C", !9, null, null, null, i32 0, null} ; [ DW_TAG_subprogram ] [line 2] [member_function]
282!9 = !{!"0x15\00\000\000\000\000\000\000", i32 0, null, null, !10, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
283!10 = !{null, !11}
284!11 = !{!"0xf\00\000\0064\0064\000\001088", null, null, !"_ZTS1C"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [artificial] [from _ZTS1C]
285!12 = !{!"0x2e\00static_member_function\00static_member_function\00_ZN1C22static_member_functionEv\003\000\000\000\006\00256\000\003", !1, !"_ZTS1C", !13, null, null, null, i32 0, null} ; [ DW_TAG_subprogram ] [line 3] [static_member_function]
286!13 = !{!"0x15\00\000\000\000\000\000\000", i32 0, null, null, !14, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
287!14 = !{!7}
288!15 = !{!"0x13\00D\0028\0032\0032\000\000\000", !1, !16, null, !17, null, null, !"_ZTSN2ns1DE"} ; [ DW_TAG_structure_type ] [D] [line 28, size 32, align 32, offset 0] [def] [from ]
289!16 = !{!"0x39\00ns\0023", !1, null} ; [ DW_TAG_namespace ] [ns] [line 23]
290!17 = !{!18}
291!18 = !{!"0xd\00A\0029\0032\0032\000\000", !1, !"_ZTSN2ns1DE", !7} ; [ DW_TAG_member ] [A] [line 29, size 32, align 32, offset 0] [from int]
292!19 = !{!20, !21, !22, !24, !27, !31}
293!20 = !{!"0x2e\00member_function\00member_function\00_ZN1C15member_functionEv\009\000\001\000\006\00256\000\009", !1, !"_ZTS1C", !9, null, void (%struct.C*)* @_ZN1C15member_functionEv, null, !8, !2} ; [ DW_TAG_subprogram ] [line 9] [def] [member_function]
294!21 = !{!"0x2e\00static_member_function\00static_member_function\00_ZN1C22static_member_functionEv\0013\000\001\000\006\00256\000\0013", !1, !"_ZTS1C", !13, null, i32 ()* @_ZN1C22static_member_functionEv, null, !12, !2} ; [ DW_TAG_subprogram ] [line 13] [def] [static_member_function]
295!22 = !{!"0x2e\00global_function\00global_function\00_Z15global_functionv\0019\000\001\000\006\00256\000\0019", !1, !23, !13, null, i32 ()* @_Z15global_functionv, null, null, !2} ; [ DW_TAG_subprogram ] [line 19] [def] [global_function]
296!23 = !{!"0x29", !1}         ; [ DW_TAG_file_type ] [/tmp/dbginfo/pubnames.cpp]
297!24 = !{!"0x2e\00global_namespace_function\00global_namespace_function\00_ZN2ns25global_namespace_functionEv\0024\000\001\000\006\00256\000\0024", !1, !16, !25, null, void ()* @_ZN2ns25global_namespace_functionEv, null, null, !2} ; [ DW_TAG_subprogram ] [line 24] [def] [global_namespace_function]
298!25 = !{!"0x15\00\000\000\000\000\000\000", i32 0, null, null, !26, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
299!26 = !{null}
300!27 = !{!"0x2e\00f3\00f3\00_Z2f3v\0037\000\001\000\006\00256\000\0037", !1, !23, !28, null, i32* ()* @_Z2f3v, null, null, !2} ; [ DW_TAG_subprogram ] [line 37] [def] [f3]
301!28 = !{!"0x15\00\000\000\000\000\000\000", i32 0, null, null, !29, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
302!29 = !{!30}
303!30 = !{!"0xf\00\000\0064\0064\000\000", null, null, !7} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from int]
304!31 = !{!"0x2e\00f7\00f7\00_Z2f7v\0054\000\001\000\006\00256\000\0054", !1, !23, !13, null, i32 ()* @_Z2f7v, null, null, !2} ; [ DW_TAG_subprogram ] [line 54] [def] [f7]
305!32 = !{!33, !34, !35, !36, !37, !38, !41, !44}
306!33 = !{!"0x34\00static_member_variable\00static_member_variable\00_ZN1C22static_member_variableE\007\000\001", null, !23, !7, i32* @_ZN1C22static_member_variableE, !6} ; [ DW_TAG_variable ] [static_member_variable] [line 7] [def]
307!34 = !{!"0x34\00global_variable\00global_variable\00\0017\000\001", null, !23, !"_ZTS1C", %struct.C* @global_variable, null} ; [ DW_TAG_variable ] [global_variable] [line 17] [def]
308!35 = !{!"0x34\00global_namespace_variable\00global_namespace_variable\00_ZN2ns25global_namespace_variableE\0027\000\001", !16, !23, !7, i32* @_ZN2ns25global_namespace_variableE, null} ; [ DW_TAG_variable ] [global_namespace_variable] [line 27] [def]
309!36 = !{!"0x34\00d\00d\00_ZN2ns1dE\0030\000\001", !16, !23, !"_ZTSN2ns1DE", %"struct.ns::D"* @_ZN2ns1dE, null} ; [ DW_TAG_variable ] [d] [line 30] [def]
310!37 = !{!"0x34\00z\00z\00\0038\001\001", !27, !23, !7, i32* @_ZZ2f3vE1z, null} ; [ DW_TAG_variable ] [z] [line 38] [local] [def]
311!38 = !{!"0x34\00c\00c\00_ZN5outer12_GLOBAL__N_11cE\0050\001\001", !39, !23, !7, i32* @_ZN5outer12_GLOBAL__N_11cE, null} ; [ DW_TAG_variable ] [c] [line 50] [local] [def]
312!39 = !{!"0x39\00\0049", !1, !40} ; [ DW_TAG_namespace ] [line 49]
313!40 = !{!"0x39\00outer\0048", !1, null} ; [ DW_TAG_namespace ] [outer] [line 48]
314!41 = !{!"0x34\00b\00b\00_ZN12_GLOBAL__N_15inner1bE\0044\001\001", !42, !23, !7, i32* @_ZN12_GLOBAL__N_15inner1bE, null} ; [ DW_TAG_variable ] [b] [line 44] [local] [def]
315!42 = !{!"0x39\00inner\0043", !1, !43} ; [ DW_TAG_namespace ] [inner] [line 43]
316!43 = !{!"0x39\00\0033", !1, null} ; [ DW_TAG_namespace ] [line 33]
317!44 = !{!"0x34\00i\00i\00_ZN12_GLOBAL__N_11iE\0034\001\001", !43, !23, !7, i32* @_ZN12_GLOBAL__N_11iE, null} ; [ DW_TAG_variable ] [i] [line 34] [local] [def]
318!45 = !{!46}
319!46 = !{!"0x3a\0040\00", !40, !39} ; [ DW_TAG_imported_module ]
320!47 = !{i32 2, !"Dwarf Version", i32 4}
321!48 = !{i32 2, !"Debug Info Version", i32 2}
322!49 = !{!"clang version 3.5.0 "}
323!50 = !{!"0x101\00this\0016777216\001088", !20, null, !51} ; [ DW_TAG_arg_variable ] [this] [line 0]
324!51 = !{!"0xf\00\000\0064\0064\000\000", null, null, !"_ZTS1C"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from _ZTS1C]
325!52 = !MDLocation(line: 0, scope: !20)
326!53 = !MDLocation(line: 10, scope: !20)
327!54 = !MDLocation(line: 11, scope: !20)
328!55 = !MDLocation(line: 14, scope: !21)
329!56 = !MDLocation(line: 20, scope: !22)
330!57 = !MDLocation(line: 25, scope: !24)
331!58 = !MDLocation(line: 26, scope: !24)
332!59 = !MDLocation(line: 39, scope: !27)
333!60 = !MDLocation(line: 55, scope: !31)
334