1 ; REQUIRES: object-emission
3 ; RUN: %llc_dwarf -O0 -filetype=obj < %s > %t
4 ; RUN: llvm-dwarfdump %t | FileCheck %s
5 ; CHECK: debug_info contents
6 ; CHECK: [[NS1:0x[0-9a-f]*]]:{{ *}}DW_TAG_namespace
7 ; CHECK-NEXT: DW_AT_name{{.*}} = "A"
8 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F1:".*debug-info-namespace.cpp"]])
9 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(5)
11 ; CHECK: [[NS2:0x[0-9a-f]*]]:{{ *}}DW_TAG_namespace
12 ; CHECK-NEXT: DW_AT_name{{.*}} = "B"
13 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2:".*foo.cpp"]])
14 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(1)
16 ; CHECK: [[I:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable
17 ; CHECK-NEXT: DW_AT_name{{.*}}= "i"
18 ; CHECK: [[VAR_FWD:0x[0-9a-f]*]]:{{ *}}DW_TAG_variable
19 ; CHECK-NEXT: DW_AT_name{{.*}}= "var_fwd"
21 ; CHECK: [[FOO:0x[0-9a-f]*]]:{{ *}}DW_TAG_structure_type
22 ; CHECK-NEXT: DW_AT_name{{.*}}= "foo"
23 ; CHECK-NEXT: DW_AT_declaration
25 ; CHECK: [[BAR:0x[0-9a-f]*]]:{{ *}}DW_TAG_structure_type
26 ; CHECK-NEXT: DW_AT_name{{.*}}= "bar"
27 ; CHECK: [[FUNC1:.*]]: DW_TAG_subprogram
29 ; CHECK: DW_AT_MIPS_linkage_name
31 ; CHECK: DW_AT_name{{.*}}= "f1"
32 ; CHECK: [[BAZ:0x[0-9a-f]*]]:{{.*}}DW_TAG_typedef
34 ; CHECK: DW_AT_name{{.*}}= "baz"
35 ; CHECK: [[VAR_DECL:0x[0-9a-f]*]]:{{.*}}DW_TAG_variable
37 ; CHECK: DW_AT_name{{.*}}= "var_decl"
39 ; CHECK: DW_AT_declaration
40 ; CHECK: [[FUNC_DECL:0x[0-9a-f]*]]:{{.*}}DW_TAG_subprogram
42 ; CHECK: DW_AT_name{{.*}}= "func_decl"
44 ; CHECK: DW_AT_declaration
45 ; CHECK: [[FUNC_FWD:0x[0-9a-f]*]]:{{.*}}DW_TAG_subprogram
47 ; CHECK: DW_AT_name{{.*}}= "func_fwd"
48 ; CHECK-NOT: DW_AT_declaration
49 ; CHECK: DW_TAG_subprogram
51 ; CHECK: DW_AT_MIPS_linkage_name
53 ; CHECK: DW_AT_name{{.*}}= "f1"
57 ; CHECK: DW_TAG_imported_module
58 ; This is a bug, it should be in F2 but it inherits the file from its
60 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F1]])
61 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(15)
62 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS2]]})
66 ; CHECK: DW_TAG_imported_module
67 ; Same bug as above, this should be F2, not F1
68 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F1]])
69 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(18)
70 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]})
73 ; CHECK: DW_TAG_subprogram
75 ; CHECK: DW_AT_MIPS_linkage_name
77 ; CHECK: DW_AT_name{{.*}}= "func"
79 ; CHECK: DW_TAG_imported_module
80 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
81 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(26)
82 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]})
84 ; CHECK: DW_TAG_imported_declaration
85 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
86 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(27)
87 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FOO]]})
89 ; CHECK: DW_TAG_imported_declaration
90 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
91 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(28)
92 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[BAR]]})
94 ; CHECK: DW_TAG_imported_declaration
95 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
96 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(29)
97 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FUNC1]]})
99 ; CHECK: DW_TAG_imported_declaration
100 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
101 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(30)
102 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[I]]})
104 ; CHECK: DW_TAG_imported_declaration
105 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
106 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(31)
107 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[BAZ]]})
109 ; CHECK: [[X:0x[0-9a-f]*]]:{{ *}}DW_TAG_imported_declaration
110 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
111 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(32)
112 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS1]]})
113 ; CHECK-NEXT: DW_AT_name{{.*}}"X"
115 ; CHECK: DW_TAG_imported_declaration
116 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
117 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(33)
118 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[X]]})
119 ; CHECK-NEXT: DW_AT_name{{.*}}"Y"
121 ; CHECK: DW_TAG_imported_declaration
122 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
123 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(34)
124 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[VAR_DECL]]})
125 ; CHECK: DW_TAG_imported_declaration
126 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
127 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(35)
128 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FUNC_DECL]]})
129 ; CHECK: DW_TAG_imported_declaration
130 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
131 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(36)
132 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[VAR_FWD]]})
133 ; CHECK: DW_TAG_imported_declaration
134 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
135 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(37)
136 ; CHECK-NEXT: DW_AT_import{{.*}}=> {[[FUNC_FWD]]})
138 ; CHECK: DW_TAG_lexical_block
140 ; CHECK: DW_TAG_imported_module
141 ; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F2]])
142 ; CHECK-NEXT: DW_AT_decl_line{{.*}}(23)
143 ; CHECK-NEXT: DW_AT_import{{.*}}=>
148 ; IR generated from clang/test/CodeGenCXX/debug-info-namespace.cpp, file paths
149 ; changed to protect the guilty. The C++ source code is:
158 ; int f1() { return 0; }
163 ; extern int var_decl;
164 ; void func_decl(void);
165 ; extern int var_fwd;
166 ; void func_fwd(void);
178 ; using namespace A::B;
190 ; using B::func_decl;
193 ; return i + X::B::i + Y::B::i;
202 ; void B::func_fwd() {}
204 @_ZN1A1B1iE = global i32 0, align 4
205 @_ZN1A1B7var_fwdE = global i32 0, align 4
206 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_debug_info_namespace.cpp, i8* null }]
208 ; Function Attrs: nounwind ssp uwtable
209 define i32 @_ZN1A1B2f1Ev() #0 {
214 ; Function Attrs: nounwind ssp uwtable
215 define void @_ZN1A1B2f1Ei(i32) #0 {
217 %.addr = alloca i32, align 4
218 store i32 %0, i32* %.addr, align 4
219 call void @llvm.dbg.declare(metadata i32* %.addr, metadata !61, metadata !62), !dbg !63
223 ; Function Attrs: nounwind readnone
224 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
226 define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" {
228 %call = call i32 @_ZN1A1B2f1Ev(), !dbg !65
229 store i32 %call, i32* @_ZN1A1B1iE, align 4, !dbg !65
233 ; Function Attrs: nounwind ssp uwtable
234 define i32 @_Z4funcb(i1 zeroext %b) #0 {
236 %retval = alloca i32, align 4
237 %b.addr = alloca i8, align 1
238 %frombool = zext i1 %b to i8
239 store i8 %frombool, i8* %b.addr, align 1
240 call void @llvm.dbg.declare(metadata i8* %b.addr, metadata !66, metadata !62), !dbg !67
241 %0 = load i8, i8* %b.addr, align 1, !dbg !68
242 %tobool = trunc i8 %0 to i1, !dbg !68
243 br i1 %tobool, label %if.then, label %if.end, !dbg !68
245 if.then: ; preds = %entry
246 %1 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !69
247 store i32 %1, i32* %retval, !dbg !69
248 br label %return, !dbg !69
250 if.end: ; preds = %entry
251 %2 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !70
252 %3 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !70
253 %add = add nsw i32 %2, %3, !dbg !70
254 %4 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !70
255 %add1 = add nsw i32 %add, %4, !dbg !70
256 store i32 %add1, i32* %retval, !dbg !70
257 br label %return, !dbg !70
259 return: ; preds = %if.end, %if.then
260 %5 = load i32, i32* %retval, !dbg !71
264 define internal void @__cxx_global_var_init1() section "__TEXT,__StaticInit,regular,pure_instructions" {
266 %0 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !72
267 store i32 %0, i32* @_ZN1A1B7var_fwdE, align 4, !dbg !72
271 ; Function Attrs: nounwind ssp uwtable
272 define void @_ZN1A1B8func_fwdEv() #0 {
277 define internal void @_GLOBAL__sub_I_debug_info_namespace.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" {
279 call void @__cxx_global_var_init(), !dbg !74
280 call void @__cxx_global_var_init1(), !dbg !74
284 attributes #0 = { nounwind ssp 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" }
285 attributes #1 = { nounwind readnone }
288 !llvm.module.flags = !{!57, !58}
291 !0 = !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.6.0 ", isOptimized: false, emissionKind: 1, file: !1, enums: !2, retainedTypes: !3, subprograms: !9, globals: !30, imports: !33)
292 !1 = !DIFile(filename: "debug-info-namespace.cpp", directory: "/tmp")
295 !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "foo", line: 5, flags: DIFlagFwdDecl, file: !5, scope: !6, identifier: "_ZTSN1A1B3fooE")
296 !5 = !DIFile(filename: "foo.cpp", directory: "/tmp")
297 !6 = !DINamespace(name: "B", line: 1, file: !5, scope: !7)
298 !7 = !DINamespace(name: "A", line: 5, file: !1, scope: null)
299 !8 = !DICompositeType(tag: DW_TAG_structure_type, name: "bar", line: 6, size: 8, align: 8, file: !5, scope: !6, elements: !2, identifier: "_ZTSN1A1B3barE")
300 !9 = !{!10, !14, !17, !21, !25, !26, !27}
301 !10 = !DISubprogram(name: "f1", linkageName: "_ZN1A1B2f1Ev", line: 3, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 3, file: !5, scope: !6, type: !11, function: i32 ()* @_ZN1A1B2f1Ev, variables: !2)
302 !11 = !DISubroutineType(types: !12)
304 !13 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
305 !14 = !DISubprogram(name: "f1", linkageName: "_ZN1A1B2f1Ei", line: 4, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 4, file: !5, scope: !6, type: !15, function: void (i32)* @_ZN1A1B2f1Ei, variables: !2)
306 !15 = !DISubroutineType(types: !16)
308 !17 = !DISubprogram(name: "__cxx_global_var_init", line: 20, isLocal: true, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 20, file: !5, scope: !18, type: !19, function: void ()* @__cxx_global_var_init, variables: !2)
309 !18 = !DIFile(filename: "foo.cpp", directory: "/tmp")
310 !19 = !DISubroutineType(types: !20)
312 !21 = !DISubprogram(name: "func", linkageName: "_Z4funcb", line: 21, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 21, file: !5, scope: !18, type: !22, function: i32 (i1)* @_Z4funcb, variables: !2)
313 !22 = !DISubroutineType(types: !23)
315 !24 = !DIBasicType(tag: DW_TAG_base_type, name: "bool", size: 8, align: 8, encoding: DW_ATE_boolean)
316 !25 = !DISubprogram(name: "__cxx_global_var_init1", line: 44, isLocal: true, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 44, file: !5, scope: !18, type: !19, function: void ()* @__cxx_global_var_init1, variables: !2)
317 !26 = !DISubprogram(name: "func_fwd", linkageName: "_ZN1A1B8func_fwdEv", line: 47, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 47, file: !5, scope: !6, type: !19, function: void ()* @_ZN1A1B8func_fwdEv, variables: !2)
318 !27 = !DISubprogram(name: "", linkageName: "_GLOBAL__sub_I_debug_info_namespace.cpp", isLocal: true, isDefinition: true, flags: DIFlagArtificial, isOptimized: false, file: !1, scope: !28, type: !29, function: void ()* @_GLOBAL__sub_I_debug_info_namespace.cpp, variables: !2)
319 !28 = !DIFile(filename: "debug-info-namespace.cpp", directory: "/tmp")
320 !29 = !DISubroutineType(types: !2)
322 !31 = !DIGlobalVariable(name: "i", linkageName: "_ZN1A1B1iE", line: 20, isLocal: false, isDefinition: true, scope: !6, file: !18, type: !13, variable: i32* @_ZN1A1B1iE)
323 !32 = !DIGlobalVariable(name: "var_fwd", linkageName: "_ZN1A1B7var_fwdE", line: 44, isLocal: false, isDefinition: true, scope: !6, file: !18, type: !13, variable: i32* @_ZN1A1B7var_fwdE)
324 !33 = !{!34, !35, !36, !37, !40, !41, !42, !43, !44, !45, !47, !48, !49, !51, !54, !55, !56}
325 !34 = !DIImportedEntity(tag: DW_TAG_imported_module, line: 15, scope: !7, entity: !6)
326 !35 = !DIImportedEntity(tag: DW_TAG_imported_module, line: 18, scope: !0, entity: !7)
327 !36 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 19, name: "E", scope: !0, entity: !7)
328 !37 = !DIImportedEntity(tag: DW_TAG_imported_module, line: 23, scope: !38, entity: !6)
329 !38 = distinct !DILexicalBlock(line: 22, column: 10, file: !5, scope: !39)
330 !39 = distinct !DILexicalBlock(line: 22, column: 7, file: !5, scope: !21)
331 !40 = !DIImportedEntity(tag: DW_TAG_imported_module, line: 26, scope: !21, entity: !7)
332 !41 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 27, scope: !21, entity: !"_ZTSN1A1B3fooE")
333 !42 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 28, scope: !21, entity: !"_ZTSN1A1B3barE")
334 !43 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 29, scope: !21, entity: !14)
335 !44 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 30, scope: !21, entity: !31)
336 !45 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 31, scope: !21, entity: !46)
337 !46 = !DIDerivedType(tag: DW_TAG_typedef, name: "baz", line: 7, file: !5, scope: !6, baseType: !"_ZTSN1A1B3barE")
338 !47 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 32, name: "X", scope: !21, entity: !7)
339 !48 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 33, name: "Y", scope: !21, entity: !47)
340 !49 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 34, scope: !21, entity: !50)
341 !50 = !DIGlobalVariable(name: "var_decl", linkageName: "_ZN1A1B8var_declE", line: 8, isLocal: false, isDefinition: false, scope: !6, file: !18, type: !13)
342 !51 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 35, scope: !21, entity: !52)
343 !52 = !DISubprogram(name: "func_decl", linkageName: "_ZN1A1B9func_declEv", line: 9, isLocal: false, isDefinition: false, flags: DIFlagPrototyped, isOptimized: false, file: !5, scope: !6, type: !19, variables: !53)
344 !53 = !{} ; previously: invalid DW_TAG_base_type
345 !54 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 36, scope: !21, entity: !32)
346 !55 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 37, scope: !21, entity: !26)
347 !56 = !DIImportedEntity(tag: DW_TAG_imported_declaration, line: 42, scope: !7, entity: !31)
348 !57 = !{i32 2, !"Dwarf Version", i32 2}
349 !58 = !{i32 2, !"Debug Info Version", i32 3}
350 !59 = !{!"clang version 3.6.0 "}
351 !60 = !DILocation(line: 3, column: 12, scope: !10)
352 !61 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "", line: 4, arg: 1, scope: !14, file: !18, type: !13)
353 !62 = !DIExpression()
354 !63 = !DILocation(line: 4, column: 12, scope: !14)
355 !64 = !DILocation(line: 4, column: 16, scope: !14)
356 !65 = !DILocation(line: 20, column: 12, scope: !17)
357 !66 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "b", line: 21, arg: 1, scope: !21, file: !18, type: !24)
358 !67 = !DILocation(line: 21, column: 15, scope: !21)
359 !68 = !DILocation(line: 22, column: 7, scope: !21)
360 !69 = !DILocation(line: 24, column: 5, scope: !38)
361 !70 = !DILocation(line: 38, column: 3, scope: !21)
362 !71 = !DILocation(line: 39, column: 1, scope: !21)
363 !72 = !DILocation(line: 44, column: 15, scope: !25)
364 !73 = !DILocation(line: 47, column: 21, scope: !26)
365 !74 = !DILocation(line: 0, scope: !75)
366 !75 = !DILexicalBlockFile(discriminator: 0, file: !5, scope: !27)