xref: /llvm-project/clang/test/CodeGenCXX/debug-info-namespace.cpp (revision bd87eb459de0b0be2785c191b69add3db65daa79)
1 // RUN: %clang_cc1 -std=c++11 -debug-info-kind=limited -S -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -std=c++11 -debug-info-kind=line-tables-only -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-GMLT %s
3 // RUN: %clang_cc1 -std=c++11 -debug-info-kind=standalone -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-NOLIMIT %s
4 
5 namespace A {
6 #line 1 "foo.cpp"
7 namespace B {
8 extern int i;
9 int f1() { return 0; }
10 void f1(int) { }
11 struct foo;
12 struct bar { };
13 typedef bar baz;
14 extern int var_decl;
15 void func_decl(void);
16 extern int var_fwd;
17 void func_fwd(void);
18 }
19 }
20 namespace A {
21 using namespace B;
22 }
23 
24 using namespace A;
25 namespace E = A;
26 int B::i = f1();
27 int func(bool b) {
28   if (b) {
29     using namespace A::B;
30     return i;
31   }
32   using namespace A;
33   using B::foo;
34   using B::bar;
35   using B::f1;
36   using B::i;
37   using B::baz;
38   namespace X = A;
39   namespace Y = X;
40   using B::var_decl;
41   using B::func_decl;
42   using B::var_fwd;
43   using B::func_fwd;
44   return i + X::B::i + Y::B::i;
45 }
46 
47 namespace A {
48 using B::i;
49 namespace B {
50 int var_fwd = i;
51 }
52 inline namespace I {
53 int var_i;
54 }
55 }
56 void B::func_fwd() {}
57 
58 // This should work even if 'i' and 'func' were declarations & not definitions,
59 // but it doesn't yet.
60 
61 // CHECK: [[I:![0-9]+]] = distinct !DIGlobalVariable(name: "i",{{.*}} scope: [[NS:![0-9]+]],
62 // CHECK: [[NS]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]], file: [[FOOCPP:![0-9]+]], line: 1)
63 // CHECK: [[FOOCPP]] = !DIFile(filename: "foo.cpp"
64 // CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null, file: [[FILE:![0-9]+]], line: 5)
65 // CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-namespace.cpp",
66 // CHECK: [[VAR_FWD:![0-9]+]] = distinct !DIGlobalVariable(name: "var_fwd",{{.*}} scope: [[NS]],
67 // CHECK-SAME:                                             line: 44
68 // CHECK-SAME:                                             isDefinition: true
69 // CHECK: distinct !DIGlobalVariable(name: "var_i",{{.*}} scope: [[INLINE:![0-9]+]],
70 // CHECK: [[INLINE]] = !DINamespace(name: "I", scope: [[CTXT]], file: [[FOOCPP]], line: 46, exportSymbols: true)
71 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
72 // CHECK-SAME:                            imports: [[MODULES:![0-9]*]]
73 // CHECK: [[MODULES]] = !{[[M1:![0-9]+]], [[M2:![0-9]+]], [[M3:![0-9]+]], [[M4:![0-9]+]], [[M5:![0-9]+]], [[M6:![0-9]+]], [[M7:![0-9]+]], [[M8:![0-9]+]], [[M9:![0-9]+]], [[M10:![0-9]+]], [[M11:![0-9]+]], [[M12:![0-9]+]], [[M13:![0-9]+]], [[M14:![0-9]+]], [[M15:![0-9]+]], [[M16:![0-9]+]], [[M17:![0-9]+]]}
74 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CTXT]], entity: [[NS]], line: 15)
75 
76 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CU]], entity: [[CTXT]],
77 // CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "E", scope: [[CU]], entity: [[CTXT]], line: 19)
78 // CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[LEX2:![0-9]+]], entity: [[NS]], line: 23)
79 // CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: [[FOOCPP]],
80 // CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC:![0-9]+]], file: [[FOOCPP]],
81 
82 // CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} isDefinition: true
83 // CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[FUNC]], entity: [[CTXT:![0-9]+]],
84 // CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FOO:![0-9]+]], line: 27)
85 // CHECK: [[FOO]] = !DICompositeType(tag: DW_TAG_structure_type, name: "foo",
86 // CHECK-SAME:                               line: 5
87 // CHECK-SAME:                               DIFlagFwdDecl
88 // CHECK: [[M7]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[BAR:![0-9]+]]
89 // CHECK: [[BAR]] = !DICompositeType(tag: DW_TAG_structure_type, name: "bar",
90 // CHECK-SAME:                               line: 6
91 // CHECK-SAME:                               DIFlagFwdDecl
92 
93 // CHECK: [[M8]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[F1:![0-9]+]]
94 // CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4
95 // CHECK-SAME:                           isDefinition: true
96 // CHECK: [[M9]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[I]]
97 // CHECK: [[M10]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[BAZ:![0-9]+]]
98 // CHECK: [[BAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "baz", scope: [[NS]], file: [[FOOCPP]],
99 // CHECK-SAME:                     baseType: [[BAR]]
100 // CHECK: [[M11]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "X", scope: [[FUNC]], entity: [[CTXT]]
101 // CHECK: [[M12]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "Y", scope: [[FUNC]], entity: [[M11]]
102 // CHECK: [[M13]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[VAR_DECL:![0-9]+]]
103 // CHECK: [[VAR_DECL]] = !DIGlobalVariable(name: "var_decl", linkageName: "{{[^"]*var_decl[^"]*}}", scope: [[NS]],{{.*}} line: 8,
104 // CHECK: [[M14]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FUNC_DECL:![0-9]+]]
105 // CHECK: [[FUNC_DECL]] = !DISubprogram(name: "func_decl",
106 // CHECK-SAME:                          scope: [[NS]], file: [[FOOCPP]], line: 9
107 // CHECK: [[M15]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[VAR_FWD:![0-9]+]]
108 // CHECK: [[M16]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FUNC_FWD:![0-9]+]]
109 // CHECK: [[FUNC_FWD]] = distinct !DISubprogram(name: "func_fwd",{{.*}} line: 50,{{.*}} isDefinition: true
110 // CHECK: [[M17]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[CTXT]], entity: [[I]]
111 
112 // CHECK-GMLT: [[CU:![0-9]+]] = distinct !DICompileUnit(
113 // CHECK-GMLT-SAME:                            emissionKind: LineTablesOnly,
114 // CHECK-GMLT-NOT:                             imports:
115 
116 // CHECK-NOLIMIT: !DICompositeType(tag: DW_TAG_structure_type, name: "bar",{{.*}} line: 6,
117 // CHECK-NOLIMIT-NOT:              DIFlagFwdDecl
118 // CHECK-NOLIMIT-SAME:             ){{$}}
119