blob: 3f3c34b8a25846da243a6ae6670aa5e5e3c148ec [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
Hans Wennborg910640b2014-06-04 21:09:46 +00008// CHECK-NOT doesn't play nice with CHECK-DAG, so use separate run lines.
9// RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s -DMSABI | FileCheck --check-prefix=MSC2 %s
10// RUN: %clang_cc1 -triple i686-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck --check-prefix=GNU2 %s
11
Nico Rieck755a36f2014-05-25 10:34:16 +000012// Helper structs to make templates more expressive.
13struct ImplicitInst_Imported {};
14struct ImplicitInst_NotImported {};
15struct ExplicitDecl_Imported {};
16struct ExplicitInst_Imported {};
17struct ExplicitSpec_Imported {};
18struct ExplicitSpec_Def_Imported {};
19struct ExplicitSpec_InlineDef_Imported {};
20struct ExplicitSpec_NotImported {};
Hans Wennborgb0f2f142014-05-15 22:07:49 +000021
Nico Rieck755a36f2014-05-25 10:34:16 +000022#define JOIN2(x, y) x##y
23#define JOIN(x, y) JOIN2(x, y)
24#define UNIQ(name) JOIN(name, __LINE__)
25#define USEVARTYPE(type, var) type UNIQ(use)() { return var; }
26#define USEVAR(var) USEVARTYPE(int, var)
27#define USE(func) void UNIQ(use)() { func(); }
Hans Wennborg853ae942014-05-30 16:59:42 +000028#define USEMEMFUNC(class, func) void (class::*UNIQ(use)())() { return &class::func; }
29#define USECLASS(class) void UNIQ(USE)() { class x; }
Hans Wennborge8ad3832014-06-11 22:44:39 +000030#define USECOPYASSIGN(class) class& (class::*UNIQ(use)())(class&) { return &class::operator=; }
31#define USEMOVEASSIGN(class) class& (class::*UNIQ(use)())(class&&) { return &class::operator=; }
Hans Wennborgb0f2f142014-05-15 22:07:49 +000032
Nico Rieck755a36f2014-05-25 10:34:16 +000033//===----------------------------------------------------------------------===//
34// Globals
35//===----------------------------------------------------------------------===//
36
37// Import declaration.
38// MSC-DAG: @"\01?ExternGlobalDecl@@3HA" = external dllimport global i32
39// GNU-DAG: @ExternGlobalDecl = external dllimport global i32
40__declspec(dllimport) extern int ExternGlobalDecl;
41USEVAR(ExternGlobalDecl)
42
43// dllimport implies a declaration.
44// MSC-DAG: @"\01?GlobalDecl@@3HA" = external dllimport global i32
45// GNU-DAG: @GlobalDecl = external dllimport global i32
46__declspec(dllimport) int GlobalDecl;
47USEVAR(GlobalDecl)
48
49// Redeclarations
50// MSC-DAG: @"\01?GlobalRedecl1@@3HA" = external dllimport global i32
51// GNU-DAG: @GlobalRedecl1 = external dllimport global i32
52__declspec(dllimport) extern int GlobalRedecl1;
53__declspec(dllimport) extern int GlobalRedecl1;
54USEVAR(GlobalRedecl1)
55
56// MSC-DAG: @"\01?GlobalRedecl2a@@3HA" = external dllimport global i32
57// GNU-DAG: @GlobalRedecl2a = external dllimport global i32
58__declspec(dllimport) int GlobalRedecl2a;
59__declspec(dllimport) int GlobalRedecl2a;
60USEVAR(GlobalRedecl2a)
61
62// M32-DAG: @"\01?GlobalRedecl2b@@3PAHA" = external dllimport global i32*
63// M64-DAG: @"\01?GlobalRedecl2b@@3PEAHEA" = external dllimport global i32*
64// GNU-DAG: @GlobalRedecl2b = external dllimport global i32*
65int *__attribute__((dllimport)) GlobalRedecl2b;
66int *__attribute__((dllimport)) GlobalRedecl2b;
67USEVARTYPE(int*, GlobalRedecl2b)
68
69// MSC-DAG: @"\01?GlobalRedecl2c@@3HA" = external dllimport global i32
70// GNU-DAG: @GlobalRedecl2c = external dllimport global i32
71int GlobalRedecl2c __attribute__((dllimport));
72int GlobalRedecl2c __attribute__((dllimport));
73USEVAR(GlobalRedecl2c)
74
75// NB: MSC issues a warning and makes GlobalRedecl3 dllexport. We follow GCC
76// and drop the dllimport with a warning.
77// MSC-DAG: @"\01?GlobalRedecl3@@3HA" = external global i32
78// GNU-DAG: @GlobalRedecl3 = external global i32
79__declspec(dllimport) extern int GlobalRedecl3;
80 extern int GlobalRedecl3; // dllimport ignored
81USEVAR(GlobalRedecl3)
82
83// MSC-DAG: @"\01?ExternalGlobal@ns@@3HA" = external dllimport global i32
84// GNU-DAG: @_ZN2ns14ExternalGlobalE = external dllimport global i32
85namespace ns { __declspec(dllimport) int ExternalGlobal; }
86USEVAR(ns::ExternalGlobal)
87
Hans Wennborgef2272c2014-06-18 15:55:13 +000088int f();
89// MO1-DAG: @"\01?x@?1??inlineStaticLocalsFunc@@YAHXZ@4HA" = available_externally dllimport global i32 0
90// MO1-DAG: @"\01??_B?1??inlineStaticLocalsFunc@@YAHXZ@51" = available_externally dllimport global i32 0
91inline int __declspec(dllimport) inlineStaticLocalsFunc() {
92 static int x = f();
93 return x++;
94};
95USE(inlineStaticLocalsFunc);
96
Nico Rieck755a36f2014-05-25 10:34:16 +000097
98
99//===----------------------------------------------------------------------===//
100// Variable templates
101//===----------------------------------------------------------------------===//
102
103// Import declaration.
104// MSC-DAG: @"\01??$ExternVarTmplDecl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
105// GNU-DAG: @_Z17ExternVarTmplDeclI21ImplicitInst_ImportedE = external dllimport global i32
106template<typename T> __declspec(dllimport) extern int ExternVarTmplDecl;
107USEVAR(ExternVarTmplDecl<ImplicitInst_Imported>)
108
109// dllimport implies a declaration.
110// MSC-DAG: @"\01??$VarTmplDecl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
111// GNU-DAG: @_Z11VarTmplDeclI21ImplicitInst_ImportedE = external dllimport global i32
112template<typename T> __declspec(dllimport) int VarTmplDecl;
113USEVAR(VarTmplDecl<ImplicitInst_Imported>)
114
115// Redeclarations
116// MSC-DAG: @"\01??$VarTmplRedecl1@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
117// GNU-DAG: @_Z14VarTmplRedecl1I21ImplicitInst_ImportedE = external dllimport global i32
118template<typename T> __declspec(dllimport) extern int VarTmplRedecl1;
119template<typename T> __declspec(dllimport) extern int VarTmplRedecl1;
120USEVAR(VarTmplRedecl1<ImplicitInst_Imported>)
121
122// MSC-DAG: @"\01??$VarTmplRedecl2@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
123// GNU-DAG: @_Z14VarTmplRedecl2I21ImplicitInst_ImportedE = external dllimport global i32
124template<typename T> __declspec(dllimport) int VarTmplRedecl2;
125template<typename T> __declspec(dllimport) int VarTmplRedecl2;
126USEVAR(VarTmplRedecl2<ImplicitInst_Imported>)
127
128// MSC-DAG: @"\01??$VarTmplRedecl3@UImplicitInst_Imported@@@@3HA" = external global i32
129// GNU-DAG: @_Z14VarTmplRedecl3I21ImplicitInst_ImportedE = external global i32
130template<typename T> __declspec(dllimport) extern int VarTmplRedecl3;
131template<typename T> extern int VarTmplRedecl3; // dllimport ignored
132USEVAR(VarTmplRedecl3<ImplicitInst_Imported>)
133
134
135// MSC-DAG: @"\01??$ExternalVarTmpl@UImplicitInst_Imported@@@ns@@3HA" = external dllimport global i32
136// GNU-DAG: @_ZN2ns15ExternalVarTmplI21ImplicitInst_ImportedEE = external dllimport global i32
137namespace ns { template<typename T> __declspec(dllimport) int ExternalVarTmpl; }
138USEVAR(ns::ExternalVarTmpl<ImplicitInst_Imported>)
139
140
141template<typename T> int VarTmpl;
142template<typename T> __declspec(dllimport) int ImportedVarTmpl;
143
144// Import implicit instantiation of an imported variable template.
145// MSC-DAG: @"\01??$ImportedVarTmpl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
146// GNU-DAG: @_Z15ImportedVarTmplI21ImplicitInst_ImportedE = external dllimport global i32
147USEVAR(ImportedVarTmpl<ImplicitInst_Imported>)
148
149// Import explicit instantiation declaration of an imported variable template.
150// MSC-DAG: @"\01??$ImportedVarTmpl@UExplicitDecl_Imported@@@@3HA" = external dllimport global i32
151// GNU-DAG: @_Z15ImportedVarTmplI21ExplicitDecl_ImportedE = external dllimport global i32
152extern template int ImportedVarTmpl<ExplicitDecl_Imported>;
153USEVAR(ImportedVarTmpl<ExplicitDecl_Imported>)
154
155// An explicit instantiation definition of an imported variable template cannot
156// be imported because the template must be defined which is illegal.
157
158// Import specialization of an imported variable template.
159// MSC-DAG: @"\01??$ImportedVarTmpl@UExplicitSpec_Imported@@@@3HA" = external dllimport global i32
160// GNU-DAG: @_Z15ImportedVarTmplI21ExplicitSpec_ImportedE = external dllimport global i32
161template<> __declspec(dllimport) int ImportedVarTmpl<ExplicitSpec_Imported>;
162USEVAR(ImportedVarTmpl<ExplicitSpec_Imported>)
163
164// Not importing specialization of an imported variable template without
165// explicit dllimport.
166// MSC-DAG: @"\01??$ImportedVarTmpl@UExplicitSpec_NotImported@@@@3HA" = global i32 0, align 4
167// GNU-DAG: @_Z15ImportedVarTmplI24ExplicitSpec_NotImportedE = global i32 0, align 4
168template<> int ImportedVarTmpl<ExplicitSpec_NotImported>;
169USEVAR(ImportedVarTmpl<ExplicitSpec_NotImported>)
170
171// Import explicit instantiation declaration of a non-imported variable template.
172// MSC-DAG: @"\01??$VarTmpl@UExplicitDecl_Imported@@@@3HA" = external dllimport global i32
173// GNU-DAG: @_Z7VarTmplI21ExplicitDecl_ImportedE = external dllimport global i32
174extern template __declspec(dllimport) int VarTmpl<ExplicitDecl_Imported>;
175USEVAR(VarTmpl<ExplicitDecl_Imported>)
176
177// Import explicit instantiation definition of a non-imported variable template.
178// MSC-DAG: @"\01??$VarTmpl@UExplicitInst_Imported@@@@3HA" = external dllimport global i32
179// GNU-DAG: @_Z7VarTmplI21ExplicitInst_ImportedE = external dllimport global i32
180template __declspec(dllimport) int VarTmpl<ExplicitInst_Imported>;
181USEVAR(VarTmpl<ExplicitInst_Imported>)
182
183// Import specialization of a non-imported variable template.
184// MSC-DAG: @"\01??$VarTmpl@UExplicitSpec_Imported@@@@3HA" = external dllimport global i32
185// GNU-DAG: @_Z7VarTmplI21ExplicitSpec_ImportedE = external dllimport global i32
186template<> __declspec(dllimport) int VarTmpl<ExplicitSpec_Imported>;
187USEVAR(VarTmpl<ExplicitSpec_Imported>)
188
189
190
191//===----------------------------------------------------------------------===//
192// Functions
193//===----------------------------------------------------------------------===//
194
195// Import function declaration.
196// MSC-DAG: declare dllimport void @"\01?decl@@YAXXZ"()
197// GNU-DAG: declare dllimport void @_Z4declv()
198__declspec(dllimport) void decl();
199USE(decl)
200
201// extern "C"
202// MSC-DAG: declare dllimport void @externC()
203// GNU-DAG: declare dllimport void @externC()
204extern "C" __declspec(dllimport) void externC();
205USE(externC)
206
207// Import inline function.
208// MSC-DAG: declare dllimport void @"\01?inlineFunc@@YAXXZ"()
209// GNU-DAG: declare dllimport void @_Z10inlineFuncv()
210// MO1-DAG: define available_externally dllimport void @"\01?inlineFunc@@YAXXZ"()
211// GO1-DAG: define available_externally dllimport void @_Z10inlineFuncv()
212__declspec(dllimport) inline void inlineFunc() {}
213USE(inlineFunc)
214
215// MSC-DAG: declare dllimport void @"\01?inlineDecl@@YAXXZ"()
216// GNU-DAG: declare dllimport void @_Z10inlineDeclv()
217// MO1-DAG: define available_externally dllimport void @"\01?inlineDecl@@YAXXZ"()
218// GO1-DAG: define available_externally dllimport void @_Z10inlineDeclv()
219__declspec(dllimport) inline void inlineDecl();
220 void inlineDecl() {}
221USE(inlineDecl)
222
223// MSC-DAG: declare dllimport void @"\01?inlineDef@@YAXXZ"()
224// GNU-DAG: declare dllimport void @_Z9inlineDefv()
225// MO1-DAG: define available_externally dllimport void @"\01?inlineDef@@YAXXZ"()
226// GO1-DAG: define available_externally dllimport void @_Z9inlineDefv()
227__declspec(dllimport) void inlineDef();
228 inline void inlineDef() {}
229USE(inlineDef)
230
231// inline attributes
232// MSC-DAG: declare dllimport void @"\01?noinline@@YAXXZ"()
233// GNU-DAG: declare dllimport void @_Z8noinlinev()
234__declspec(dllimport) __attribute__((noinline)) inline void noinline() {}
235USE(noinline)
236
Hans Wennborg910640b2014-06-04 21:09:46 +0000237// MSC2-NOT: @"\01?alwaysInline@@YAXXZ"()
238// GNU2-NOT: @_Z12alwaysInlinev()
239__declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline() {}
240USE(alwaysInline)
241
Nico Rieck755a36f2014-05-25 10:34:16 +0000242// Redeclarations
243// MSC-DAG: declare dllimport void @"\01?redecl1@@YAXXZ"()
244// GNU-DAG: declare dllimport void @_Z7redecl1v()
245__declspec(dllimport) void redecl1();
246__declspec(dllimport) void redecl1();
247USE(redecl1)
248
249// NB: MSC issues a warning and makes redecl2/redecl3 dllexport. We follow GCC
250// and drop the dllimport with a warning.
251// MSC-DAG: declare void @"\01?redecl2@@YAXXZ"()
252// GNU-DAG: declare void @_Z7redecl2v()
253__declspec(dllimport) void redecl2();
254 void redecl2();
255USE(redecl2)
256
257// MSC-DAG: define void @"\01?redecl3@@YAXXZ"()
258// GNU-DAG: define void @_Z7redecl3v()
259__declspec(dllimport) void redecl3();
260 void redecl3() {} // dllimport ignored
261USE(redecl3)
262
263
264// Friend functions
265// MSC-DAG: declare dllimport void @"\01?friend1@@YAXXZ"()
266// GNU-DAG: declare dllimport void @_Z7friend1v()
267// MSC-DAG: declare void @"\01?friend2@@YAXXZ"()
268// GNU-DAG: declare void @_Z7friend2v()
269// MSC-DAG: define void @"\01?friend3@@YAXXZ"()
270// GNU-DAG: define void @_Z7friend3v()
271struct FuncFriend {
272 friend __declspec(dllimport) void friend1();
273 friend __declspec(dllimport) void friend2();
274 friend __declspec(dllimport) void friend3();
Hans Wennborgb0f2f142014-05-15 22:07:49 +0000275};
Nico Rieck755a36f2014-05-25 10:34:16 +0000276__declspec(dllimport) void friend1();
277 void friend2(); // dllimport ignored
278 void friend3() {} // dllimport ignored
279USE(friend1)
280USE(friend2)
281USE(friend3)
Hans Wennborgb0f2f142014-05-15 22:07:49 +0000282
Nico Rieck755a36f2014-05-25 10:34:16 +0000283// Implicit declarations can be redeclared with dllimport.
284// MSC-DAG: declare dllimport noalias i8* @"\01??2@{{YAPAXI|YAPEAX_K}}@Z"(
285// GNU-DAG: declare dllimport noalias i8* @_Znw{{[yj]}}(
286__declspec(dllimport) void* operator new(__SIZE_TYPE__ n);
287void UNIQ(use)() { ::operator new(42); }
288
289// MSC-DAG: declare dllimport void @"\01?externalFunc@ns@@YAXXZ"()
290// GNU-DAG: declare dllimport void @_ZN2ns12externalFuncEv()
291namespace ns { __declspec(dllimport) void externalFunc(); }
292USE(ns::externalFunc)
293
294
295
296//===----------------------------------------------------------------------===//
297// Function templates
298//===----------------------------------------------------------------------===//
299
300// Import function template declaration.
301// MSC-DAG: declare dllimport void @"\01??$funcTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
302// GNU-DAG: declare dllimport void @_Z12funcTmplDeclI21ImplicitInst_ImportedEvv()
303template<typename T> __declspec(dllimport) void funcTmplDecl();
304USE(funcTmplDecl<ImplicitInst_Imported>)
305
306// Function template definitions cannot be imported.
307
308// Import inline function template.
309// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl1@UImplicitInst_Imported@@@@YAXXZ"()
310// GNU-DAG: declare dllimport void @_Z15inlineFuncTmpl1I21ImplicitInst_ImportedEvv()
311// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl1@UImplicitInst_Imported@@@@YAXXZ"()
312// GO1-DAG: define available_externally dllimport void @_Z15inlineFuncTmpl1I21ImplicitInst_ImportedEvv()
313template<typename T> __declspec(dllimport) inline void inlineFuncTmpl1() {}
314USE(inlineFuncTmpl1<ImplicitInst_Imported>)
315
316// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl2@UImplicitInst_Imported@@@@YAXXZ"()
317// GNU-DAG: declare dllimport void @_Z15inlineFuncTmpl2I21ImplicitInst_ImportedEvv()
318// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl2@UImplicitInst_Imported@@@@YAXXZ"()
319// GO1-DAG: define available_externally dllimport void @_Z15inlineFuncTmpl2I21ImplicitInst_ImportedEvv()
320template<typename T> inline void __attribute__((dllimport)) inlineFuncTmpl2() {}
321USE(inlineFuncTmpl2<ImplicitInst_Imported>)
322
323// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
324// GNU-DAG: declare dllimport void @_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv()
325// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
326// GO1-DAG: define available_externally dllimport void @_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv()
327template<typename T> __declspec(dllimport) inline void inlineFuncTmplDecl();
328template<typename T> void inlineFuncTmplDecl() {}
329USE(inlineFuncTmplDecl<ImplicitInst_Imported>)
330
331// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmplDef@UImplicitInst_Imported@@@@YAXXZ"()
332// GNU-DAG: declare dllimport void @_Z17inlineFuncTmplDefI21ImplicitInst_ImportedEvv()
333// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmplDef@UImplicitInst_Imported@@@@YAXXZ"()
334// GO1-DAG: define available_externally dllimport void @_Z17inlineFuncTmplDefI21ImplicitInst_ImportedEvv()
335template<typename T> __declspec(dllimport) void inlineFuncTmplDef();
336template<typename T> inline void inlineFuncTmplDef() {}
337USE(inlineFuncTmplDef<ImplicitInst_Imported>)
338
339
340// Redeclarations
341// MSC-DAG: declare dllimport void @"\01??$funcTmplRedecl1@UImplicitInst_Imported@@@@YAXXZ"()
342// GNU-DAG: declare dllimport void @_Z15funcTmplRedecl1I21ImplicitInst_ImportedEvv()
343template<typename T> __declspec(dllimport) void funcTmplRedecl1();
344template<typename T> __declspec(dllimport) void funcTmplRedecl1();
345USE(funcTmplRedecl1<ImplicitInst_Imported>)
346
347// MSC-DAG: declare void @"\01??$funcTmplRedecl2@UImplicitInst_NotImported@@@@YAXXZ"()
348// GNU-DAG: declare void @_Z15funcTmplRedecl2I24ImplicitInst_NotImportedEvv()
349template<typename T> __declspec(dllimport) void funcTmplRedecl2();
350template<typename T> void funcTmplRedecl2(); // dllimport ignored
351USE(funcTmplRedecl2<ImplicitInst_NotImported>)
352
353// MSC-DAG: define linkonce_odr void @"\01??$funcTmplRedecl3@UImplicitInst_NotImported@@@@YAXXZ"()
354// GNU-DAG: define linkonce_odr void @_Z15funcTmplRedecl3I24ImplicitInst_NotImportedEvv()
355template<typename T> __declspec(dllimport) void funcTmplRedecl3();
356template<typename T> void funcTmplRedecl3() {} // dllimport ignored
357USE(funcTmplRedecl3<ImplicitInst_NotImported>)
358
359
360// Function template friends
361// MSC-DAG: declare dllimport void @"\01??$funcTmplFriend1@UImplicitInst_Imported@@@@YAXXZ"()
362// GNU-DAG: declare dllimport void @_Z15funcTmplFriend1I21ImplicitInst_ImportedEvv()
363// MSC-DAG: declare void @"\01??$funcTmplFriend2@UImplicitInst_NotImported@@@@YAXXZ"()
364// GNU-DAG: declare void @_Z15funcTmplFriend2I24ImplicitInst_NotImportedEvv()
365// MSC-DAG: define linkonce_odr void @"\01??$funcTmplFriend3@UImplicitInst_NotImported@@@@YAXXZ"()
366// GNU-DAG: define linkonce_odr void @_Z15funcTmplFriend3I24ImplicitInst_NotImportedEvv()
367// MSC-DAG: declare dllimport void @"\01??$funcTmplFriend4@UImplicitInst_Imported@@@@YAXXZ"()
368// GNU-DAG: declare dllimport void @_Z15funcTmplFriend4I21ImplicitInst_ImportedEvv()
369struct FuncTmplFriend {
370 template<typename T> friend __declspec(dllimport) void funcTmplFriend1();
371 template<typename T> friend __declspec(dllimport) void funcTmplFriend2();
372 template<typename T> friend __declspec(dllimport) void funcTmplFriend3();
373 template<typename T> friend __declspec(dllimport) inline void funcTmplFriend4();
374};
375template<typename T> __declspec(dllimport) void funcTmplFriend1();
376template<typename T> void funcTmplFriend2(); // dllimport ignored
377template<typename T> void funcTmplFriend3() {} // dllimport ignored
378template<typename T> inline void funcTmplFriend4() {}
379USE(funcTmplFriend1<ImplicitInst_Imported>)
380USE(funcTmplFriend2<ImplicitInst_NotImported>)
381USE(funcTmplFriend3<ImplicitInst_NotImported>)
382USE(funcTmplFriend4<ImplicitInst_Imported>)
383
384// MSC-DAG: declare dllimport void @"\01??$externalFuncTmpl@UImplicitInst_Imported@@@ns@@YAXXZ"()
385// GNU-DAG: declare dllimport void @_ZN2ns16externalFuncTmplI21ImplicitInst_ImportedEEvv()
386namespace ns { template<typename T> __declspec(dllimport) void externalFuncTmpl(); }
387USE(ns::externalFuncTmpl<ImplicitInst_Imported>)
388
389
390template<typename T> void funcTmpl() {}
391template<typename T> inline void inlineFuncTmpl() {}
392template<typename T> __declspec(dllimport) void importedFuncTmplDecl();
393template<typename T> __declspec(dllimport) inline void importedFuncTmpl() {}
394
395// Import implicit instantiation of an imported function template.
396// MSC-DAG: declare dllimport void @"\01??$importedFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
397// GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI21ImplicitInst_ImportedEvv()
398USE(importedFuncTmplDecl<ImplicitInst_Imported>)
399
400// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UImplicitInst_Imported@@@@YAXXZ"()
401// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ImplicitInst_ImportedEvv()
402// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UImplicitInst_Imported@@@@YAXXZ"()
403// GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI21ImplicitInst_ImportedEvv()
404USE(importedFuncTmpl<ImplicitInst_Imported>)
405
406// Import explicit instantiation declaration of an imported function template.
407// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
408// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitDecl_ImportedEvv()
409// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
410// GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI21ExplicitDecl_ImportedEvv()
411extern template void importedFuncTmpl<ExplicitDecl_Imported>();
412USE(importedFuncTmpl<ExplicitDecl_Imported>)
413
414// Import explicit instantiation definition of an imported function template.
415// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
416// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitInst_ImportedEvv()
417// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
418// GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI21ExplicitInst_ImportedEvv()
419template void importedFuncTmpl<ExplicitInst_Imported>();
420USE(importedFuncTmpl<ExplicitInst_Imported>)
421
422
423// Import specialization of an imported function template.
424// MSC-DAG: declare dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_Imported@@@@YAXXZ"()
425// GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI21ExplicitSpec_ImportedEvv()
426template<> __declspec(dllimport) void importedFuncTmplDecl<ExplicitSpec_Imported>();
427USE(importedFuncTmplDecl<ExplicitSpec_Imported>)
428
429// MSC-DAG-FIXME: declare dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
430// MO1-DAG-FIXME: define available_externally dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
431#ifdef MSABI
432//template<> __declspec(dllimport) void importedFuncTmplDecl<ExplicitSpec_Def_Imported>() {}
433//USE(importedFuncTmplDecl<ExplicitSpec_Def_Imported>)
434#endif
435
436// MSC-DAG: declare dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
437// GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI31ExplicitSpec_InlineDef_ImportedEvv()
438// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
439// GO1-DAG: define available_externally dllimport void @_Z20importedFuncTmplDeclI31ExplicitSpec_InlineDef_ImportedEvv()
440template<> __declspec(dllimport) inline void importedFuncTmplDecl<ExplicitSpec_InlineDef_Imported>() {}
441USE(importedFuncTmplDecl<ExplicitSpec_InlineDef_Imported>)
442
443
444// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_Imported@@@@YAXXZ"()
445// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitSpec_ImportedEvv()
446template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Imported>();
447USE(importedFuncTmpl<ExplicitSpec_Imported>)
448
449// MSC-DAG-FIXME: declare dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
450// MO1-DAG-FIXME: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
451#ifdef MSABI
452//template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Def_Imported>() {}
453//USE(importedFuncTmpl<ExplicitSpec_Def_Imported>)
454#endif
455
456// MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
457// GNU-DAG: declare dllimport void @_Z16importedFuncTmplI31ExplicitSpec_InlineDef_ImportedEvv()
458// MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
459// GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI31ExplicitSpec_InlineDef_ImportedEvv()
460template<> __declspec(dllimport) inline void importedFuncTmpl<ExplicitSpec_InlineDef_Imported>() {}
461USE(importedFuncTmpl<ExplicitSpec_InlineDef_Imported>)
462
463
464// Not importing specialization of an imported function template without
465// explicit dllimport.
466// MSC-DAG: define void @"\01??$importedFuncTmpl@UExplicitSpec_NotImported@@@@YAXXZ"()
467// GNU-DAG: define void @_Z16importedFuncTmplI24ExplicitSpec_NotImportedEvv()
468template<> void importedFuncTmpl<ExplicitSpec_NotImported>() {}
469USE(importedFuncTmpl<ExplicitSpec_NotImported>)
470
471
472// Import explicit instantiation declaration of a non-imported function template.
473// MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
474// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
475// GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitDecl_ImportedEvv()
476// GNU-DAG: declare dllimport void @_Z14inlineFuncTmplI21ExplicitDecl_ImportedEvv()
477// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
478// GO1-DAG: define available_externally dllimport void @_Z14inlineFuncTmplI21ExplicitDecl_ImportedEvv()
479extern template __declspec(dllimport) void funcTmpl<ExplicitDecl_Imported>();
480extern template __declspec(dllimport) void inlineFuncTmpl<ExplicitDecl_Imported>();
481USE(funcTmpl<ExplicitDecl_Imported>)
482USE(inlineFuncTmpl<ExplicitDecl_Imported>)
483
484
485// Import explicit instantiation definition of a non-imported function template.
486// MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"()
487// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
488// GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv()
489// GNU-DAG: declare dllimport void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv()
490// MO1-DAG: define available_externally dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"()
491// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
492// GO1-DAG: define available_externally dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv()
493// GO1-DAG: define available_externally dllimport void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv()
494template __declspec(dllimport) void funcTmpl<ExplicitInst_Imported>();
495template __declspec(dllimport) void inlineFuncTmpl<ExplicitInst_Imported>();
496USE(funcTmpl<ExplicitInst_Imported>)
497USE(inlineFuncTmpl<ExplicitInst_Imported>)
498
499
500// Import specialization of a non-imported function template.
501// MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitSpec_Imported@@@@YAXXZ"()
502// GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitSpec_ImportedEvv()
503template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Imported>();
504USE(funcTmpl<ExplicitSpec_Imported>)
505
506// MSC-DAG-FIXME: declare dllimport void @"\01??$funcTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
507// MO1-DAG-FIXME: define available_externally dllimport void @"\01??$funcTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
508#ifdef MSABI
509//template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Def_Imported>() {}
510//USE(funcTmpl<ExplicitSpec_Def_Imported>)
511#endif
512
513// MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
514// GNU-DAG: declare dllimport void @_Z8funcTmplI31ExplicitSpec_InlineDef_ImportedEvv()
515// MO1-DAG: define available_externally dllimport void @"\01??$funcTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
516// GO1-DAG: define available_externally dllimport void @_Z8funcTmplI31ExplicitSpec_InlineDef_ImportedEvv()
517template<> __declspec(dllimport) inline void funcTmpl<ExplicitSpec_InlineDef_Imported>() {}
518USE(funcTmpl<ExplicitSpec_InlineDef_Imported>)
Hans Wennborg853ae942014-05-30 16:59:42 +0000519
520
521
522//===----------------------------------------------------------------------===//
523// Classes
524//===----------------------------------------------------------------------===//
525
526struct __declspec(dllimport) T {
527 void a() {}
528 // MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01?a@T@@QAEXXZ"
529
530 static int b;
531 // MO1-DAG: @"\01?b@T@@2HA" = external dllimport global i32
Hans Wennborge8ad3832014-06-11 22:44:39 +0000532
533 T& operator=(T&) = default;
534 // MO1-DAG: define available_externally dllimport x86_thiscallcc nonnull %struct.T* @"\01??4T@@QAEAAU0@AAU0@@Z"
535
536 T& operator=(T&&) = default;
537 // Note: Don't mark inline move operators dllimport because current MSVC versions don't export them.
538 // MO1-DAG: define linkonce_odr x86_thiscallcc nonnull %struct.T* @"\01??4T@@QAEAAU0@$$QAU0@@Z"
Hans Wennborg853ae942014-05-30 16:59:42 +0000539};
540USEMEMFUNC(T, a)
541USEVAR(T::b)
Hans Wennborge8ad3832014-06-11 22:44:39 +0000542USECOPYASSIGN(T)
543USEMOVEASSIGN(T)
Hans Wennborg853ae942014-05-30 16:59:42 +0000544
545template <typename T> struct __declspec(dllimport) U { void foo() {} };
546// MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01?foo@?$U@H@@QAEXXZ"
547struct __declspec(dllimport) V : public U<int> { };
548USEMEMFUNC(V, foo)
549
550struct __declspec(dllimport) W { virtual void foo() {} };
551USECLASS(W)
552// vftable:
553// 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 +0000554// GO1-DAG: @_ZTV1W = available_externally dllimport unnamed_addr constant [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.W*)* @_ZN1W3fooEv to i8*)]
555
556struct __declspec(dllimport) KeyFuncClass {
557 constexpr KeyFuncClass() {}
558 virtual void foo();
559};
560constexpr KeyFuncClass keyFuncClassVar;
561// G32-DAG: @_ZTV12KeyFuncClass = external dllimport unnamed_addr constant [3 x i8*]
Hans Wennborg853ae942014-05-30 16:59:42 +0000562
563struct __declspec(dllimport) X : public virtual W {};
564USECLASS(X)
565// vbtable:
566// MO1-DAG: @"\01??_8X@@7B@" = available_externally dllimport unnamed_addr constant [2 x i32] [i32 0, i32 4]
567
568struct __declspec(dllimport) Y {
569 int x;
570};
571
572struct __declspec(dllimport) Z { virtual ~Z() {} };
573USECLASS(Z)
574// User-defined dtor:
575// MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01??1Z@@UAE@XZ"
576
577namespace DontUseDtorAlias {
578 struct __declspec(dllimport) A { ~A(); };
579 struct __declspec(dllimport) B : A { ~B(); };
580 inline A::~A() { }
581 inline B::~B() { }
582 // Emit a real definition of B's constructor; don't alias it to A's.
583 // MO1-DAG: available_externally dllimport x86_thiscallcc void @"\01??1B@DontUseDtorAlias@@QAE@XZ"
584 USECLASS(B)
585}
586
587namespace Vtordisp {
588 // Don't dllimport the vtordisp.
Hans Wennborgc94391d2014-06-06 20:04:01 +0000589 // MO1-DAG: define linkonce_odr x86_thiscallcc void @"\01?f@?$C@D@Vtordisp@@$4PPPPPPPM@A@AEXXZ"
Hans Wennborg853ae942014-05-30 16:59:42 +0000590
591 class Base {
592 virtual void f() {}
593 };
594 template <typename T>
595 class __declspec(dllimport) C : virtual public Base {
596 public:
597 C() {}
598 virtual void f() {}
599 };
600 template class C<char>;
601}
Hans Wennborgda24e9c2014-06-02 23:13:03 +0000602
Hans Wennborge9af3162014-06-04 00:18:41 +0000603namespace ClassTemplateStaticDef {
Hans Wennborgcd959222014-06-09 18:30:28 +0000604 // Regular template static field:
Hans Wennborge9af3162014-06-04 00:18:41 +0000605 template <typename T> struct __declspec(dllimport) S {
606 static int x;
607 };
608 template <typename T> int S<T>::x;
Hans Wennborgcd959222014-06-09 18:30:28 +0000609 // MSC-DAG: @"\01?x@?$S@H@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0
Hans Wennborge9af3162014-06-04 00:18:41 +0000610 int f() { return S<int>::x; }
Hans Wennborgcd959222014-06-09 18:30:28 +0000611
612 // Partial class template specialization static field:
613 template <typename A> struct T;
614 template <typename A> struct __declspec(dllimport) T<A*> {
615 static int x;
616 };
617 template <typename A> int T<A*>::x;
Hans Wennborg5e645282014-06-24 23:57:13 +0000618 // GNU-DAG: @_ZN22ClassTemplateStaticDef1TIPvE1xE = available_externally dllimport global i32 0
Hans Wennborgcd959222014-06-09 18:30:28 +0000619 int g() { return T<void*>::x; }
Hans Wennborge9af3162014-06-04 00:18:41 +0000620}
621
Hans Wennborg910640b2014-06-04 21:09:46 +0000622namespace PR19933 {
623// Don't dynamically initialize dllimport vars.
624// MSC2-NOT: @llvm.global_ctors
625// GNU2-NOT: @llvm.global_ctors
Hans Wennborgda24e9c2014-06-02 23:13:03 +0000626
Hans Wennborg910640b2014-06-04 21:09:46 +0000627 struct NonPOD { NonPOD(); };
628 template <typename T> struct A { static NonPOD x; };
629 template <typename T> NonPOD A<T>::x;
630 template struct __declspec(dllimport) A<int>;
631 // MSC-DAG: @"\01?x@?$A@H@PR19933@@2UNonPOD@2@A" = available_externally dllimport global %"struct.PR19933::NonPOD" zeroinitializer
Hans Wennborgda24e9c2014-06-02 23:13:03 +0000632
Hans Wennborg910640b2014-06-04 21:09:46 +0000633 int f();
634 template <typename T> struct B { static int x; };
635 template <typename T> int B<T>::x = f();
636 template struct __declspec(dllimport) B<int>;
637 // MSC-DAG: @"\01?x@?$B@H@PR19933@@2HA" = available_externally dllimport global i32 0
638
639 constexpr int g() { return 42; }
640 template <typename T> struct C { static int x; };
641 template <typename T> int C<T>::x = g();
642 template struct __declspec(dllimport) C<int>;
643 // MSC-DAG: @"\01?x@?$C@H@PR19933@@2HA" = available_externally dllimport global i32 42
Hans Wennborg91ebe6e2014-06-10 00:55:51 +0000644
645 template <int I> struct D { static int x, y; };
646 template <int I> int D<I>::x = I + 1;
647 template <int I> int D<I>::y = I + f();
648 template struct __declspec(dllimport) D<42>;
649 // MSC-DAG: @"\01?x@?$D@$0CK@@PR19933@@2HA" = available_externally dllimport global i32 43
650 // MSC-DAG: @"\01?y@?$D@$0CK@@PR19933@@2HA" = available_externally dllimport global i32 0
Hans Wennborg910640b2014-06-04 21:09:46 +0000651}
Hans Wennborg5e645282014-06-24 23:57:13 +0000652
653// MS ignores DLL attributes on partial specializations.
654template <typename T> struct PartiallySpecializedClassTemplate {};
655template <typename T> struct __declspec(dllimport) PartiallySpecializedClassTemplate<T*> { void f() {} };
656USEMEMFUNC(PartiallySpecializedClassTemplate<void*>, f);
657// M32-DAG: define linkonce_odr x86_thiscallcc void @"\01?f@?$PartiallySpecializedClassTemplate@PAX@@QAEXXZ"
658// G32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @_ZN33PartiallySpecializedClassTemplateIPvE1fEv
659
660template <typename T> struct ExplicitlySpecializedClassTemplate {};
661template <> struct __declspec(dllimport) ExplicitlySpecializedClassTemplate<void*> { void f() {} };
662USEMEMFUNC(ExplicitlySpecializedClassTemplate<void*>, f);
663// M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"\01?f@?$ExplicitlySpecializedClassTemplate@PAX@@QAEXXZ"
664// G32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @_ZN34ExplicitlySpecializedClassTemplateIPvE1fEv