blob: ed36d8d04402ec2862789adf4e3d9ee1b5a7388f [file] [log] [blame]
Hans Wennborg853ae942014-05-30 16:59:42 +00001// RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s -DMSABI | FileCheck --check-prefix=MSC --check-prefix=M32 %s
2// RUN: %clang_cc1 -triple x86_64-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s -DMSABI | FileCheck --check-prefix=MSC --check-prefix=M64 %s
3// RUN: %clang_cc1 -triple i686-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck --check-prefix=GNU --check-prefix=G32 %s
4// RUN: %clang_cc1 -triple x86_64-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck --check-prefix=GNU --check-prefix=G64 %s
5// RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O1 -o - %s -DMSABI | FileCheck --check-prefix=MO1 %s
6// RUN: %clang_cc1 -triple i686-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O1 -o - %s | FileCheck --check-prefix=GO1 %s
Hans Wennborgb0f2f142014-05-15 22:07:49 +00007
Nico Rieck755a36f2014-05-25 10:34:16 +00008// Helper structs to make templates more expressive.
9struct ImplicitInst_Imported {};
10struct ImplicitInst_NotImported {};
11struct ExplicitDecl_Imported {};
12struct ExplicitInst_Imported {};
13struct ExplicitSpec_Imported {};
14struct ExplicitSpec_Def_Imported {};
15struct ExplicitSpec_InlineDef_Imported {};
16struct ExplicitSpec_NotImported {};
Hans Wennborgb0f2f142014-05-15 22:07:49 +000017
Nico Rieck755a36f2014-05-25 10:34:16 +000018#define JOIN2(x, y) x##y
19#define JOIN(x, y) JOIN2(x, y)
20#define UNIQ(name) JOIN(name, __LINE__)
21#define USEVARTYPE(type, var) type UNIQ(use)() { return var; }
22#define USEVAR(var) USEVARTYPE(int, var)
23#define USE(func) void UNIQ(use)() { func(); }
Hans Wennborg853ae942014-05-30 16:59:42 +000024#define USEMEMFUNC(class, func) void (class::*UNIQ(use)())() { return &class::func; }
25#define USECLASS(class) void UNIQ(USE)() { class x; }
Hans Wennborgb0f2f142014-05-15 22:07:49 +000026
Nico Rieck755a36f2014-05-25 10:34:16 +000027//===----------------------------------------------------------------------===//
28// Globals
29//===----------------------------------------------------------------------===//
30
31// Import declaration.
32// MSC-DAG: @"\01?ExternGlobalDecl@@3HA" = external dllimport global i32
33// GNU-DAG: @ExternGlobalDecl = external dllimport global i32
34__declspec(dllimport) extern int ExternGlobalDecl;
35USEVAR(ExternGlobalDecl)
36
37// dllimport implies a declaration.
38// MSC-DAG: @"\01?GlobalDecl@@3HA" = external dllimport global i32
39// GNU-DAG: @GlobalDecl = external dllimport global i32
40__declspec(dllimport) int GlobalDecl;
41USEVAR(GlobalDecl)
42
43// Redeclarations
44// MSC-DAG: @"\01?GlobalRedecl1@@3HA" = external dllimport global i32
45// GNU-DAG: @GlobalRedecl1 = external dllimport global i32
46__declspec(dllimport) extern int GlobalRedecl1;
47__declspec(dllimport) extern int GlobalRedecl1;
48USEVAR(GlobalRedecl1)
49
50// MSC-DAG: @"\01?GlobalRedecl2a@@3HA" = external dllimport global i32
51// GNU-DAG: @GlobalRedecl2a = external dllimport global i32
52__declspec(dllimport) int GlobalRedecl2a;
53__declspec(dllimport) int GlobalRedecl2a;
54USEVAR(GlobalRedecl2a)
55
56// M32-DAG: @"\01?GlobalRedecl2b@@3PAHA" = external dllimport global i32*
57// M64-DAG: @"\01?GlobalRedecl2b@@3PEAHEA" = external dllimport global i32*
58// GNU-DAG: @GlobalRedecl2b = external dllimport global i32*
59int *__attribute__((dllimport)) GlobalRedecl2b;
60int *__attribute__((dllimport)) GlobalRedecl2b;
61USEVARTYPE(int*, GlobalRedecl2b)
62
63// MSC-DAG: @"\01?GlobalRedecl2c@@3HA" = external dllimport global i32
64// GNU-DAG: @GlobalRedecl2c = external dllimport global i32
65int GlobalRedecl2c __attribute__((dllimport));
66int GlobalRedecl2c __attribute__((dllimport));
67USEVAR(GlobalRedecl2c)
68
69// NB: MSC issues a warning and makes GlobalRedecl3 dllexport. We follow GCC
70// and drop the dllimport with a warning.
71// MSC-DAG: @"\01?GlobalRedecl3@@3HA" = external global i32
72// GNU-DAG: @GlobalRedecl3 = external global i32
73__declspec(dllimport) extern int GlobalRedecl3;
74 extern int GlobalRedecl3; // dllimport ignored
75USEVAR(GlobalRedecl3)
76
77// MSC-DAG: @"\01?ExternalGlobal@ns@@3HA" = external dllimport global i32
78// GNU-DAG: @_ZN2ns14ExternalGlobalE = external dllimport global i32
79namespace ns { __declspec(dllimport) int ExternalGlobal; }
80USEVAR(ns::ExternalGlobal)
81
82
83
84//===----------------------------------------------------------------------===//
85// Variable templates
86//===----------------------------------------------------------------------===//
87
88// Import declaration.
89// MSC-DAG: @"\01??$ExternVarTmplDecl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
90// GNU-DAG: @_Z17ExternVarTmplDeclI21ImplicitInst_ImportedE = external dllimport global i32
91template<typename T> __declspec(dllimport) extern int ExternVarTmplDecl;
92USEVAR(ExternVarTmplDecl<ImplicitInst_Imported>)
93
94// dllimport implies a declaration.
95// MSC-DAG: @"\01??$VarTmplDecl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
96// GNU-DAG: @_Z11VarTmplDeclI21ImplicitInst_ImportedE = external dllimport global i32
97template<typename T> __declspec(dllimport) int VarTmplDecl;
98USEVAR(VarTmplDecl<ImplicitInst_Imported>)
99
100// Redeclarations
101// MSC-DAG: @"\01??$VarTmplRedecl1@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
102// GNU-DAG: @_Z14VarTmplRedecl1I21ImplicitInst_ImportedE = external dllimport global i32
103template<typename T> __declspec(dllimport) extern int VarTmplRedecl1;
104template<typename T> __declspec(dllimport) extern int VarTmplRedecl1;
105USEVAR(VarTmplRedecl1<ImplicitInst_Imported>)
106
107// MSC-DAG: @"\01??$VarTmplRedecl2@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
108// GNU-DAG: @_Z14VarTmplRedecl2I21ImplicitInst_ImportedE = external dllimport global i32
109template<typename T> __declspec(dllimport) int VarTmplRedecl2;
110template<typename T> __declspec(dllimport) int VarTmplRedecl2;
111USEVAR(VarTmplRedecl2<ImplicitInst_Imported>)
112
113// MSC-DAG: @"\01??$VarTmplRedecl3@UImplicitInst_Imported@@@@3HA" = external global i32
114// GNU-DAG: @_Z14VarTmplRedecl3I21ImplicitInst_ImportedE = external global i32
115template<typename T> __declspec(dllimport) extern int VarTmplRedecl3;
116template<typename T> extern int VarTmplRedecl3; // dllimport ignored
117USEVAR(VarTmplRedecl3<ImplicitInst_Imported>)
118
119
120// MSC-DAG: @"\01??$ExternalVarTmpl@UImplicitInst_Imported@@@ns@@3HA" = external dllimport global i32
121// GNU-DAG: @_ZN2ns15ExternalVarTmplI21ImplicitInst_ImportedEE = external dllimport global i32
122namespace ns { template<typename T> __declspec(dllimport) int ExternalVarTmpl; }
123USEVAR(ns::ExternalVarTmpl<ImplicitInst_Imported>)
124
125
126template<typename T> int VarTmpl;
127template<typename T> __declspec(dllimport) int ImportedVarTmpl;
128
129// Import implicit instantiation of an imported variable template.
130// MSC-DAG: @"\01??$ImportedVarTmpl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
131// GNU-DAG: @_Z15ImportedVarTmplI21ImplicitInst_ImportedE = external dllimport global i32
132USEVAR(ImportedVarTmpl<ImplicitInst_Imported>)
133
134// Import explicit instantiation declaration of an imported variable template.
135// MSC-DAG: @"\01??$ImportedVarTmpl@UExplicitDecl_Imported@@@@3HA" = external dllimport global i32
136// GNU-DAG: @_Z15ImportedVarTmplI21ExplicitDecl_ImportedE = external dllimport global i32
137extern template int ImportedVarTmpl<ExplicitDecl_Imported>;
138USEVAR(ImportedVarTmpl<ExplicitDecl_Imported>)
139
140// An explicit instantiation definition of an imported variable template cannot
141// be imported because the template must be defined which is illegal.
142
143// Import specialization of an imported variable template.
144// MSC-DAG: @"\01??$ImportedVarTmpl@UExplicitSpec_Imported@@@@3HA" = external dllimport global i32
145// GNU-DAG: @_Z15ImportedVarTmplI21ExplicitSpec_ImportedE = external dllimport global i32
146template<> __declspec(dllimport) int ImportedVarTmpl<ExplicitSpec_Imported>;
147USEVAR(ImportedVarTmpl<ExplicitSpec_Imported>)
148
149// Not importing specialization of an imported variable template without
150// explicit dllimport.
151// MSC-DAG: @"\01??$ImportedVarTmpl@UExplicitSpec_NotImported@@@@3HA" = global i32 0, align 4
152// GNU-DAG: @_Z15ImportedVarTmplI24ExplicitSpec_NotImportedE = global i32 0, align 4
153template<> int ImportedVarTmpl<ExplicitSpec_NotImported>;
154USEVAR(ImportedVarTmpl<ExplicitSpec_NotImported>)
155
156// Import explicit instantiation declaration of a non-imported variable template.
157// MSC-DAG: @"\01??$VarTmpl@UExplicitDecl_Imported@@@@3HA" = external dllimport global i32
158// GNU-DAG: @_Z7VarTmplI21ExplicitDecl_ImportedE = external dllimport global i32
159extern template __declspec(dllimport) int VarTmpl<ExplicitDecl_Imported>;
160USEVAR(VarTmpl<ExplicitDecl_Imported>)
161
162// Import explicit instantiation definition of a non-imported variable template.
163// MSC-DAG: @"\01??$VarTmpl@UExplicitInst_Imported@@@@3HA" = external dllimport global i32
164// GNU-DAG: @_Z7VarTmplI21ExplicitInst_ImportedE = external dllimport global i32
165template __declspec(dllimport) int VarTmpl<ExplicitInst_Imported>;
166USEVAR(VarTmpl<ExplicitInst_Imported>)
167
168// Import specialization of a non-imported variable template.
169// MSC-DAG: @"\01??$VarTmpl@UExplicitSpec_Imported@@@@3HA" = external dllimport global i32
170// GNU-DAG: @_Z7VarTmplI21ExplicitSpec_ImportedE = external dllimport global i32
171template<> __declspec(dllimport) int VarTmpl<ExplicitSpec_Imported>;
172USEVAR(VarTmpl<ExplicitSpec_Imported>)
173
174
175
176//===----------------------------------------------------------------------===//
177// Functions
178//===----------------------------------------------------------------------===//
179
180// Import function declaration.
181// MSC-DAG: declare dllimport void @"\01?decl@@YAXXZ"()
182// GNU-DAG: declare dllimport void @_Z4declv()
183__declspec(dllimport) void decl();
184USE(decl)
185
186// extern "C"
187// MSC-DAG: declare dllimport void @externC()
188// GNU-DAG: declare dllimport void @externC()
189extern "C" __declspec(dllimport) void externC();
190USE(externC)
191
192// Import inline function.
193// MSC-DAG: declare dllimport void @"\01?inlineFunc@@YAXXZ"()
194// GNU-DAG: declare dllimport void @_Z10inlineFuncv()
195// MO1-DAG: define available_externally dllimport void @"\01?inlineFunc@@YAXXZ"()
196// GO1-DAG: define available_externally dllimport void @_Z10inlineFuncv()
197__declspec(dllimport) inline void inlineFunc() {}
198USE(inlineFunc)
199
200// MSC-DAG: declare dllimport void @"\01?inlineDecl@@YAXXZ"()
201// GNU-DAG: declare dllimport void @_Z10inlineDeclv()
202// MO1-DAG: define available_externally dllimport void @"\01?inlineDecl@@YAXXZ"()
203// GO1-DAG: define available_externally dllimport void @_Z10inlineDeclv()
204__declspec(dllimport) inline void inlineDecl();
205 void inlineDecl() {}
206USE(inlineDecl)
207
208// MSC-DAG: declare dllimport void @"\01?inlineDef@@YAXXZ"()
209// GNU-DAG: declare dllimport void @_Z9inlineDefv()
210// MO1-DAG: define available_externally dllimport void @"\01?inlineDef@@YAXXZ"()
211// GO1-DAG: define available_externally dllimport void @_Z9inlineDefv()
212__declspec(dllimport) void inlineDef();
213 inline void inlineDef() {}
214USE(inlineDef)
215
216// inline attributes
217// MSC-DAG: declare dllimport void @"\01?noinline@@YAXXZ"()
218// GNU-DAG: declare dllimport void @_Z8noinlinev()
219__declspec(dllimport) __attribute__((noinline)) inline void noinline() {}
220USE(noinline)
221
Nico Rieck755a36f2014-05-25 10:34:16 +0000222// Redeclarations
223// MSC-DAG: declare dllimport void @"\01?redecl1@@YAXXZ"()
224// GNU-DAG: declare dllimport void @_Z7redecl1v()
225__declspec(dllimport) void redecl1();
226__declspec(dllimport) void redecl1();
227USE(redecl1)
228
229// NB: MSC issues a warning and makes redecl2/redecl3 dllexport. We follow GCC
230// and drop the dllimport with a warning.
231// MSC-DAG: declare void @"\01?redecl2@@YAXXZ"()
232// GNU-DAG: declare void @_Z7redecl2v()
233__declspec(dllimport) void redecl2();
234 void redecl2();
235USE(redecl2)
236
237// MSC-DAG: define void @"\01?redecl3@@YAXXZ"()
238// GNU-DAG: define void @_Z7redecl3v()
239__declspec(dllimport) void redecl3();
240 void redecl3() {} // dllimport ignored
241USE(redecl3)
242
243
244// Friend functions
245// MSC-DAG: declare dllimport void @"\01?friend1@@YAXXZ"()
246// GNU-DAG: declare dllimport void @_Z7friend1v()
247// MSC-DAG: declare void @"\01?friend2@@YAXXZ"()
248// GNU-DAG: declare void @_Z7friend2v()
249// MSC-DAG: define void @"\01?friend3@@YAXXZ"()
250// GNU-DAG: define void @_Z7friend3v()
251struct FuncFriend {
252 friend __declspec(dllimport) void friend1();
253 friend __declspec(dllimport) void friend2();
254 friend __declspec(dllimport) void friend3();
Hans Wennborgb0f2f142014-05-15 22:07:49 +0000255};
Nico Rieck755a36f2014-05-25 10:34:16 +0000256__declspec(dllimport) void friend1();
257 void friend2(); // dllimport ignored
258 void friend3() {} // dllimport ignored
259USE(friend1)
260USE(friend2)
261USE(friend3)
Hans Wennborgb0f2f142014-05-15 22:07:49 +0000262
Nico Rieck755a36f2014-05-25 10:34:16 +0000263// Implicit declarations can be redeclared with dllimport.
264// MSC-DAG: declare dllimport noalias i8* @"\01??2@{{YAPAXI|YAPEAX_K}}@Z"(
265// GNU-DAG: declare dllimport noalias i8* @_Znw{{[yj]}}(
266__declspec(dllimport) void* operator new(__SIZE_TYPE__ n);
267void UNIQ(use)() { ::operator new(42); }
268
269// MSC-DAG: declare dllimport void @"\01?externalFunc@ns@@YAXXZ"()
270// GNU-DAG: declare dllimport void @_ZN2ns12externalFuncEv()
271namespace ns { __declspec(dllimport) void externalFunc(); }
272USE(ns::externalFunc)
273
274
275
276//===----------------------------------------------------------------------===//
277// Function templates
278//===----------------------------------------------------------------------===//
279
280// Import function template declaration.
281// MSC-DAG: declare dllimport void @"\01??$funcTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
282// GNU-DAG: declare dllimport void @_Z12funcTmplDeclI21ImplicitInst_ImportedEvv()
283template<typename T> __declspec(dllimport) void funcTmplDecl();
284USE(funcTmplDecl<ImplicitInst_Imported>)
285
286// Function template definitions cannot be imported.
287
288// Import inline function template.
289// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl1@UImplicitInst_Imported@@@@YAXXZ"()
290// GNU-DAG: declare dllimport void @_Z15inlineFuncTmpl1I21ImplicitInst_ImportedEvv()
291// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl1@UImplicitInst_Imported@@@@YAXXZ"()
292// GO1-DAG: define available_externally dllimport void @_Z15inlineFuncTmpl1I21ImplicitInst_ImportedEvv()
293template<typename T> __declspec(dllimport) inline void inlineFuncTmpl1() {}
294USE(inlineFuncTmpl1<ImplicitInst_Imported>)
295
296// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl2@UImplicitInst_Imported@@@@YAXXZ"()
297// GNU-DAG: declare dllimport void @_Z15inlineFuncTmpl2I21ImplicitInst_ImportedEvv()
298// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl2@UImplicitInst_Imported@@@@YAXXZ"()
299// GO1-DAG: define available_externally dllimport void @_Z15inlineFuncTmpl2I21ImplicitInst_ImportedEvv()
300template<typename T> inline void __attribute__((dllimport)) inlineFuncTmpl2() {}
301USE(inlineFuncTmpl2<ImplicitInst_Imported>)
302
303// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
304// GNU-DAG: declare dllimport void @_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv()
305// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
306// GO1-DAG: define available_externally dllimport void @_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv()
307template<typename T> __declspec(dllimport) inline void inlineFuncTmplDecl();
308template<typename T> void inlineFuncTmplDecl() {}
309USE(inlineFuncTmplDecl<ImplicitInst_Imported>)
310
311// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmplDef@UImplicitInst_Imported@@@@YAXXZ"()
312// GNU-DAG: declare dllimport void @_Z17inlineFuncTmplDefI21ImplicitInst_ImportedEvv()
313// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmplDef@UImplicitInst_Imported@@@@YAXXZ"()
314// GO1-DAG: define available_externally dllimport void @_Z17inlineFuncTmplDefI21ImplicitInst_ImportedEvv()
315template<typename T> __declspec(dllimport) void inlineFuncTmplDef();
316template<typename T> inline void inlineFuncTmplDef() {}
317USE(inlineFuncTmplDef<ImplicitInst_Imported>)
318
319
320// Redeclarations
321// MSC-DAG: declare dllimport void @"\01??$funcTmplRedecl1@UImplicitInst_Imported@@@@YAXXZ"()
322// GNU-DAG: declare dllimport void @_Z15funcTmplRedecl1I21ImplicitInst_ImportedEvv()
323template<typename T> __declspec(dllimport) void funcTmplRedecl1();
324template<typename T> __declspec(dllimport) void funcTmplRedecl1();
325USE(funcTmplRedecl1<ImplicitInst_Imported>)
326
327// MSC-DAG: declare void @"\01??$funcTmplRedecl2@UImplicitInst_NotImported@@@@YAXXZ"()
328// GNU-DAG: declare void @_Z15funcTmplRedecl2I24ImplicitInst_NotImportedEvv()
329template<typename T> __declspec(dllimport) void funcTmplRedecl2();
330template<typename T> void funcTmplRedecl2(); // dllimport ignored
331USE(funcTmplRedecl2<ImplicitInst_NotImported>)
332
333// MSC-DAG: define linkonce_odr void @"\01??$funcTmplRedecl3@UImplicitInst_NotImported@@@@YAXXZ"()
334// GNU-DAG: define linkonce_odr void @_Z15funcTmplRedecl3I24ImplicitInst_NotImportedEvv()
335template<typename T> __declspec(dllimport) void funcTmplRedecl3();
336template<typename T> void funcTmplRedecl3() {} // dllimport ignored
337USE(funcTmplRedecl3<ImplicitInst_NotImported>)
338
339
340// Function template friends
341// MSC-DAG: declare dllimport void @"\01??$funcTmplFriend1@UImplicitInst_Imported@@@@YAXXZ"()
342// GNU-DAG: declare dllimport void @_Z15funcTmplFriend1I21ImplicitInst_ImportedEvv()
343// MSC-DAG: declare void @"\01??$funcTmplFriend2@UImplicitInst_NotImported@@@@YAXXZ"()
344// GNU-DAG: declare void @_Z15funcTmplFriend2I24ImplicitInst_NotImportedEvv()
345// MSC-DAG: define linkonce_odr void @"\01??$funcTmplFriend3@UImplicitInst_NotImported@@@@YAXXZ"()
346// GNU-DAG: define linkonce_odr void @_Z15funcTmplFriend3I24ImplicitInst_NotImportedEvv()
347// MSC-DAG: declare dllimport void @"\01??$funcTmplFriend4@UImplicitInst_Imported@@@@YAXXZ"()
348// GNU-DAG: declare dllimport void @_Z15funcTmplFriend4I21ImplicitInst_ImportedEvv()
349struct FuncTmplFriend {
350 template<typename T> friend __declspec(dllimport) void funcTmplFriend1();
351 template<typename T> friend __declspec(dllimport) void funcTmplFriend2();
352 template<typename T> friend __declspec(dllimport) void funcTmplFriend3();
353 template<typename T> friend __declspec(dllimport) inline void funcTmplFriend4();
354};
355template<typename T> __declspec(dllimport) void funcTmplFriend1();
356template<typename T> void funcTmplFriend2(); // dllimport ignored
357template<typename T> void funcTmplFriend3() {} // dllimport ignored
358template<typename T> inline void funcTmplFriend4() {}
359USE(funcTmplFriend1<ImplicitInst_Imported>)
360USE(funcTmplFriend2<ImplicitInst_NotImported>)
361USE(funcTmplFriend3<ImplicitInst_NotImported>)
362USE(funcTmplFriend4<ImplicitInst_Imported>)
363
364// MSC-DAG: declare dllimport void @"\01??$externalFuncTmpl@UImplicitInst_Imported@@@ns@@YAXXZ"()
365// GNU-DAG: declare dllimport void @_ZN2ns16externalFuncTmplI21ImplicitInst_ImportedEEvv()
366namespace ns { template<typename T> __declspec(dllimport) void externalFuncTmpl(); }
367USE(ns::externalFuncTmpl<ImplicitInst_Imported>)
368
369
370template<typename T> void funcTmpl() {}
371template<typename T> inline void inlineFuncTmpl() {}
372template<typename T> __declspec(dllimport) void importedFuncTmplDecl();
373template<typename T> __declspec(dllimport) inline void importedFuncTmpl() {}
374
375// Import implicit instantiation of an imported function template.
376// MSC-DAG: declare dllimport void @"\01??$importedFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
377// GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI21ImplicitInst_ImportedEvv()
378USE(importedFuncTmplDecl<ImplicitInst_Imported>)
379
380// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UImplicitInst_Imported@@@@YAXXZ"()
381// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ImplicitInst_ImportedEvv()
382// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UImplicitInst_Imported@@@@YAXXZ"()
383// GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI21ImplicitInst_ImportedEvv()
384USE(importedFuncTmpl<ImplicitInst_Imported>)
385
386// Import explicit instantiation declaration of an imported function template.
387// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
388// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitDecl_ImportedEvv()
389// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
390// GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI21ExplicitDecl_ImportedEvv()
391extern template void importedFuncTmpl<ExplicitDecl_Imported>();
392USE(importedFuncTmpl<ExplicitDecl_Imported>)
393
394// Import explicit instantiation definition of an imported function template.
395// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
396// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitInst_ImportedEvv()
397// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
398// GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI21ExplicitInst_ImportedEvv()
399template void importedFuncTmpl<ExplicitInst_Imported>();
400USE(importedFuncTmpl<ExplicitInst_Imported>)
401
402
403// Import specialization of an imported function template.
404// MSC-DAG: declare dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_Imported@@@@YAXXZ"()
405// GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI21ExplicitSpec_ImportedEvv()
406template<> __declspec(dllimport) void importedFuncTmplDecl<ExplicitSpec_Imported>();
407USE(importedFuncTmplDecl<ExplicitSpec_Imported>)
408
409// MSC-DAG-FIXME: declare dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
410// MO1-DAG-FIXME: define available_externally dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
411#ifdef MSABI
412//template<> __declspec(dllimport) void importedFuncTmplDecl<ExplicitSpec_Def_Imported>() {}
413//USE(importedFuncTmplDecl<ExplicitSpec_Def_Imported>)
414#endif
415
416// MSC-DAG: declare dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
417// GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI31ExplicitSpec_InlineDef_ImportedEvv()
418// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
419// GO1-DAG: define available_externally dllimport void @_Z20importedFuncTmplDeclI31ExplicitSpec_InlineDef_ImportedEvv()
420template<> __declspec(dllimport) inline void importedFuncTmplDecl<ExplicitSpec_InlineDef_Imported>() {}
421USE(importedFuncTmplDecl<ExplicitSpec_InlineDef_Imported>)
422
423
424// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_Imported@@@@YAXXZ"()
425// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitSpec_ImportedEvv()
426template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Imported>();
427USE(importedFuncTmpl<ExplicitSpec_Imported>)
428
429// MSC-DAG-FIXME: declare dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
430// MO1-DAG-FIXME: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
431#ifdef MSABI
432//template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Def_Imported>() {}
433//USE(importedFuncTmpl<ExplicitSpec_Def_Imported>)
434#endif
435
436// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
437// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI31ExplicitSpec_InlineDef_ImportedEvv()
438// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
439// GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI31ExplicitSpec_InlineDef_ImportedEvv()
440template<> __declspec(dllimport) inline void importedFuncTmpl<ExplicitSpec_InlineDef_Imported>() {}
441USE(importedFuncTmpl<ExplicitSpec_InlineDef_Imported>)
442
443
444// Not importing specialization of an imported function template without
445// explicit dllimport.
446// MSC-DAG: define void @"\01??$importedFuncTmpl@UExplicitSpec_NotImported@@@@YAXXZ"()
447// GNU-DAG: define void @_Z16importedFuncTmplI24ExplicitSpec_NotImportedEvv()
448template<> void importedFuncTmpl<ExplicitSpec_NotImported>() {}
449USE(importedFuncTmpl<ExplicitSpec_NotImported>)
450
451
452// Import explicit instantiation declaration of a non-imported function template.
453// MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
454// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
455// GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitDecl_ImportedEvv()
456// GNU-DAG: declare dllimport void @_Z14inlineFuncTmplI21ExplicitDecl_ImportedEvv()
457// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
458// GO1-DAG: define available_externally dllimport void @_Z14inlineFuncTmplI21ExplicitDecl_ImportedEvv()
459extern template __declspec(dllimport) void funcTmpl<ExplicitDecl_Imported>();
460extern template __declspec(dllimport) void inlineFuncTmpl<ExplicitDecl_Imported>();
461USE(funcTmpl<ExplicitDecl_Imported>)
462USE(inlineFuncTmpl<ExplicitDecl_Imported>)
463
464
465// Import explicit instantiation definition of a non-imported function template.
466// MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"()
467// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
468// GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv()
469// GNU-DAG: declare dllimport void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv()
470// MO1-DAG: define available_externally dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"()
471// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
472// GO1-DAG: define available_externally dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv()
473// GO1-DAG: define available_externally dllimport void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv()
474template __declspec(dllimport) void funcTmpl<ExplicitInst_Imported>();
475template __declspec(dllimport) void inlineFuncTmpl<ExplicitInst_Imported>();
476USE(funcTmpl<ExplicitInst_Imported>)
477USE(inlineFuncTmpl<ExplicitInst_Imported>)
478
479
480// Import specialization of a non-imported function template.
481// MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitSpec_Imported@@@@YAXXZ"()
482// GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitSpec_ImportedEvv()
483template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Imported>();
484USE(funcTmpl<ExplicitSpec_Imported>)
485
486// MSC-DAG-FIXME: declare dllimport void @"\01??$funcTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
487// MO1-DAG-FIXME: define available_externally dllimport void @"\01??$funcTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
488#ifdef MSABI
489//template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Def_Imported>() {}
490//USE(funcTmpl<ExplicitSpec_Def_Imported>)
491#endif
492
493// MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
494// GNU-DAG: declare dllimport void @_Z8funcTmplI31ExplicitSpec_InlineDef_ImportedEvv()
495// MO1-DAG: define available_externally dllimport void @"\01??$funcTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
496// GO1-DAG: define available_externally dllimport void @_Z8funcTmplI31ExplicitSpec_InlineDef_ImportedEvv()
497template<> __declspec(dllimport) inline void funcTmpl<ExplicitSpec_InlineDef_Imported>() {}
498USE(funcTmpl<ExplicitSpec_InlineDef_Imported>)
Hans Wennborg853ae942014-05-30 16:59:42 +0000499
500
501
502//===----------------------------------------------------------------------===//
503// Classes
504//===----------------------------------------------------------------------===//
505
506struct __declspec(dllimport) T {
507 void a() {}
508 // MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01?a@T@@QAEXXZ"
509
510 static int b;
511 // MO1-DAG: @"\01?b@T@@2HA" = external dllimport global i32
512};
513USEMEMFUNC(T, a)
514USEVAR(T::b)
515
516template <typename T> struct __declspec(dllimport) U { void foo() {} };
517// MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01?foo@?$U@H@@QAEXXZ"
518struct __declspec(dllimport) V : public U<int> { };
519USEMEMFUNC(V, foo)
520
521struct __declspec(dllimport) W { virtual void foo() {} };
522USECLASS(W)
523// vftable:
524// MO1-DAG: @"\01??_7W@@6B@" = available_externally dllimport unnamed_addr constant [1 x i8*] [i8* bitcast (void (%struct.W*)* @"\01?foo@W@@UAEXXZ" to i8*)]
Hans Wennborgda24e9c2014-06-02 23:13:03 +0000525// GO1-DAG: @_ZTV1W = available_externally dllimport unnamed_addr constant [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.W*)* @_ZN1W3fooEv to i8*)]
526
527struct __declspec(dllimport) KeyFuncClass {
528 constexpr KeyFuncClass() {}
529 virtual void foo();
530};
531constexpr KeyFuncClass keyFuncClassVar;
532// G32-DAG: @_ZTV12KeyFuncClass = external dllimport unnamed_addr constant [3 x i8*]
Hans Wennborg853ae942014-05-30 16:59:42 +0000533
534struct __declspec(dllimport) X : public virtual W {};
535USECLASS(X)
536// vbtable:
537// MO1-DAG: @"\01??_8X@@7B@" = available_externally dllimport unnamed_addr constant [2 x i32] [i32 0, i32 4]
538
539struct __declspec(dllimport) Y {
540 int x;
541};
542
543struct __declspec(dllimport) Z { virtual ~Z() {} };
544USECLASS(Z)
545// User-defined dtor:
546// MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01??1Z@@UAE@XZ"
547
548namespace DontUseDtorAlias {
549 struct __declspec(dllimport) A { ~A(); };
550 struct __declspec(dllimport) B : A { ~B(); };
551 inline A::~A() { }
552 inline B::~B() { }
553 // Emit a real definition of B's constructor; don't alias it to A's.
554 // MO1-DAG: available_externally dllimport x86_thiscallcc void @"\01??1B@DontUseDtorAlias@@QAE@XZ"
555 USECLASS(B)
556}
557
558namespace Vtordisp {
559 // Don't dllimport the vtordisp.
560 // MO1-DAG: define weak x86_thiscallcc void @"\01?f@?$C@D@Vtordisp@@$4PPPPPPPM@A@AEXXZ"
561
562 class Base {
563 virtual void f() {}
564 };
565 template <typename T>
566 class __declspec(dllimport) C : virtual public Base {
567 public:
568 C() {}
569 virtual void f() {}
570 };
571 template class C<char>;
572}
Hans Wennborgda24e9c2014-06-02 23:13:03 +0000573
574//===----------------------------------------------------------------------===//
575// Negative checks
576//===----------------------------------------------------------------------===//
577
578// These checks are at the end to avoid interference with the DAG checks.
579
580// MSC-NOT: @"\01?alwaysInline@@YAXXZ"()
581// GNU-NOT: @_Z12alwaysInlinev()
582__declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline() {}
583USE(alwaysInline)