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