• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; REQUIRES: object-emission
2
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)
10; CHECK-NOT: NULL
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)
15; CHECK-NOT: NULL
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"
20; CHECK-NOT: NULL
21; CHECK: [[FOO:0x[0-9a-f]*]]:{{ *}}DW_TAG_structure_type
22; CHECK-NEXT: DW_AT_name{{.*}}= "foo"
23; CHECK-NEXT: DW_AT_declaration
24; CHECK-NOT: NULL
25; CHECK: [[BAR:0x[0-9a-f]*]]:{{ *}}DW_TAG_structure_type
26; CHECK-NEXT: DW_AT_name{{.*}}= "bar"
27; CHECK: [[FUNC1:.*]]: DW_TAG_subprogram
28; CHECK-NOT: DW_TAG
29; CHECK: DW_AT_MIPS_linkage_name
30; CHECK-NOT: DW_TAG
31; CHECK: DW_AT_name{{.*}}= "f1"
32; CHECK: [[BAZ:0x[0-9a-f]*]]:{{.*}}DW_TAG_typedef
33; CHECK-NOT: DW_TAG
34; CHECK: DW_AT_name{{.*}}= "baz"
35; CHECK: [[VAR_DECL:0x[0-9a-f]*]]:{{.*}}DW_TAG_variable
36; CHECK-NOT: DW_TAG
37; CHECK: DW_AT_name{{.*}}= "var_decl"
38; CHECK-NOT: DW_TAG
39; CHECK: DW_AT_declaration
40; CHECK: [[FUNC_DECL:0x[0-9a-f]*]]:{{.*}}DW_TAG_subprogram
41; CHECK-NOT: DW_TAG
42; CHECK: DW_AT_name{{.*}}= "func_decl"
43; CHECK-NOT: DW_TAG
44; CHECK: DW_AT_declaration
45; CHECK: [[FUNC_FWD:0x[0-9a-f]*]]:{{.*}}DW_TAG_subprogram
46; CHECK-NOT: DW_TAG
47; CHECK: DW_AT_name{{.*}}= "func_fwd"
48; CHECK-NOT: DW_AT_declaration
49; CHECK: DW_TAG_subprogram
50; CHECK-NOT: DW_TAG
51; CHECK: DW_AT_MIPS_linkage_name
52; CHECK-NOT: DW_TAG
53; CHECK: DW_AT_name{{.*}}= "f1"
54; CHECK: NULL
55
56; CHECK-NOT: NULL
57; CHECK: DW_TAG_imported_module
58; This is a bug, it should be in F2 but it inherits the file from its
59; enclosing scope
60; CHECK-NEXT: DW_AT_decl_file{{.*}}([[F1]])
61; CHECK-NEXT: DW_AT_decl_line{{.*}}(15)
62; CHECK-NEXT: DW_AT_import{{.*}}=> {[[NS2]]})
63; CHECK: NULL
64; CHECK-NOT: NULL
65
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]]})
71; CHECK-NOT: NULL
72
73; CHECK: DW_TAG_subprogram
74; CHECK-NOT: DW_TAG
75; CHECK: DW_AT_MIPS_linkage_name
76; CHECK-NOT: DW_TAG
77; CHECK: DW_AT_name{{.*}}= "func"
78; CHECK-NOT: NULL
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]]})
83; CHECK-NOT: NULL
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]]})
88; CHECK-NOT: NULL
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]]})
93; CHECK-NOT: NULL
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]]})
98; CHECK-NOT: NULL
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]]})
103; CHECK-NOT: NULL
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]]})
108; CHECK-NOT: NULL
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"
114; CHECK-NOT: NULL
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"
120; CHECK-NOT: NULL
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]]})
137
138; CHECK: DW_TAG_lexical_block
139; CHECK-NOT: NULL
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{{.*}}=>
144; CHECK: NULL
145; CHECK: NULL
146; CHECK: NULL
147
148; IR generated from clang/test/CodeGenCXX/debug-info-namespace.cpp, file paths
149; changed to protect the guilty. The C++ source code is:
150; // RUN...
151; // RUN...
152; // RUN...
153;
154; namespace A {
155; #line 1 "foo.cpp"
156; namespace B {
157; extern int i;
158; int f1() { return 0; }
159; void f1(int) { }
160; struct foo;
161; struct bar { };
162; typedef bar baz;
163; extern int var_decl;
164; void func_decl(void);
165; extern int var_fwd;
166; void func_fwd(void);
167; }
168; }
169; namespace A {
170; using namespace B;
171; }
172;
173; using namespace A;
174; namespace E = A;
175; int B::i = f1();
176; int func(bool b) {
177;   if (b) {
178;     using namespace A::B;
179;     return i;
180;   }
181;   using namespace A;
182;   using B::foo;
183;   using B::bar;
184;   using B::f1;
185;   using B::i;
186;   using B::baz;
187;   namespace X = A;
188;   namespace Y = X;
189;   using B::var_decl;
190;   using B::func_decl;
191;   using B::var_fwd;
192;   using B::func_fwd;
193;   return i + X::B::i + Y::B::i;
194; }
195;
196; namespace A {
197; using B::i;
198; namespace B {
199; int var_fwd = i;
200; }
201; }
202; void B::func_fwd() {}
203
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 }]
207
208; Function Attrs: nounwind ssp uwtable
209define i32 @_ZN1A1B2f1Ev() #0 {
210entry:
211  ret i32 0, !dbg !60
212}
213
214; Function Attrs: nounwind ssp uwtable
215define void @_ZN1A1B2f1Ei(i32) #0 {
216entry:
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
220  ret void, !dbg !64
221}
222
223; Function Attrs: nounwind readnone
224declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
225
226define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" {
227entry:
228  %call = call i32 @_ZN1A1B2f1Ev(), !dbg !65
229  store i32 %call, i32* @_ZN1A1B1iE, align 4, !dbg !65
230  ret void, !dbg !65
231}
232
233; Function Attrs: nounwind ssp uwtable
234define i32 @_Z4funcb(i1 zeroext %b) #0 {
235entry:
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
244
245if.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
249
250if.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
258
259return:                                           ; preds = %if.end, %if.then
260  %5 = load i32, i32* %retval, !dbg !71
261  ret i32 %5, !dbg !71
262}
263
264define internal void @__cxx_global_var_init1() section "__TEXT,__StaticInit,regular,pure_instructions" {
265entry:
266  %0 = load i32, i32* @_ZN1A1B1iE, align 4, !dbg !72
267  store i32 %0, i32* @_ZN1A1B7var_fwdE, align 4, !dbg !72
268  ret void, !dbg !72
269}
270
271; Function Attrs: nounwind ssp uwtable
272define void @_ZN1A1B8func_fwdEv() #0 {
273entry:
274  ret void, !dbg !73
275}
276
277define internal void @_GLOBAL__sub_I_debug_info_namespace.cpp() section "__TEXT,__StaticInit,regular,pure_instructions" {
278entry:
279  call void @__cxx_global_var_init(), !dbg !74
280  call void @__cxx_global_var_init1(), !dbg !74
281  ret void, !dbg !74
282}
283
284attributes #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" }
285attributes #1 = { nounwind readnone }
286
287!llvm.dbg.cu = !{!0}
288!llvm.module.flags = !{!57, !58}
289!llvm.ident = !{!59}
290
291!0 = !MDCompileUnit(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 = !MDFile(filename: "debug-info-namespace.cpp", directory: "/tmp")
293!2 = !{}
294!3 = !{!4, !8}
295!4 = !MDCompositeType(tag: DW_TAG_structure_type, name: "foo", line: 5, flags: DIFlagFwdDecl, file: !5, scope: !6, identifier: "_ZTSN1A1B3fooE")
296!5 = !MDFile(filename: "foo.cpp", directory: "/tmp")
297!6 = !MDNamespace(name: "B", line: 1, file: !5, scope: !7)
298!7 = !MDNamespace(name: "A", line: 5, file: !1, scope: null)
299!8 = !MDCompositeType(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 = !MDSubprogram(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 = !MDSubroutineType(types: !12)
303!12 = !{!13}
304!13 = !MDBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
305!14 = !MDSubprogram(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 = !MDSubroutineType(types: !16)
307!16 = !{null, !13}
308!17 = !MDSubprogram(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 = !MDFile(filename: "foo.cpp", directory: "/tmp")
310!19 = !MDSubroutineType(types: !20)
311!20 = !{null}
312!21 = !MDSubprogram(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 = !MDSubroutineType(types: !23)
314!23 = !{!13, !24}
315!24 = !MDBasicType(tag: DW_TAG_base_type, name: "bool", size: 8, align: 8, encoding: DW_ATE_boolean)
316!25 = !MDSubprogram(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 = !MDSubprogram(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 = !MDSubprogram(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 = !MDFile(filename: "debug-info-namespace.cpp", directory: "/tmp")
320!29 = !MDSubroutineType(types: !2)
321!30 = !{!31, !32}
322!31 = !MDGlobalVariable(name: "i", linkageName: "_ZN1A1B1iE", line: 20, isLocal: false, isDefinition: true, scope: !6, file: !18, type: !13, variable: i32* @_ZN1A1B1iE)
323!32 = !MDGlobalVariable(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 = !MDImportedEntity(tag: DW_TAG_imported_module, line: 15, scope: !7, entity: !6)
326!35 = !MDImportedEntity(tag: DW_TAG_imported_module, line: 18, scope: !0, entity: !7)
327!36 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 19, name: "E", scope: !0, entity: !7)
328!37 = !MDImportedEntity(tag: DW_TAG_imported_module, line: 23, scope: !38, entity: !6)
329!38 = distinct !MDLexicalBlock(line: 22, column: 10, file: !5, scope: !39)
330!39 = distinct !MDLexicalBlock(line: 22, column: 7, file: !5, scope: !21)
331!40 = !MDImportedEntity(tag: DW_TAG_imported_module, line: 26, scope: !21, entity: !7)
332!41 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 27, scope: !21, entity: !"_ZTSN1A1B3fooE")
333!42 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 28, scope: !21, entity: !"_ZTSN1A1B3barE")
334!43 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 29, scope: !21, entity: !14)
335!44 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 30, scope: !21, entity: !31)
336!45 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 31, scope: !21, entity: !46)
337!46 = !MDDerivedType(tag: DW_TAG_typedef, name: "baz", line: 7, file: !5, scope: !6, baseType: !"_ZTSN1A1B3barE")
338!47 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 32, name: "X", scope: !21, entity: !7)
339!48 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 33, name: "Y", scope: !21, entity: !47)
340!49 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 34, scope: !21, entity: !50)
341!50 = !MDGlobalVariable(name: "var_decl", linkageName: "_ZN1A1B8var_declE", line: 8, isLocal: false, isDefinition: false, scope: !6, file: !18, type: !13)
342!51 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 35, scope: !21, entity: !52)
343!52 = !MDSubprogram(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 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 36, scope: !21, entity: !32)
346!55 = !MDImportedEntity(tag: DW_TAG_imported_declaration, line: 37, scope: !21, entity: !26)
347!56 = !MDImportedEntity(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 = !MDLocation(line: 3, column: 12, scope: !10)
352!61 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "", line: 4, arg: 1, scope: !14, file: !18, type: !13)
353!62 = !MDExpression()
354!63 = !MDLocation(line: 4, column: 12, scope: !14)
355!64 = !MDLocation(line: 4, column: 16, scope: !14)
356!65 = !MDLocation(line: 20, column: 12, scope: !17)
357!66 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "b", line: 21, arg: 1, scope: !21, file: !18, type: !24)
358!67 = !MDLocation(line: 21, column: 15, scope: !21)
359!68 = !MDLocation(line: 22, column: 7, scope: !21)
360!69 = !MDLocation(line: 24, column: 5, scope: !38)
361!70 = !MDLocation(line: 38, column: 3, scope: !21)
362!71 = !MDLocation(line: 39, column: 1, scope: !21)
363!72 = !MDLocation(line: 44, column: 15, scope: !25)
364!73 = !MDLocation(line: 47, column: 21, scope: !26)
365!74 = !MDLocation(line: 0, scope: !75)
366!75 = !MDLexicalBlockFile(discriminator: 0, file: !5, scope: !27)
367