Clang Project

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