1 // RUN: rm -rf %t
2 // Test that only forward declarations are emitted for types defined in modules.
3 
4 // Modules:
5 // RUN: %clang_cc1 -x objective-c++ -std=c++11 -debug-info-kind=standalone \
6 // RUN:     -dwarf-ext-refs -fmodules                                   \
7 // RUN:     -fmodule-format=obj -fimplicit-module-maps -DMODULES \
8 // RUN:     -triple %itanium_abi_triple \
9 // RUN:     -fmodules-cache-path=%t %s -I %S/Inputs -I %t -emit-llvm -o %t-mod.ll
10 // RUN: cat %t-mod.ll |  FileCheck %s
11 
12 // PCH:
13 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodule-format=obj -emit-pch -I%S/Inputs \
14 // RUN:     -triple %itanium_abi_triple \
15 // RUN:     -o %t.pch %S/Inputs/DebugCXX.h
16 // RUN: %clang_cc1 -std=c++11 -debug-info-kind=standalone \
17 // RUN:     -dwarf-ext-refs -fmodule-format=obj \
18 // RUN:     -triple %itanium_abi_triple \
19 // RUN:     -include-pch %t.pch %s -emit-llvm -o %t-pch.ll
20 // RUN: cat %t-pch.ll |  FileCheck %s
21 // RUN: cat %t-pch.ll |  FileCheck %s --check-prefix=CHECK-PCH
22 
23 #ifdef MODULES
24 @import DebugCXX;
25 #endif
26 
27 // Set the line number so that the LIT check expected line number doesn't have to be updated after adding/removing a line in the RUN section.
28 #line 50
29 using DebugCXX::Struct;
30 
31 Struct s;
32 DebugCXX::Enum e;
33 
34 // Template instantiations.
35 DebugCXX::Template<long> implicitTemplate;
36 DebugCXX::Template<int> explicitTemplate;
37 DebugCXX::FloatInstantiation typedefTemplate;
38 DebugCXX::B anchoredTemplate;
39 
40 int Struct::static_member = -1;
41 enum {
42   e3 = -1
43 } conflicting_uid = e3;
44 auto anon_enum = DebugCXX::e2;
45 char _anchor = anon_enum + conflicting_uid;
46 
47 TypedefUnion tdu;
48 TypedefEnum tde;
49 TypedefStruct tds;
50 TypedefTemplate tdt;
51 Template1<int> explicitTemplate1;
52 
53 template <class T> class FwdDeclTemplate { T t; };
54 TypedefFwdDeclTemplate tdfdt;
55 
56 InAnonymousNamespace anon;
57 
58 // Types that are forward-declared in the module and defined here.
59 struct PureFwdDecl { int i; };
60 PureFwdDecl definedLocally;
61 
62 struct Specialized<int>::Member { int i; };
63 struct Specialized<int>::Member definedLocally2;
64 
65 template <class T> struct FwdDeclTemplateMember<T>::Member { T t; };
66 TypedefFwdDeclTemplateMember tdfdtm;
67 
68 SpecializedBase definedLocally3;
69 extern template class WithSpecializedBase<int>;
70 WithSpecializedBase<int> definedLocally4;
71 
72 void foo() {
73   anon.i = GlobalStruct.i = GlobalUnion.i = GlobalEnum;
74   A a;
75   Virtual virt;
76 }
77 
78 // CHECK: ![[CPP:.*]] = !DIFile(filename: {{.*}}ExtDebugInfo.cpp"
79 
80 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",
81 // CHECK-SAME:             scope: ![[NS:[0-9]+]],
82 // CHECK-SAME:             flags: DIFlagFwdDecl
83 // CHECK-SAME:             identifier:  "_ZTSN8DebugCXX4EnumE")
84 
85 // CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]])
86 // CHECK: ![[MOD]] = !DIModule(scope: null, name: {{.*}}DebugCXX
87 
88 // This type is not anchored in the module by an explicit template instantiation.
89 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
90 // CHECK-SAME:             name: "Template<long, DebugCXX::traits<long> >",
91 // CHECK-SAME:             scope: ![[NS]],
92 // CHECK-SAME:             elements:
93 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIlNS_6traitsIlEEEE")
94 
95 // This type is anchored in the module by an explicit template instantiation.
96 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
97 // CHECK-SAME:             name: "Template<int, DebugCXX::traits<int> >",
98 // CHECK-SAME:             scope: ![[NS]],
99 // CHECK-SAME:             flags: DIFlagFwdDecl
100 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIiNS_6traitsIiEEEE")
101 
102 // This type isn't, however, even with standalone non-module debug info this
103 // type is a forward declaration.
104 // CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<int>",
105 
106 // This one isn't.
107 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
108 // CHECK-SAME:             name: "Template<float, DebugCXX::traits<float> >",
109 // CHECK-SAME:             scope: ![[NS]],
110 // CHECK-SAME:             elements:
111 // CHECK-SAME:             templateParams:
112 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX8TemplateIfNS_6traitsIfEEEE")
113 
114 // This type is anchored in the module by an explicit template instantiation.
115 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "traits<float>",
116 // CHECK-SAME:             flags: DIFlagFwdDecl
117 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX6traitsIfEE")
118 
119 
120 // This type is anchored in the module via a function argument,
121 // but we don't know this (yet).
122 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A<void>",
123 // CHECK-SAME:             scope: ![[NS]],
124 // CHECK-SAME:             elements:
125 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX1AIJvEEE")
126 
127 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_member",
128 // CHECK-SAME:           scope: ![[STRUCT:[0-9]*]]
129 
130 // CHECK: ![[STRUCT]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Struct",
131 // CHECK-SAME:             scope: ![[NS]],
132 // CHECK-SAME:             flags: DIFlagFwdDecl
133 // CHECK-SAME:             identifier: "_ZTSN8DebugCXX6StructE")
134 
135 // CHECK: !DICompositeType(tag: DW_TAG_union_type,
136 // CHECK-SAME:             flags: DIFlagFwdDecl
137 // CHECK-SAME:             identifier: "_ZTS12TypedefUnion")
138 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
139 // CHECK-SAME:             flags: DIFlagFwdDecl,
140 // CHECK-SAME:             identifier: "_ZTS11TypedefEnum")
141 // CHECK: !DICompositeType(tag: DW_TAG_structure_type,
142 // CHECK-SAME:             flags: DIFlagFwdDecl,
143 // CHECK-SAME:             identifier: "_ZTS13TypedefStruct")
144 
145 // This one isn't.
146 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<void *>",
147 // CHECK-SAME:             elements:
148 // CHECK-SAME:             templateParams:
149 // CHECK-SAME:             identifier: "_ZTS9Template1IPvE")
150 
151 // This type is anchored in the module by an explicit template instantiation.
152 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<int>",
153 // CHECK-SAME:             flags: DIFlagFwdDecl,
154 // CHECK-SAME:             identifier: "_ZTS9Template1IiE")
155 
156 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "FwdDeclTemplate<int>",
157 // CHECK-SAME:             elements:
158 // CHECK-SAME:             templateParams:
159 // CHECK-SAME:             identifier: "_ZTS15FwdDeclTemplateIiE")
160 
161 // This type is defined locally and forward-declared in the module.
162 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PureFwdDecl",
163 // CHECK-SAME:             elements:
164 // CHECK-SAME:             identifier: "_ZTS11PureFwdDecl")
165 
166 // This type is defined locally and forward-declared in the module.
167 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
168 // CHECK-SAME:             elements:
169 // CHECK-SAME:             identifier: "_ZTSN11SpecializedIiE6MemberE")
170 
171 // This type is defined locally and forward-declared in the module.
172 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member",
173 // CHECK-SAME:             elements:
174 // CHECK-SAME:             identifier: "_ZTSN21FwdDeclTemplateMemberIiE6MemberE")
175 
176 // This type is defined locally and forward-declared in the module.
177 // CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "SpecializedBase",
178 // CHECK-SAME:           baseType: ![[SPECIALIZEDBASE:.*]])
179 // CHECK: ![[SPECIALIZEDBASE]] =
180 // CHECK-SAME: !DICompositeType(tag: DW_TAG_class_type,
181 // CHECK-SAME:                  name: "WithSpecializedBase<float>",
182 // CHECK-SAME:                  elements:
183 // CHECK-SAME:                  identifier: "_ZTS19WithSpecializedBaseIfE")
184 
185 // This type is explicitly specialized locally.
186 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "WithSpecializedBase<int>",
187 // CHECK-SAME:             elements:
188 // CHECK-SAME:             identifier: "_ZTS19WithSpecializedBaseIiE")
189 
190 // CHECK: !DIGlobalVariable(name: "anon_enum", {{.*}}, type: ![[ANON_ENUM:[0-9]+]]
191 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[NS]],
192 // CHECK-SAME:             line: 19
193 
194 // CHECK: !DIGlobalVariable(name: "GlobalUnion",
195 // CHECK-SAME:              type: ![[GLOBAL_UNION:[0-9]+]]
196 // CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
197 // CHECK-SAME:                elements: !{{[0-9]+}})
198 // CHECK: !DIGlobalVariable(name: "GlobalStruct",
199 // CHECK-SAME:              type: ![[GLOBAL_STRUCT:[0-9]+]]
200 // CHECK: ![[GLOBAL_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
201 // CHECK-SAME:                elements: !{{[0-9]+}})
202 
203 
204 // CHECK: !DIGlobalVariable(name: "anon",
205 // CHECK-SAME:              type: ![[GLOBAL_ANON:[0-9]+]]
206 // CHECK: ![[GLOBAL_ANON]] = !DICompositeType(tag: DW_TAG_structure_type,
207 // CHECK-SAME:              name: "InAnonymousNamespace", {{.*}}DIFlagFwdDecl)
208 
209 // CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !{{[0-9]+}}, entity: ![[STRUCT]], file: ![[CPP]], line: 50)
210 
211 // CHECK: !DICompileUnit(
212 // CHECK-SAME:           splitDebugFilename:
213 // CHECK-SAME:           dwoId:
214 // CHECK-PCH: !DICompileUnit({{.*}}splitDebugFilename:
215 // CHECK-PCH:                dwoId: 18446744073709551614
216 
217 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A",
218 // CHECK-SAME:             DIFlagFwdDecl
219 
220 // There is a full definition of the type available in the module.
221 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",
222 // CHECK-SAME:             DIFlagFwdDecl
223 // CHECK-SAME:             identifier: "_ZTS7Virtual")
224