xref: /llvm-project/clang/test/CodeGenCXX/debug-info-namespace.cpp (revision 6ee72d743b64b5cdd1c447c6f1cea0fd29378410)
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 namespace {
57 int anonymous;
58 }
59 void B::func_fwd() {
60   anonymous = 0;
61 }
62 
63 
64 // This should work even if 'i' and 'func' were declarations & not definitions,
65 // but it doesn't yet.
66 
67 // CHECK: [[I:![0-9]+]] = distinct !DIGlobalVariable(name: "i",{{.*}} scope: [[NS:![0-9]+]],
68 // CHECK: [[NS]] = !DINamespace(name: "B", scope: [[CTXT:![0-9]+]])
69 // CHECK: [[CTXT]] = !DINamespace(name: "A", scope: null)
70 // CHECK: [[FOOCPP:.*]] = !DIFile(filename: "foo.cpp"
71 // CHECK: [[VAR_FWD:![0-9]+]] = distinct !DIGlobalVariable(name: "var_fwd",{{.*}} scope: [[NS]],
72 // CHECK-SAME:                                             line: 44
73 // CHECK-SAME:                                             isDefinition: true
74 // CHECK: distinct !DIGlobalVariable(name: "var_i",{{.*}} scope: [[INLINE:![0-9]+]],
75 // CHECK: [[INLINE]] = !DINamespace(name: "I", scope: [[CTXT]], exportSymbols: true)
76 // CHECK: !DINamespace(scope: null)
77 // CHECK: [[CU:![0-9]+]] = distinct !DICompileUnit(
78 // CHECK-SAME:                            imports: [[MODULES:![0-9]*]]
79 // 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]+]]}
80 // CHECK: [[M1]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CTXT]], entity: [[NS]], line: 15)
81 
82 // CHECK: [[M2]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[CU]], entity: [[CTXT]],
83 // CHECK: [[M3]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "E", scope: [[CU]], entity: [[CTXT]], line: 19)
84 // CHECK: [[M4]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[LEX2:![0-9]+]], entity: [[NS]], line: 23)
85 // CHECK: [[LEX2]] = distinct !DILexicalBlock(scope: [[LEX1:![0-9]+]], file: [[FOOCPP]],
86 // CHECK: [[LEX1]] = distinct !DILexicalBlock(scope: [[FUNC:![0-9]+]], file: [[FOOCPP]],
87 
88 // CHECK: [[FUNC:![0-9]+]] = distinct !DISubprogram(name: "func",{{.*}} isDefinition: true
89 // CHECK: [[M5]] = !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[FUNC]], entity: [[CTXT:![0-9]+]],
90 // CHECK: [[M6]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FOO:![0-9]+]], line: 27)
91 // CHECK: [[FOO]] = !DICompositeType(tag: DW_TAG_structure_type, name: "foo",
92 // CHECK-SAME:                               line: 5
93 // CHECK-SAME:                               DIFlagFwdDecl
94 // CHECK: [[M7]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[BAR:![0-9]+]]
95 // CHECK: [[BAR]] = !DICompositeType(tag: DW_TAG_structure_type, name: "bar",
96 // CHECK-SAME:                               line: 6
97 // CHECK-SAME:                               DIFlagFwdDecl
98 
99 // CHECK: [[M8]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[F1:![0-9]+]]
100 // CHECK: [[F1:![0-9]+]] = distinct !DISubprogram(name: "f1",{{.*}} line: 4
101 // CHECK-SAME:                           isDefinition: true
102 // CHECK: [[M9]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[I]]
103 // CHECK: [[M10]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[BAZ:![0-9]+]]
104 // CHECK: [[BAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "baz", scope: [[NS]], file: [[FOOCPP]],
105 // CHECK-SAME:                     baseType: [[BAR]]
106 // CHECK: [[M11]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "X", scope: [[FUNC]], entity: [[CTXT]]
107 // CHECK: [[M12]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "Y", scope: [[FUNC]], entity: [[M11]]
108 // CHECK: [[M13]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[VAR_DECL:![0-9]+]]
109 // CHECK: [[VAR_DECL]] = !DIGlobalVariable(name: "var_decl", linkageName: "{{[^"]*var_decl[^"]*}}", scope: [[NS]],{{.*}} line: 8,
110 // CHECK: [[M14]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FUNC_DECL:![0-9]+]]
111 // CHECK: [[FUNC_DECL]] = !DISubprogram(name: "func_decl",
112 // CHECK-SAME:                          scope: [[NS]], file: [[FOOCPP]], line: 9
113 // CHECK: [[M15]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[VAR_FWD:![0-9]+]]
114 // CHECK: [[M16]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[FUNC]], entity: [[FUNC_FWD:![0-9]+]]
115 // CHECK: [[FUNC_FWD]] = distinct !DISubprogram(name: "func_fwd",{{.*}} line: 53,{{.*}} isDefinition: true
116 // CHECK: [[M17]] = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: [[CTXT]], entity: [[I]]
117 
118 // CHECK-GMLT: [[CU:![0-9]+]] = distinct !DICompileUnit(
119 // CHECK-GMLT-SAME:                            emissionKind: LineTablesOnly,
120 // CHECK-GMLT-NOT:                             imports:
121 
122 // CHECK-NOLIMIT: !DICompositeType(tag: DW_TAG_structure_type, name: "bar",{{.*}} line: 6,
123 // CHECK-NOLIMIT-NOT:              DIFlagFwdDecl
124 // CHECK-NOLIMIT-SAME:             ){{$}}
125