1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -g -fno-standalone-debug -S -emit-llvm %s -o - | FileCheck %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -g -gline-tables-only -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-GMLT %s
3*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -g -fstandalone-debug -S -emit-llvm %s -o - | FileCheck -check-prefix=CHECK-NOLIMIT %s
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc namespace A {
6f4a2713aSLionel Sambuc #line 1 "foo.cpp"
7f4a2713aSLionel Sambuc namespace B {
8*0a6a1f1dSLionel Sambuc extern int i;
f1()9*0a6a1f1dSLionel Sambuc int f1() { return 0; }
f1(int)10f4a2713aSLionel Sambuc void f1(int) { }
11f4a2713aSLionel Sambuc struct foo;
12f4a2713aSLionel Sambuc struct bar { };
13f4a2713aSLionel Sambuc typedef bar baz;
14*0a6a1f1dSLionel Sambuc extern int var_decl;
15*0a6a1f1dSLionel Sambuc void func_decl(void);
16*0a6a1f1dSLionel Sambuc extern int var_fwd;
17*0a6a1f1dSLionel Sambuc void func_fwd(void);
18f4a2713aSLionel Sambuc }
19f4a2713aSLionel Sambuc }
20f4a2713aSLionel Sambuc namespace A {
21f4a2713aSLionel Sambuc using namespace B;
22f4a2713aSLionel Sambuc }
23f4a2713aSLionel Sambuc
24f4a2713aSLionel Sambuc using namespace A;
25f4a2713aSLionel Sambuc namespace E = A;
26*0a6a1f1dSLionel Sambuc int B::i = f1();
func(bool b)27f4a2713aSLionel Sambuc int func(bool b) {
28f4a2713aSLionel Sambuc if (b) {
29f4a2713aSLionel Sambuc using namespace A::B;
30f4a2713aSLionel Sambuc return i;
31f4a2713aSLionel Sambuc }
32f4a2713aSLionel Sambuc using namespace A;
33f4a2713aSLionel Sambuc using B::foo;
34f4a2713aSLionel Sambuc using B::bar;
35f4a2713aSLionel Sambuc using B::f1;
36f4a2713aSLionel Sambuc using B::i;
37f4a2713aSLionel Sambuc using B::baz;
38f4a2713aSLionel Sambuc namespace X = A;
39f4a2713aSLionel Sambuc namespace Y = X;
40*0a6a1f1dSLionel Sambuc using B::var_decl;
41*0a6a1f1dSLionel Sambuc using B::func_decl;
42*0a6a1f1dSLionel Sambuc using B::var_fwd;
43*0a6a1f1dSLionel Sambuc using B::func_fwd;
44f4a2713aSLionel Sambuc return i + X::B::i + Y::B::i;
45f4a2713aSLionel Sambuc }
46f4a2713aSLionel Sambuc
47*0a6a1f1dSLionel Sambuc namespace A {
48*0a6a1f1dSLionel Sambuc using B::i;
49*0a6a1f1dSLionel Sambuc namespace B {
50*0a6a1f1dSLionel Sambuc int var_fwd = i;
51*0a6a1f1dSLionel Sambuc }
52*0a6a1f1dSLionel Sambuc }
func_fwd()53*0a6a1f1dSLionel Sambuc void B::func_fwd() {}
54*0a6a1f1dSLionel Sambuc
55f4a2713aSLionel Sambuc // This should work even if 'i' and 'func' were declarations & not definitions,
56f4a2713aSLionel Sambuc // but it doesn't yet.
57f4a2713aSLionel Sambuc
58*0a6a1f1dSLionel Sambuc // CHECK: [[CU:![0-9]*]] = !{!"0x11\00{{.*}}\001"{{.*}}, [[MODULES:![0-9]*]]} ; [ DW_TAG_compile_unit ]
59f4a2713aSLionel Sambuc // CHECK: [[FOO:![0-9]*]] {{.*}} ; [ DW_TAG_structure_type ] [foo] [line 5, size 0, align 0, offset 0] [decl] [from ]
60*0a6a1f1dSLionel Sambuc // CHECK: [[FOOCPP:![0-9]*]] = !{!"foo.cpp", {{.*}}
61*0a6a1f1dSLionel Sambuc // CHECK: [[NS:![0-9]*]] = !{!"0x39\00B\001", [[FILE2:![0-9]*]], [[CTXT:![0-9]*]]} ; [ DW_TAG_namespace ] [B] [line 1]
62*0a6a1f1dSLionel Sambuc // CHECK: [[CTXT]] = !{!"0x39\00A\005", [[FILE:![0-9]*]], null} ; [ DW_TAG_namespace ] [A] [line 5]
63*0a6a1f1dSLionel Sambuc // CHECK: [[FILE]] {{.*}}debug-info-namespace.cpp"
64f4a2713aSLionel Sambuc // CHECK: [[BAR:![0-9]*]] {{.*}} ; [ DW_TAG_structure_type ] [bar] [line 6, {{.*}}] [decl] [from ]
65f4a2713aSLionel Sambuc // CHECK: [[F1:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] [line 4] [def] [f1]
66f4a2713aSLionel Sambuc // CHECK: [[FILE2]]} ; [ DW_TAG_file_type ] [{{.*}}foo.cpp]
67*0a6a1f1dSLionel Sambuc // CHECK: [[FUNC:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] {{.*}} [def] [func]
68*0a6a1f1dSLionel Sambuc // CHECK: [[FUNC_FWD:![0-9]*]] {{.*}} [ DW_TAG_subprogram ] [line 47] [def] [func_fwd]
69*0a6a1f1dSLionel Sambuc // CHECK: [[I:![0-9]*]] = !{!"0x34\00i\00{{.*}}", [[NS]], {{.*}} ; [ DW_TAG_variable ] [i]
70*0a6a1f1dSLionel Sambuc // CHECK: [[VAR_FWD:![0-9]*]] = !{!"0x34\00var_fwd\00{{.*}}", [[NS]], {{.*}}} ; [ DW_TAG_variable ] [var_fwd] [line 44] [def]
71f4a2713aSLionel Sambuc
72*0a6a1f1dSLionel Sambuc // 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]*]]}
73*0a6a1f1dSLionel Sambuc // CHECK: [[M1]] = !{!"0x3a\0015\00", [[CTXT]], [[NS]]} ; [ DW_TAG_imported_module ]
74*0a6a1f1dSLionel Sambuc // CHECK: [[M2]] = !{!"0x3a\00{{[0-9]+}}\00", [[CU]], [[CTXT]]} ; [ DW_TAG_imported_module ]
75*0a6a1f1dSLionel Sambuc // CHECK: [[M3]] = !{!"0x8\0019\00E", [[CU]], [[CTXT]]} ; [ DW_TAG_imported_declaration ]
76*0a6a1f1dSLionel Sambuc // CHECK: [[M4]] = !{!"0x3a\0023\00", [[LEX2:![0-9]*]], [[NS]]} ; [ DW_TAG_imported_module ]
77*0a6a1f1dSLionel Sambuc // CHECK: [[LEX2]] = !{!"0xb\00{{[0-9]*}}\000\00{{.*}}", [[FILE2]], [[LEX1:![0-9]+]]} ; [ DW_TAG_lexical_block ]
78*0a6a1f1dSLionel Sambuc // CHECK: [[LEX1]] = !{!"0xb\00{{[0-9]*}}\000\00{{.*}}", [[FILE2]], [[FUNC]]} ; [ DW_TAG_lexical_block ]
79*0a6a1f1dSLionel Sambuc // CHECK: [[M5]] = !{!"0x3a\00{{[0-9]+}}\00", [[FUNC]], [[CTXT]]} ; [ DW_TAG_imported_module ]
80*0a6a1f1dSLionel Sambuc // CHECK: [[M6]] = !{!"0x8\0027\00", [[FUNC]], [[FOO:!"_ZTSN1A1B3fooE"]]} ; [ DW_TAG_imported_declaration ]
81*0a6a1f1dSLionel Sambuc // CHECK: [[M7]] = !{!"0x8\00{{[0-9]+}}\00", [[FUNC]], [[BAR:!"_ZTSN1A1B3barE"]]} ; [ DW_TAG_imported_declaration ]
82*0a6a1f1dSLionel Sambuc // CHECK: [[M8]] = !{!"0x8\00{{[0-9]+}}\00", [[FUNC]], [[F1]]} ; [ DW_TAG_imported_declaration ]
83*0a6a1f1dSLionel Sambuc // CHECK: [[M9]] = !{!"0x8\00{{[0-9]+}}\00", [[FUNC]], [[I]]} ; [ DW_TAG_imported_declaration ]
84*0a6a1f1dSLionel Sambuc // CHECK: [[M10]] = !{!"0x8\00{{[0-9]+}}\00", [[FUNC]], [[BAZ:![0-9]*]]} ; [ DW_TAG_imported_declaration ]
85*0a6a1f1dSLionel Sambuc // CHECK: [[BAZ]] = !{!"0x16\00baz\00{{.*}}", [[FOOCPP]], [[NS]], !"_ZTSN1A1B3barE"} ; [ DW_TAG_typedef ] [baz] {{.*}} [from _ZTSN1A1B3barE]
86*0a6a1f1dSLionel Sambuc // CHECK: [[M11]] = !{!"0x8\00{{[0-9]+}}\00X", [[FUNC]], [[CTXT]]} ; [ DW_TAG_imported_declaration ]
87*0a6a1f1dSLionel Sambuc // CHECK: [[M12]] = !{!"0x8\00{{[0-9]+}}\00Y", [[FUNC]], [[M11]]} ; [ DW_TAG_imported_declaration ]
88*0a6a1f1dSLionel Sambuc // CHECK: [[M13]] = !{!"0x8\00{{[0-9]+}}\00", [[FUNC]], [[VAR_DECL:![0-9]*]]} ; [ DW_TAG_imported_declaration ]
89*0a6a1f1dSLionel Sambuc // CHECK [[VAR_DECL]] = !{!"0x34\00var_decl\00{{.*}}", [[NS]], {{.*}}} ; [ DW_TAG_variable ] [var_decl] [line 8]
90*0a6a1f1dSLionel Sambuc // CHECK: [[M14]] = !{!"0x8\00{{[0-9]+}}\00", [[FUNC]], [[FUNC_DECL:![0-9]*]]} ; [ DW_TAG_imported_declaration ]
91*0a6a1f1dSLionel Sambuc // CHECK: [[FUNC_DECL]] = !{!"0x2e\00func_decl\00{{.*}}", [[FOOCPP]], [[NS]], {{.*}}} ; [ DW_TAG_subprogram ] [line 9] [scope 0] [func_decl]
92*0a6a1f1dSLionel Sambuc // CHECK: [[M15]] = !{!"0x8\00{{[0-9]+}}\00", [[FUNC]], [[VAR_FWD:![0-9]*]]} ; [ DW_TAG_imported_declaration ]
93*0a6a1f1dSLionel Sambuc // CHECK: [[M16]] = !{!"0x8\00{{[0-9]+}}\00", [[FUNC]], [[FUNC_FWD:![0-9]*]]} ; [ DW_TAG_imported_declaration ]
94*0a6a1f1dSLionel Sambuc // CHECK: [[M17]] = !{!"0x8\00{{[0-9]+}}\00", [[CTXT]], [[I]]} ; [ DW_TAG_imported_declaration ]
95*0a6a1f1dSLionel Sambuc // CHECK-GMLT: [[CU:![0-9]*]] = !{!"0x11\00{{.*}}\002"{{.*}}, [[MODULES:![0-9]*]]} ; [ DW_TAG_compile_unit ]
96*0a6a1f1dSLionel Sambuc // CHECK-GMLT: [[MODULES]] = !{}
97f4a2713aSLionel Sambuc
98f4a2713aSLionel Sambuc // CHECK-NOLIMIT: ; [ DW_TAG_structure_type ] [bar] [line 6, {{.*}}] [def] [from ]
99f4a2713aSLionel Sambuc
100f4a2713aSLionel Sambuc // REQUIRES: shell-preserves-root
101*0a6a1f1dSLionel Sambuc // REQUIRES: dw2
102