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'
8 ; void member_function();
9 ; static int static_member_function();
10 ; static int static_member_variable;
13 ; int C::static_member_variable = 0;
15 ; void C::member_function() {
16 ; static_member_variable = 0;
19 ; int C::static_member_function() {
20 ; return static_member_variable;
25 ; int global_function() {
30 ; void global_namespace_function() {
31 ; global_variable.member_function();
33 ; int global_namespace_variable = 1;
34 ; extern int global_namespace_variable_decl;
40 ; using ns::global_namespace_variable_decl;
64 ; return i + *f3() + inner::b + outer::c;
67 ; ASM: .section .debug_gnu_pubnames
68 ; ASM: .byte 32 # Kind: VARIABLE, EXTERNAL
69 ; ASM-NEXT: .asciz "global_variable" # External Name
71 ; ASM: .section .debug_gnu_pubtypes
72 ; ASM: .byte 16 # Kind: TYPE, EXTERNAL
73 ; ASM-NEXT: .asciz "C" # External Name
75 ; CHECK: .debug_info contents:
76 ; CHECK: Compile Unit:
77 ; CHECK: DW_AT_GNU_pubnames [DW_FORM_flag_present] (true)
78 ; CHECK-NOT: DW_AT_GNU_pubtypes [
80 ; CHECK: [[STATIC_MEM_VAR:0x[0-9a-f]+]]: DW_TAG_variable
81 ; CHECK-NEXT: DW_AT_specification {{.*}} "static_member_variable"
83 ; CHECK: [[C:0x[0-9a-f]+]]: DW_TAG_structure_type
84 ; CHECK-NEXT: DW_AT_name {{.*}} "C"
86 ; CHECK: DW_TAG_member
87 ; CHECK-NEXT: DW_AT_name {{.*}} "static_member_variable"
89 ; CHECK: DW_TAG_subprogram
90 ; CHECK-NEXT: DW_AT_linkage_name
91 ; CHECK-NEXT: DW_AT_name {{.*}} "member_function"
93 ; CHECK: DW_TAG_subprogram
94 ; CHECK-NEXT: DW_AT_linkage_name
95 ; CHECK-NEXT: DW_AT_name {{.*}} "static_member_function"
97 ; CHECK: [[INT:0x[0-9a-f]+]]: DW_TAG_base_type
98 ; CHECK-NEXT: DW_AT_name {{.*}} "int"
100 ; CHECK: [[GLOB_VAR:0x[0-9a-f]+]]: DW_TAG_variable
101 ; CHECK-NEXT: DW_AT_name {{.*}} "global_variable"
103 ; CHECK: [[NS:0x[0-9a-f]+]]: DW_TAG_namespace
104 ; CHECK-NEXT: DW_AT_name {{.*}} "ns"
106 ; CHECK: [[GLOB_NS_VAR:0x[0-9a-f]+]]: DW_TAG_variable
107 ; CHECK-NEXT: DW_AT_name {{.*}} "global_namespace_variable"
108 ; CHECK-NOT: DW_AT_specification
109 ; CHECK: DW_AT_location
110 ; CHECK-NOT: DW_AT_specification
112 ; CHECK: [[D_VAR:0x[0-9a-f]+]]: DW_TAG_variable
113 ; CHECK-NEXT: DW_AT_name {{.*}} "d"
114 ; CHECK-NOT: DW_AT_specification
115 ; CHECK: DW_AT_location
116 ; CHECK-NOT: DW_AT_specification
118 ; CHECK: [[D:0x[0-9a-f]+]]: DW_TAG_structure_type
119 ; CHECK-NEXT: DW_AT_name {{.*}} "D"
121 ; CHECK: [[GLOB_NS_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
123 ; CHECK: DW_AT_linkage_name
125 ; CHECK: DW_AT_name {{.*}} "global_namespace_function"
127 ; CHECK: DW_TAG_subprogram
129 ; CHECK: DW_AT_name {{.*}} "f3"
130 ; CHECK-NOT: {{DW_TAG|NULL}}
131 ; CHECK: [[F3_Z:.*]]: DW_TAG_variable
133 ; CHECK: DW_AT_name {{.*}} "z"
134 ; CHECK-NOT: {{DW_TAG|NULL}}
135 ; CHECK: DW_AT_location
136 ; CHECK-NOT: {{DW_TAG|NULL}}
138 ; CHECK-NOT: {{DW_TAG|NULL}}
140 ; CHECK: [[ANON:.*]]: DW_TAG_namespace
141 ; CHECK-NOT: DW_AT_name
142 ; CHECK: [[ANON_I:.*]]: DW_TAG_variable
144 ; CHECK: DW_AT_name {{.*}} "i"
145 ; CHECK-NOT: {{DW_TAG|NULL}}
146 ; CHECK: [[ANON_INNER:.*]]: DW_TAG_namespace
148 ; CHECK: DW_AT_name {{.*}} "inner"
149 ; CHECK-NOT: {{DW_TAG|NULL}}
150 ; CHECK: [[ANON_INNER_B:.*]]: DW_TAG_variable
152 ; CHECK: DW_AT_name {{.*}} "b"
153 ; CHECK-NOT: {{DW_TAG|NULL}}
155 ; CHECK-NOT: {{DW_TAG|NULL}}
157 ; CHECK-NOT: {{DW_TAG|NULL}}
159 ; CHECK: [[OUTER:.*]]: DW_TAG_namespace
161 ; CHECK: DW_AT_name {{.*}} "outer"
162 ; CHECK-NOT: {{DW_TAG|NULL}}
163 ; CHECK: [[OUTER_ANON:.*]]: DW_TAG_namespace
164 ; CHECK-NOT: {{DW_TAG|NULL}}
165 ; CHECK-NOT: DW_AT_name
166 ; CHECK: [[OUTER_ANON_C:.*]]: DW_TAG_variable
168 ; CHECK: DW_AT_name {{.*}} "c"
169 ; CHECK-NOT: {{DW_TAG|NULL}}
171 ; CHECK-NOT: {{DW_TAG|NULL}}
172 ; FIXME: We probably shouldn't bother describing the implicit
173 ; import of the preceding anonymous namespace. This should be fixed
175 ; CHECK: DW_TAG_imported_module
176 ; CHECK-NOT: {{DW_TAG|NULL}}
178 ; CHECK-NOT: {{DW_TAG|NULL}}
180 ; CHECK: DW_TAG_imported_declaration
181 ; CHECK-NOT: {{DW_TAG|NULL}}
183 ; CHECK: [[MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
185 ; CHECK: DW_AT_specification {{.*}} "_ZN1C15member_functionEv"
187 ; CHECK: [[STATIC_MEM_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
189 ; CHECK: DW_AT_specification {{.*}} "_ZN1C22static_member_functionEv"
191 ; CHECK: [[GLOBAL_FUNC:0x[0-9a-f]+]]: DW_TAG_subprogram
193 ; CHECK: DW_AT_linkage_name
195 ; CHECK: DW_AT_name {{.*}} "global_function"
197 ; CHECK-LABEL: .debug_gnu_pubnames contents:
198 ; CHECK-NEXT: length = {{.*}} version = 0x0002 unit_offset = 0x00000000 unit_size = {{.*}}
199 ; CHECK-NEXT: Offset Linkage Kind Name
200 ; CHECK-NEXT: [[GLOBAL_FUNC]] EXTERNAL FUNCTION "global_function"
201 ; CHECK-NEXT: [[NS]] EXTERNAL TYPE "ns"
202 ; CHECK-NEXT: [[OUTER_ANON_C]] STATIC VARIABLE "outer::(anonymous namespace)::c"
203 ; CHECK-NEXT: [[ANON_I]] STATIC VARIABLE "(anonymous namespace)::i"
204 ; GCC Doesn't put local statics in pubnames, but it seems not unreasonable and
205 ; comes out naturally from LLVM's implementation, so I'm OK with it for now. If
206 ; it's demonstrated that this is a major size concern or degrades debug info
207 ; consumer behavior, feel free to change it.
208 ; CHECK-NEXT: [[F3_Z]] STATIC VARIABLE "f3::z"
209 ; CHECK-NEXT: [[ANON]] EXTERNAL TYPE "(anonymous namespace)"
210 ; CHECK-NEXT: [[OUTER_ANON]] EXTERNAL TYPE "outer::(anonymous namespace)"
211 ; CHECK-NEXT: [[ANON_INNER_B]] STATIC VARIABLE "(anonymous namespace)::inner::b"
212 ; CHECK-NEXT: [[OUTER]] EXTERNAL TYPE "outer"
213 ; CHECK-NEXT: [[MEM_FUNC]] EXTERNAL FUNCTION "C::member_function"
214 ; CHECK-NEXT: [[GLOB_VAR]] EXTERNAL VARIABLE "global_variable"
215 ; CHECK-NEXT: [[GLOB_NS_VAR]] EXTERNAL VARIABLE "ns::global_namespace_variable"
216 ; CHECK-NEXT: [[ANON_INNER]] EXTERNAL TYPE "(anonymous namespace)::inner"
217 ; CHECK-NEXT: [[D_VAR]] EXTERNAL VARIABLE "ns::d"
218 ; CHECK-NEXT: [[GLOB_NS_FUNC]] EXTERNAL FUNCTION "ns::global_namespace_function"
219 ; CHECK-NEXT: [[STATIC_MEM_VAR]] EXTERNAL VARIABLE "C::static_member_variable"
220 ; CHECK-NEXT: [[STATIC_MEM_FUNC]] EXTERNAL FUNCTION "C::static_member_function"
224 ; CHECK-LABEL: debug_gnu_pubtypes contents:
225 ; CHECK: Offset Linkage Kind Name
226 ; CHECK-DAG: [[C]] EXTERNAL TYPE "C"
227 ; CHECK-DAG: [[D]] EXTERNAL TYPE "ns::D"
228 ; CHECK-DAG: [[INT]] STATIC TYPE "int"
230 %struct.C = type { i8 }
231 %"struct.ns::D" = type { i32 }
233 @_ZN1C22static_member_variableE = global i32 0, align 4
234 @global_variable = global %struct.C zeroinitializer, align 1
235 @_ZN2ns25global_namespace_variableE = global i32 1, align 4
236 @_ZN2ns1dE = global %"struct.ns::D" zeroinitializer, align 4
237 @_ZZ2f3vE1z = internal global i32 0, align 4
238 @_ZN12_GLOBAL__N_11iE = internal global i32 0, align 4
239 @_ZN12_GLOBAL__N_15inner1bE = internal global i32 0, align 4
240 @_ZN5outer12_GLOBAL__N_11cE = internal global i32 0, align 4
242 ; Function Attrs: nounwind uwtable
243 define void @_ZN1C15member_functionEv(%struct.C* %this) #0 align 2 !dbg !20 {
245 %this.addr = alloca %struct.C*, align 8
246 store %struct.C* %this, %struct.C** %this.addr, align 8
247 call void @llvm.dbg.declare(metadata %struct.C** %this.addr, metadata !51, metadata !53), !dbg !54
248 %this1 = load %struct.C*, %struct.C** %this.addr
249 store i32 0, i32* @_ZN1C22static_member_variableE, align 4, !dbg !55
253 ; Function Attrs: nounwind readnone
254 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
256 ; Function Attrs: nounwind uwtable
257 define i32 @_ZN1C22static_member_functionEv() #0 align 2 !dbg !21 {
259 %0 = load i32, i32* @_ZN1C22static_member_variableE, align 4, !dbg !57
263 ; Function Attrs: nounwind uwtable
264 define i32 @_Z15global_functionv() #0 !dbg !22 {
269 ; Function Attrs: nounwind uwtable
270 define void @_ZN2ns25global_namespace_functionEv() #0 !dbg !23 {
272 call void @_ZN1C15member_functionEv(%struct.C* @global_variable), !dbg !59
276 ; Function Attrs: nounwind uwtable
277 define i32* @_Z2f3v() #0 !dbg !26 {
279 ret i32* @_ZZ2f3vE1z, !dbg !61
282 ; Function Attrs: nounwind uwtable
283 define i32 @_Z2f7v() #0 !dbg !30 {
285 %0 = load i32, i32* @_ZN12_GLOBAL__N_11iE, align 4, !dbg !62
286 %call = call i32* @_Z2f3v(), !dbg !62
287 %1 = load i32, i32* %call, align 4, !dbg !62
288 %add = add nsw i32 %0, %1, !dbg !62
289 %2 = load i32, i32* @_ZN12_GLOBAL__N_15inner1bE, align 4, !dbg !62
290 %add1 = add nsw i32 %add, %2, !dbg !62
291 %3 = load i32, i32* @_ZN5outer12_GLOBAL__N_11cE, align 4, !dbg !62
292 %add2 = add nsw i32 %add1, %3, !dbg !62
293 ret i32 %add2, !dbg !62
296 attributes #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" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
297 attributes #1 = { nounwind readnone }
300 !llvm.module.flags = !{!48, !49}
303 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.7.0 (trunk 234897) (llvm/trunk 234911)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !3, subprograms: !19, globals: !31, imports: !44)
304 !1 = !DIFile(filename: "gnu-public-names.cpp", directory: "/tmp/dbginfo")
307 !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !1, line: 1, size: 8, align: 8, elements: !5, identifier: "_ZTS1C")
309 !6 = !DIDerivedType(tag: DW_TAG_member, name: "static_member_variable", scope: !"_ZTS1C", file: !1, line: 4, baseType: !7, flags: DIFlagStaticMember)
310 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
311 !8 = !DISubprogram(name: "member_function", linkageName: "_ZN1C15member_functionEv", scope: !"_ZTS1C", file: !1, line: 2, type: !9, isLocal: false, isDefinition: false, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false)
312 !9 = !DISubroutineType(types: !10)
314 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !"_ZTS1C", size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
315 !12 = !DISubprogram(name: "static_member_function", linkageName: "_ZN1C22static_member_functionEv", scope: !"_ZTS1C", file: !1, line: 3, type: !13, isLocal: false, isDefinition: false, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false)
316 !13 = !DISubroutineType(types: !14)
318 !15 = !DICompositeType(tag: DW_TAG_structure_type, name: "D", scope: !16, file: !1, line: 29, size: 32, align: 32, elements: !17, identifier: "_ZTSN2ns1DE")
319 !16 = !DINamespace(name: "ns", scope: null, file: !1, line: 23)
321 !18 = !DIDerivedType(tag: DW_TAG_member, name: "A", scope: !"_ZTSN2ns1DE", file: !1, line: 30, baseType: !7, size: 32, align: 32)
322 !19 = !{!20, !21, !22, !23, !26, !30}
323 !20 = distinct !DISubprogram(name: "member_function", linkageName: "_ZN1C15member_functionEv", scope: !"_ZTS1C", file: !1, line: 9, type: !9, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, declaration: !8, variables: !2)
324 !21 = distinct !DISubprogram(name: "static_member_function", linkageName: "_ZN1C22static_member_functionEv", scope: !"_ZTS1C", file: !1, line: 13, type: !13, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: false, declaration: !12, variables: !2)
325 !22 = distinct !DISubprogram(name: "global_function", linkageName: "_Z15global_functionv", scope: !1, file: !1, line: 19, type: !13, isLocal: false, isDefinition: true, scopeLine: 19, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
326 !23 = distinct !DISubprogram(name: "global_namespace_function", linkageName: "_ZN2ns25global_namespace_functionEv", scope: !16, file: !1, line: 24, type: !24, isLocal: false, isDefinition: true, scopeLine: 24, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
327 !24 = !DISubroutineType(types: !25)
329 !26 = distinct !DISubprogram(name: "f3", linkageName: "_Z2f3v", scope: !1, file: !1, line: 40, type: !27, isLocal: false, isDefinition: true, scopeLine: 40, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
330 !27 = !DISubroutineType(types: !28)
332 !29 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, align: 64)
333 !30 = distinct !DISubprogram(name: "f7", linkageName: "_Z2f7v", scope: !1, file: !1, line: 57, type: !13, isLocal: false, isDefinition: true, scopeLine: 57, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
334 !31 = !{!32, !33, !34, !35, !36, !37, !39, !41}
335 !32 = !DIGlobalVariable(name: "static_member_variable", linkageName: "_ZN1C22static_member_variableE", scope: !0, file: !1, line: 7, type: !7, isLocal: false, isDefinition: true, variable: i32* @_ZN1C22static_member_variableE, declaration: !6)
336 !33 = !DIGlobalVariable(name: "global_variable", scope: !0, file: !1, line: 17, type: !"_ZTS1C", isLocal: false, isDefinition: true, variable: %struct.C* @global_variable)
337 !34 = !DIGlobalVariable(name: "global_namespace_variable", linkageName: "_ZN2ns25global_namespace_variableE", scope: !16, file: !1, line: 27, type: !7, isLocal: false, isDefinition: true, variable: i32* @_ZN2ns25global_namespace_variableE)
338 !35 = !DIGlobalVariable(name: "d", linkageName: "_ZN2ns1dE", scope: !16, file: !1, line: 31, type: !"_ZTSN2ns1DE", isLocal: false, isDefinition: true, variable: %"struct.ns::D"* @_ZN2ns1dE)
339 !36 = !DIGlobalVariable(name: "z", scope: !26, file: !1, line: 41, type: !7, isLocal: true, isDefinition: true, variable: i32* @_ZZ2f3vE1z)
340 !37 = !DIGlobalVariable(name: "i", linkageName: "_ZN12_GLOBAL__N_11iE", scope: !38, file: !1, line: 37, type: !7, isLocal: true, isDefinition: true, variable: i32* @_ZN12_GLOBAL__N_11iE)
341 !38 = !DINamespace(scope: null, file: !1, line: 36)
342 !39 = !DIGlobalVariable(name: "b", linkageName: "_ZN12_GLOBAL__N_15inner1bE", scope: !40, file: !1, line: 47, type: !7, isLocal: true, isDefinition: true, variable: i32* @_ZN12_GLOBAL__N_15inner1bE)
343 !40 = !DINamespace(name: "inner", scope: !38, file: !1, line: 46)
344 !41 = !DIGlobalVariable(name: "c", linkageName: "_ZN5outer12_GLOBAL__N_11cE", scope: !42, file: !1, line: 53, type: !7, isLocal: true, isDefinition: true, variable: i32* @_ZN5outer12_GLOBAL__N_11cE)
345 !42 = !DINamespace(scope: !43, file: !1, line: 52)
346 !43 = !DINamespace(name: "outer", scope: null, file: !1, line: 51)
348 !45 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !0, entity: !46, line: 34)
349 !46 = !DIGlobalVariable(name: "global_namespace_variable_decl", linkageName: "_ZN2ns30global_namespace_variable_declE", scope: !16, file: !1, line: 28, type: !7, isLocal: false, isDefinition: false)
350 !47 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !43, entity: !42, line: 43)
351 !48 = !{i32 2, !"Dwarf Version", i32 4}
352 !49 = !{i32 2, !"Debug Info Version", i32 3}
353 !50 = !{!"clang version 3.7.0 (trunk 234897) (llvm/trunk 234911)"}
354 !51 = !DILocalVariable(name: "this", arg: 1, scope: !20, type: !52, flags: DIFlagArtificial | DIFlagObjectPointer)
355 !52 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !"_ZTS1C", size: 64, align: 64)
356 !53 = !DIExpression()
357 !54 = !DILocation(line: 0, scope: !20)
358 !55 = !DILocation(line: 10, scope: !20)
359 !56 = !DILocation(line: 11, scope: !20)
360 !57 = !DILocation(line: 14, scope: !21)
361 !58 = !DILocation(line: 20, scope: !22)
362 !59 = !DILocation(line: 25, scope: !23)
363 !60 = !DILocation(line: 26, scope: !23)
364 !61 = !DILocation(line: 42, scope: !26)
365 !62 = !DILocation(line: 58, scope: !30)