blob: b7bd675602d0b5a9c48d45b290781f40afacbfbf [file] [log] [blame]
Stephen Hines0e2c34f2015-03-23 12:09:02 -07001// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++1y -O1 -mconstructor-aliases -disable-llvm-optzns -o - %s -w | FileCheck --check-prefix=MSC --check-prefix=M32 %s
2// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=MSC --check-prefix=M64 %s
3// RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G32 %s
4// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G64 %s
Stephen Hines6bcf27b2014-05-29 04:14:42 -07005
6// Helper structs to make templates more expressive.
7struct ImplicitInst_Exported {};
8struct ExplicitDecl_Exported {};
9struct ExplicitInst_Exported {};
10struct ExplicitSpec_Exported {};
11struct ExplicitSpec_Def_Exported {};
12struct ExplicitSpec_InlineDef_Exported {};
13struct ExplicitSpec_NotExported {};
14struct External { int v; };
15
16#define JOIN2(x, y) x##y
17#define JOIN(x, y) JOIN2(x, y)
18#define UNIQ(name) JOIN(name, __LINE__)
19#define USEVAR(var) int UNIQ(use)() { return var; }
20#define USE(func) void UNIQ(use)() { func(); }
Stephen Hinesc568f1e2014-07-21 00:47:37 -070021#define USEMEMFUNC(class, func) void (class::*UNIQ(use)())() { return &class::func; }
Stephen Hines6bcf27b2014-05-29 04:14:42 -070022#define INSTVAR(var) template int var;
23#define INST(func) template void func();
24
Stephen Hinesc568f1e2014-07-21 00:47:37 -070025// The vftable for struct W is comdat largest because we have RTTI.
26// M32-DAG: $"\01??_7W@@6B@" = comdat largest
27
Stephen Hines6bcf27b2014-05-29 04:14:42 -070028
29//===----------------------------------------------------------------------===//
30// Globals
31//===----------------------------------------------------------------------===//
32
33// Declarations are not exported.
34// MSC-NOT: @"\01?ExternGlobalDecl@@3HA"
35// GNU-NOT: @ExternGlobalDecl
36__declspec(dllexport) extern int ExternGlobalDecl;
37
38// dllexport implies a definition.
39// MSC-DAG: @"\01?GlobalDef@@3HA" = dllexport global i32 0, align 4
40// GNU-DAG: @GlobalDef = dllexport global i32 0, align 4
41__declspec(dllexport) int GlobalDef;
42
43// Export definition.
44// MSC-DAG: @"\01?GlobalInit1@@3HA" = dllexport global i32 1, align 4
45// GNU-DAG: @GlobalInit1 = dllexport global i32 1, align 4
46__declspec(dllexport) int GlobalInit1 = 1;
47
48// MSC-DAG: @"\01?GlobalInit2@@3HA" = dllexport global i32 1, align 4
49// GNU-DAG: @GlobalInit2 = dllexport global i32 1, align 4
50int __declspec(dllexport) GlobalInit2 = 1;
51
52// Declare, then export definition.
53// MSC-DAG: @"\01?GlobalDeclInit@@3HA" = dllexport global i32 1, align 4
54// GNU-DAG: @GlobalDeclInit = dllexport global i32 1, align 4
55__declspec(dllexport) extern int GlobalDeclInit;
56int GlobalDeclInit = 1;
57
58// Redeclarations
59// MSC-DAG: @"\01?GlobalRedecl1@@3HA" = dllexport global i32 0, align 4
60// GNU-DAG: @GlobalRedecl1 = dllexport global i32 0, align 4
61__declspec(dllexport) extern int GlobalRedecl1;
62__declspec(dllexport) int GlobalRedecl1;
63
64// MSC-DAG: @"\01?GlobalRedecl2@@3HA" = dllexport global i32 0, align 4
65// GNU-DAG: @GlobalRedecl2 = dllexport global i32 0, align 4
66__declspec(dllexport) extern int GlobalRedecl2;
67 int GlobalRedecl2;
68
69// MSC-DAG: @"\01?ExternalGlobal@ns@@3HA" = dllexport global i32 0, align 4
70// GNU-DAG: @_ZN2ns14ExternalGlobalE = dllexport global i32 0, align 4
71namespace ns { __declspec(dllexport) int ExternalGlobal; }
72
73// MSC-DAG: @"\01?ExternalAutoTypeGlobal@@3UExternal@@A" = dllexport global %struct.External zeroinitializer, align 4
74// GNU-DAG: @ExternalAutoTypeGlobal = dllexport global %struct.External zeroinitializer, align 4
75__declspec(dllexport) auto ExternalAutoTypeGlobal = External();
76
Stephen Hinesc568f1e2014-07-21 00:47:37 -070077int f();
Stephen Hines176edba2014-12-01 14:53:08 -080078// MSC-DAG: @"\01?x@?1??nonInlineStaticLocalsFunc@@YAHXZ@4HA" = internal {{(unnamed_addr )*}}global i32 0
79// MSC-DAG: @"\01?$S1@?1??nonInlineStaticLocalsFunc@@YAHXZ@4IA" = internal {{(unnamed_addr )*}}global i32 0
Stephen Hinesc568f1e2014-07-21 00:47:37 -070080int __declspec(dllexport) nonInlineStaticLocalsFunc() {
81 static int x = f();
82 return x++;
83};
84
Stephen Hines0e2c34f2015-03-23 12:09:02 -070085// MSC-DAG: @"\01?x@?1??inlineStaticLocalsFunc@@YAHXZ@4HA" = weak_odr dllexport global i32 0, comdat
86// MSC-DAG: @"\01??_B?1??inlineStaticLocalsFunc@@YAHXZ@51" = weak_odr dllexport global i32 0, comdat
Stephen Hinesc568f1e2014-07-21 00:47:37 -070087// Note: MinGW doesn't seem to export the static local here.
88inline int __declspec(dllexport) inlineStaticLocalsFunc() {
89 static int x = f();
90 return x++;
91}
92
Stephen Hines6bcf27b2014-05-29 04:14:42 -070093
94
95//===----------------------------------------------------------------------===//
96// Variable templates
97//===----------------------------------------------------------------------===//
98
99// Declarations are not exported.
100
101// dllexport implies a definition.
102// MSC-NOT: @"\01??$VarTmplDef@UExplicitInst_Exported@@@@3HA"
103// GNU-NOT: @_Z10VarTmplDefI21ExplicitInst_ExportedE
104template<typename T> __declspec(dllexport) int VarTmplDef;
105INSTVAR(VarTmplDef<ExplicitInst_Exported>)
106
107// MSC-DAG: @"\01??$VarTmplImplicitDef@UImplicitInst_Exported@@@@3HA" = external dllexport global
108// GNU-DAG: @_Z18VarTmplImplicitDefI21ImplicitInst_ExportedE = external dllexport global
109template<typename T> __declspec(dllexport) int VarTmplImplicitDef;
110USEVAR(VarTmplImplicitDef<ImplicitInst_Exported>)
111
112// Export definition.
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700113// MSC-DAG: @"\01??$VarTmplInit1@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
114// GNU-DAG: @_Z12VarTmplInit1I21ExplicitInst_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700115template<typename T> __declspec(dllexport) int VarTmplInit1 = 1;
116INSTVAR(VarTmplInit1<ExplicitInst_Exported>)
117
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700118// MSC-DAG: @"\01??$VarTmplInit2@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
119// GNU-DAG: @_Z12VarTmplInit2I21ExplicitInst_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700120template<typename T> int __declspec(dllexport) VarTmplInit2 = 1;
121INSTVAR(VarTmplInit2<ExplicitInst_Exported>)
122
123// Declare, then export definition.
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700124// MSC-DAG: @"\01??$VarTmplDeclInit@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
125// GNU-DAG: @_Z15VarTmplDeclInitI21ExplicitInst_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700126template<typename T> __declspec(dllexport) extern int VarTmplDeclInit;
127template<typename T> int VarTmplDeclInit = 1;
128INSTVAR(VarTmplDeclInit<ExplicitInst_Exported>)
129
130// Redeclarations
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700131// MSC-DAG: @"\01??$VarTmplRedecl1@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
132// GNU-DAG: @_Z14VarTmplRedecl1I21ExplicitInst_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700133template<typename T> __declspec(dllexport) extern int VarTmplRedecl1;
134template<typename T> __declspec(dllexport) int VarTmplRedecl1 = 1;
135INSTVAR(VarTmplRedecl1<ExplicitInst_Exported>)
136
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700137// MSC-DAG: @"\01??$VarTmplRedecl2@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
138// GNU-DAG: @_Z14VarTmplRedecl2I21ExplicitInst_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700139template<typename T> __declspec(dllexport) extern int VarTmplRedecl2;
140template<typename T> int VarTmplRedecl2 = 1;
141INSTVAR(VarTmplRedecl2<ExplicitInst_Exported>)
142
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700143// MSC-DAG: @"\01??$ExternalVarTmpl@UExplicitInst_Exported@@@ns@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
144// GNU-DAG: @_ZN2ns15ExternalVarTmplI21ExplicitInst_ExportedEE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700145namespace ns { template<typename T> __declspec(dllexport) int ExternalVarTmpl = 1; }
146INSTVAR(ns::ExternalVarTmpl<ExplicitInst_Exported>)
147
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700148// MSC-DAG: @"\01??$ExternalAutoTypeVarTmpl@UExplicitInst_Exported@@@@3UExternal@@A" = weak_odr dllexport global %struct.External zeroinitializer, comdat, align 4
149// GNU-DAG: @_Z23ExternalAutoTypeVarTmplI21ExplicitInst_ExportedE = weak_odr dllexport global %struct.External zeroinitializer, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700150template<typename T> __declspec(dllexport) auto ExternalAutoTypeVarTmpl = External();
151template External ExternalAutoTypeVarTmpl<ExplicitInst_Exported>;
152
153
154template<typename T> int VarTmpl = 1;
155template<typename T> __declspec(dllexport) int ExportedVarTmpl = 1;
156
157// Export implicit instantiation of an exported variable template.
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700158// MSC-DAG: @"\01??$ExportedVarTmpl@UImplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
159// GNU-DAG: @_Z15ExportedVarTmplI21ImplicitInst_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700160USEVAR(ExportedVarTmpl<ImplicitInst_Exported>)
161
162// Export explicit instantiation declaration of an exported variable template.
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700163// MSC-DAG: @"\01??$ExportedVarTmpl@UImplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
164// GNU-DAG: @_Z15ExportedVarTmplI21ExplicitDecl_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700165extern template int ExportedVarTmpl<ExplicitDecl_Exported>;
166 template int ExportedVarTmpl<ExplicitDecl_Exported>;
167
168// Export explicit instantiation definition of an exported variable template.
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700169// MSC-DAG: @"\01??$ExportedVarTmpl@UImplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
170// GNU-DAG: @_Z15ExportedVarTmplI21ExplicitInst_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700171template __declspec(dllexport) int ExportedVarTmpl<ExplicitInst_Exported>;
172
173// Export specialization of an exported variable template.
174// MSC-DAG: @"\01??$ExportedVarTmpl@UExplicitSpec_Exported@@@@3HA" = dllexport global i32 0, align 4
175// GNU-DAG: @_Z15ExportedVarTmplI21ExplicitSpec_ExportedE = dllexport global i32 0, align 4
176template<> __declspec(dllexport) int ExportedVarTmpl<ExplicitSpec_Exported>;
177
178// MSC-DAG: @"\01??$ExportedVarTmpl@UExplicitSpec_Def_Exported@@@@3HA" = dllexport global i32 1, align 4
179// GNU-DAG: @_Z15ExportedVarTmplI25ExplicitSpec_Def_ExportedE = dllexport global i32 1, align 4
180template<> __declspec(dllexport) int ExportedVarTmpl<ExplicitSpec_Def_Exported> = 1;
181
182// Not exporting specialization of an exported variable template without
183// explicit dllexport.
184// MSC-DAG: @"\01??$ExportedVarTmpl@UExplicitSpec_NotExported@@@@3HA" = global i32 0, align 4
185// GNU-DAG: @_Z15ExportedVarTmplI24ExplicitSpec_NotExportedE = global i32 0, align 4
186template<> int ExportedVarTmpl<ExplicitSpec_NotExported>;
187
188
189// Export explicit instantiation declaration of a non-exported variable template.
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700190// MSC-DAG: @"\01??$VarTmpl@UExplicitDecl_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
191// GNU-DAG: @_Z7VarTmplI21ExplicitDecl_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700192extern template __declspec(dllexport) int VarTmpl<ExplicitDecl_Exported>;
193 template __declspec(dllexport) int VarTmpl<ExplicitDecl_Exported>;
194
195// Export explicit instantiation definition of a non-exported variable template.
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700196// MSC-DAG: @"\01??$VarTmpl@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
197// GNU-DAG: @_Z7VarTmplI21ExplicitInst_ExportedE = weak_odr dllexport global i32 1, comdat, align 4
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700198template __declspec(dllexport) int VarTmpl<ExplicitInst_Exported>;
199
200// Export specialization of a non-exported variable template.
201// MSC-DAG: @"\01??$VarTmpl@UExplicitSpec_Exported@@@@3HA" = dllexport global i32 0, align 4
202// GNU-DAG: @_Z7VarTmplI21ExplicitSpec_ExportedE = dllexport global i32 0, align 4
203template<> __declspec(dllexport) int VarTmpl<ExplicitSpec_Exported>;
204
205// MSC-DAG: @"\01??$VarTmpl@UExplicitSpec_Def_Exported@@@@3HA" = dllexport global i32 1, align 4
206// GNU-DAG: @_Z7VarTmplI25ExplicitSpec_Def_ExportedE = dllexport global i32 1, align 4
207template<> __declspec(dllexport) int VarTmpl<ExplicitSpec_Def_Exported> = 1;
208
209
210
211//===----------------------------------------------------------------------===//
212// Functions
213//===----------------------------------------------------------------------===//
214
215// Declarations are not exported.
216
217// Export function definition.
218// MSC-DAG: define dllexport void @"\01?def@@YAXXZ"()
219// GNU-DAG: define dllexport void @_Z3defv()
220__declspec(dllexport) void def() {}
221
222// extern "C"
223// MSC-DAG: define dllexport void @externC()
224// GNU-DAG: define dllexport void @externC()
225extern "C" __declspec(dllexport) void externC() {}
226
227// Export inline function.
228// MSC-DAG: define weak_odr dllexport void @"\01?inlineFunc@@YAXXZ"()
229// GNU-DAG: define weak_odr dllexport void @_Z10inlineFuncv()
230__declspec(dllexport) inline void inlineFunc() {}
231
232// MSC-DAG: define weak_odr dllexport void @"\01?inlineDecl@@YAXXZ"()
233// GNU-DAG: define weak_odr dllexport void @_Z10inlineDeclv()
234__declspec(dllexport) inline void inlineDecl();
235 void inlineDecl() {}
236
237// MSC-DAG: define weak_odr dllexport void @"\01?inlineDef@@YAXXZ"()
238// GNU-DAG: define weak_odr dllexport void @_Z9inlineDefv()
239__declspec(dllexport) void inlineDef();
240 inline void inlineDef() {}
241
242// Redeclarations
243// MSC-DAG: define dllexport void @"\01?redecl1@@YAXXZ"()
244// GNU-DAG: define dllexport void @_Z7redecl1v()
245__declspec(dllexport) void redecl1();
246__declspec(dllexport) void redecl1() {}
247
248// MSC-DAG: define dllexport void @"\01?redecl2@@YAXXZ"()
249// GNU-DAG: define dllexport void @_Z7redecl2v()
250__declspec(dllexport) void redecl2();
251 void redecl2() {}
252
253// Friend functions
254// MSC-DAG: define dllexport void @"\01?friend1@@YAXXZ"()
255// GNU-DAG: define dllexport void @_Z7friend1v()
256// MSC-DAG: define dllexport void @"\01?friend2@@YAXXZ"()
257// GNU-DAG: define dllexport void @_Z7friend2v()
258struct FuncFriend {
259 friend __declspec(dllexport) void friend1();
260 friend __declspec(dllexport) void friend2();
261};
262__declspec(dllexport) void friend1() {}
263 void friend2() {}
264
265// Implicit declarations can be redeclared with dllexport.
266// MSC-DAG: define dllexport noalias i8* @"\01??2@{{YAPAXI|YAPEAX_K}}@Z"(
267// GNU-DAG: define dllexport noalias i8* @_Znw{{[yj]}}(
268void* alloc(__SIZE_TYPE__ n);
269__declspec(dllexport) void* operator new(__SIZE_TYPE__ n) { return alloc(n); }
270
271// MSC-DAG: define dllexport void @"\01?externalFunc@ns@@YAXXZ"()
272// GNU-DAG: define dllexport void @_ZN2ns12externalFuncEv()
273namespace ns { __declspec(dllexport) void externalFunc() {} }
274
275
276
277//===----------------------------------------------------------------------===//
278// Function templates
279//===----------------------------------------------------------------------===//
280
281// Export function template definition.
282// MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplDef@UExplicitInst_Exported@@@@YAXXZ"()
283// GNU-DAG: define weak_odr dllexport void @_Z11funcTmplDefI21ExplicitInst_ExportedEvv()
284template<typename T> __declspec(dllexport) void funcTmplDef() {}
285INST(funcTmplDef<ExplicitInst_Exported>)
286
287// Export inline function template.
288// MSC-DAG: define weak_odr dllexport void @"\01??$inlineFuncTmpl1@UExplicitInst_Exported@@@@YAXXZ"()
289// GNU-DAG: define weak_odr dllexport void @_Z15inlineFuncTmpl1I21ExplicitInst_ExportedEvv()
290template<typename T> __declspec(dllexport) inline void inlineFuncTmpl1() {}
291INST(inlineFuncTmpl1<ExplicitInst_Exported>)
292
293// MSC-DAG: define weak_odr dllexport void @"\01??$inlineFuncTmpl2@UExplicitInst_Exported@@@@YAXXZ"()
294// GNU-DAG: define weak_odr dllexport void @_Z15inlineFuncTmpl2I21ExplicitInst_ExportedEvv()
295template<typename T> inline void __attribute__((dllexport)) inlineFuncTmpl2() {}
296INST(inlineFuncTmpl2<ExplicitInst_Exported>)
297
298// MSC-DAG: define weak_odr dllexport void @"\01??$inlineFuncTmplDecl@UExplicitInst_Exported@@@@YAXXZ"()
299// GNU-DAG: define weak_odr dllexport void @_Z18inlineFuncTmplDeclI21ExplicitInst_ExportedEvv()
300template<typename T> __declspec(dllexport) inline void inlineFuncTmplDecl();
301template<typename T> void inlineFuncTmplDecl() {}
302INST(inlineFuncTmplDecl<ExplicitInst_Exported>)
303
304// MSC-DAG: define weak_odr dllexport void @"\01??$inlineFuncTmplDef@UExplicitInst_Exported@@@@YAXXZ"()
305// GNU-DAG: define weak_odr dllexport void @_Z17inlineFuncTmplDefI21ExplicitInst_ExportedEvv()
306template<typename T> __declspec(dllexport) void inlineFuncTmplDef();
307template<typename T> inline void inlineFuncTmplDef() {}
308INST(inlineFuncTmplDef<ExplicitInst_Exported>)
309
310
311// Redeclarations
312// MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplRedecl1@UExplicitInst_Exported@@@@YAXXZ"()
313// GNU-DAG: define weak_odr dllexport void @_Z15funcTmplRedecl1I21ExplicitInst_ExportedEvv()
314template<typename T> __declspec(dllexport) void funcTmplRedecl1();
315template<typename T> __declspec(dllexport) void funcTmplRedecl1() {}
316INST(funcTmplRedecl1<ExplicitInst_Exported>)
317
318// MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplRedecl2@UExplicitInst_Exported@@@@YAXXZ"()
319// GNU-DAG: define weak_odr dllexport void @_Z15funcTmplRedecl2I21ExplicitInst_ExportedEvv()
320template<typename T> __declspec(dllexport) void funcTmplRedecl2();
321template<typename T> void funcTmplRedecl2() {}
322INST(funcTmplRedecl2<ExplicitInst_Exported>)
323
324// MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplRedecl3@UExplicitInst_Exported@@@@YAXXZ"()
325// GNU-DAG: define weak_odr dllexport void @_Z15funcTmplRedecl3I21ExplicitInst_ExportedEvv()
326template<typename T> __declspec(dllexport) void funcTmplRedecl3();
327template<typename T> void funcTmplRedecl3() {}
328INST(funcTmplRedecl3<ExplicitInst_Exported>)
329
330
331// Function template friends
332// MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplFriend1@UExplicitInst_Exported@@@@YAXXZ"()
333// GNU-DAG: define weak_odr dllexport void @_Z15funcTmplFriend1I21ExplicitInst_ExportedEvv()
334// MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplFriend2@UExplicitInst_Exported@@@@YAXXZ"()
335// GNU-DAG: define weak_odr dllexport void @_Z15funcTmplFriend2I21ExplicitInst_ExportedEvv()
336struct FuncTmplFriend {
337 template<typename T> friend __declspec(dllexport) void funcTmplFriend1();
338 template<typename T> friend __declspec(dllexport) void funcTmplFriend2();
339};
340template<typename T> __declspec(dllexport) void funcTmplFriend1() {}
341template<typename T> void funcTmplFriend2() {}
342INST(funcTmplFriend1<ExplicitInst_Exported>)
343INST(funcTmplFriend2<ExplicitInst_Exported>)
344
345// MSC-DAG: define weak_odr dllexport void @"\01??$externalFuncTmpl@UExplicitInst_Exported@@@ns@@YAXXZ"()
346// GNU-DAG: define weak_odr dllexport void @_ZN2ns16externalFuncTmplI21ExplicitInst_ExportedEEvv()
347namespace ns { template<typename T> __declspec(dllexport) void externalFuncTmpl() {} }
348INST(ns::externalFuncTmpl<ExplicitInst_Exported>)
349
350
351template<typename T> void funcTmpl() {}
352template<typename T> __declspec(dllexport) void exportedFuncTmpl() {}
353
354// Export implicit instantiation of an exported function template.
355// MSC-DAG: define weak_odr dllexport void @"\01??$exportedFuncTmpl@UImplicitInst_Exported@@@@YAXXZ"()
356// GNU-DAG: define weak_odr dllexport void @_Z16exportedFuncTmplI21ImplicitInst_ExportedEvv()
357USE(exportedFuncTmpl<ImplicitInst_Exported>)
358
359// Export explicit instantiation declaration of an exported function template.
360// MSC-DAG: define weak_odr dllexport void @"\01??$exportedFuncTmpl@UExplicitDecl_Exported@@@@YAXXZ"()
361// GNU-DAG: define weak_odr dllexport void @_Z16exportedFuncTmplI21ExplicitDecl_ExportedEvv()
362extern template void exportedFuncTmpl<ExplicitDecl_Exported>();
363 template void exportedFuncTmpl<ExplicitDecl_Exported>();
364
365// Export explicit instantiation definition of an exported function template.
366// MSC-DAG: define weak_odr dllexport void @"\01??$exportedFuncTmpl@UExplicitInst_Exported@@@@YAXXZ"()
367// GNU-DAG: define weak_odr dllexport void @_Z16exportedFuncTmplI21ExplicitInst_ExportedEvv()
368template void exportedFuncTmpl<ExplicitInst_Exported>();
369
370// Export specialization of an exported function template.
371// MSC-DAG: define dllexport void @"\01??$exportedFuncTmpl@UExplicitSpec_Def_Exported@@@@YAXXZ"()
372// GNU-DAG: define dllexport void @_Z16exportedFuncTmplI25ExplicitSpec_Def_ExportedEvv()
373template<> __declspec(dllexport) void exportedFuncTmpl<ExplicitSpec_Def_Exported>() {}
374
375// MSC-DAG: define weak_odr dllexport void @"\01??$exportedFuncTmpl@UExplicitSpec_InlineDef_Exported@@@@YAXXZ"()
376// GNU-DAG: define weak_odr dllexport void @_Z16exportedFuncTmplI31ExplicitSpec_InlineDef_ExportedEvv()
377template<> __declspec(dllexport) inline void exportedFuncTmpl<ExplicitSpec_InlineDef_Exported>() {}
378
379// Not exporting specialization of an exported function template without
380// explicit dllexport.
381// MSC-DAG: define void @"\01??$exportedFuncTmpl@UExplicitSpec_NotExported@@@@YAXXZ"()
382// GNU-DAG: define void @_Z16exportedFuncTmplI24ExplicitSpec_NotExportedEvv()
383template<> void exportedFuncTmpl<ExplicitSpec_NotExported>() {}
384
385
386// Export explicit instantiation declaration of a non-exported function template.
387// MSC-DAG: define weak_odr dllexport void @"\01??$funcTmpl@UExplicitDecl_Exported@@@@YAXXZ"()
388// GNU-DAG: define weak_odr dllexport void @_Z8funcTmplI21ExplicitDecl_ExportedEvv()
389extern template __declspec(dllexport) void funcTmpl<ExplicitDecl_Exported>();
390 template __declspec(dllexport) void funcTmpl<ExplicitDecl_Exported>();
391
392// Export explicit instantiation definition of a non-exported function template.
393// MSC-DAG: define weak_odr dllexport void @"\01??$funcTmpl@UExplicitInst_Exported@@@@YAXXZ"()
394// GNU-DAG: define weak_odr dllexport void @_Z8funcTmplI21ExplicitInst_ExportedEvv()
395template __declspec(dllexport) void funcTmpl<ExplicitInst_Exported>();
396
397// Export specialization of a non-exported function template.
398// MSC-DAG: define dllexport void @"\01??$funcTmpl@UExplicitSpec_Def_Exported@@@@YAXXZ"()
399// GNU-DAG: define dllexport void @_Z8funcTmplI25ExplicitSpec_Def_ExportedEvv()
400template<> __declspec(dllexport) void funcTmpl<ExplicitSpec_Def_Exported>() {}
401
402// MSC-DAG: define weak_odr dllexport void @"\01??$funcTmpl@UExplicitSpec_InlineDef_Exported@@@@YAXXZ"()
403// GNU-DAG: define weak_odr dllexport void @_Z8funcTmplI31ExplicitSpec_InlineDef_ExportedEvv()
404template<> __declspec(dllexport) inline void funcTmpl<ExplicitSpec_InlineDef_Exported>() {}
405
406
407
408//===----------------------------------------------------------------------===//
409// Precedence
410//===----------------------------------------------------------------------===//
411
412// dllexport takes precedence over the dllimport if both are specified.
413// MSC-DAG: @"\01?PrecedenceGlobal1A@@3HA" = dllexport global i32 0, align 4
414// MSC-DAG: @"\01?PrecedenceGlobal1B@@3HA" = dllexport global i32 0, align 4
415// GNU-DAG: @PrecedenceGlobal1A = dllexport global i32 0, align 4
416// GNU-DAG: @PrecedenceGlobal1B = dllexport global i32 0, align 4
417__attribute__((dllimport, dllexport)) int PrecedenceGlobal1A; // dllimport ignored
418__declspec(dllimport) __declspec(dllexport) int PrecedenceGlobal1B; // dllimport ignored
419
420// MSC-DAG: @"\01?PrecedenceGlobal2A@@3HA" = dllexport global i32 0, align 4
421// MSC-DAG: @"\01?PrecedenceGlobal2B@@3HA" = dllexport global i32 0, align 4
422// GNU-DAG: @PrecedenceGlobal2A = dllexport global i32 0, align 4
423// GNU-DAG: @PrecedenceGlobal2B = dllexport global i32 0, align 4
424__attribute__((dllexport, dllimport)) int PrecedenceGlobal2A; // dllimport ignored
425__declspec(dllexport) __declspec(dllimport) int PrecedenceGlobal2B; // dllimport ignored
426
427// MSC-DAG: @"\01?PrecedenceGlobalRedecl1@@3HA" = dllexport global i32 0, align 4
428// GNU-DAG: @PrecedenceGlobalRedecl1 = dllexport global i32 0, align 4
429__declspec(dllexport) extern int PrecedenceGlobalRedecl1;
430__declspec(dllimport) int PrecedenceGlobalRedecl1 = 0;
431
432// MSC-DAG: @"\01?PrecedenceGlobalRedecl2@@3HA" = dllexport global i32 0, align 4
433// GNU-DAG: @PrecedenceGlobalRedecl2 = dllexport global i32 0, align 4
434__declspec(dllimport) extern int PrecedenceGlobalRedecl2;
435__declspec(dllexport) int PrecedenceGlobalRedecl2;
436
437// MSC-DAG: @"\01?PrecedenceGlobalMixed1@@3HA" = dllexport global i32 0, align 4
438// GNU-DAG: @PrecedenceGlobalMixed1 = dllexport global i32 0, align 4
439__attribute__((dllexport)) extern int PrecedenceGlobalMixed1;
440__declspec(dllimport) int PrecedenceGlobalMixed1 = 0;
441
442// MSC-DAG: @"\01?PrecedenceGlobalMixed2@@3HA" = dllexport global i32 0, align 4
443// GNU-DAG: @PrecedenceGlobalMixed2 = dllexport global i32 0, align 4
444__attribute__((dllimport)) extern int PrecedenceGlobalMixed2;
445__declspec(dllexport) int PrecedenceGlobalMixed2;
446
447// MSC-DAG: define dllexport void @"\01?precedence1A@@YAXXZ"
448// MSC-DAG: define dllexport void @"\01?precedence1B@@YAXXZ"
449// GNU-DAG: define dllexport void @_Z12precedence1Av()
450// GNU-DAG: define dllexport void @_Z12precedence1Bv()
451void __attribute__((dllimport, dllexport)) precedence1A() {}
452void __declspec(dllimport) __declspec(dllexport) precedence1B() {}
453
454// MSC-DAG: define dllexport void @"\01?precedence2A@@YAXXZ"
455// MSC-DAG: define dllexport void @"\01?precedence2B@@YAXXZ"
456// GNU-DAG: define dllexport void @_Z12precedence2Av()
457// GNU-DAG: define dllexport void @_Z12precedence2Bv()
458void __attribute__((dllexport, dllimport)) precedence2A() {}
459void __declspec(dllexport) __declspec(dllimport) precedence2B() {}
460
461// MSC-DAG: define dllexport void @"\01?precedenceRedecl1@@YAXXZ"
462// GNU-DAG: define dllexport void @_Z17precedenceRedecl1v()
463void __declspec(dllimport) precedenceRedecl1();
464void __declspec(dllexport) precedenceRedecl1() {}
465
466// MSC-DAG: define dllexport void @"\01?precedenceRedecl2@@YAXXZ"
467// GNU-DAG: define dllexport void @_Z17precedenceRedecl2v()
468void __declspec(dllexport) precedenceRedecl2();
469void __declspec(dllimport) precedenceRedecl2() {}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700470
471
472
473//===----------------------------------------------------------------------===//
474// Classes
475//===----------------------------------------------------------------------===//
476
477struct S {
478 void __declspec(dllexport) a() {}
479 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?a@S@@QAEXXZ"
480
481 struct T {
482 void __declspec(dllexport) a() {}
483 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?a@T@S@@QAEXXZ"
484 };
485};
486
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700487struct CtorWithClosure {
488 __declspec(dllexport) CtorWithClosure(...) {}
489// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??_FCtorWithClosure@@QAEXXZ"
490// M32-DAG: %[[this_addr:.*]] = alloca %struct.CtorWithClosure*, align 4
491// M32-DAG: store %struct.CtorWithClosure* %this, %struct.CtorWithClosure** %[[this_addr]], align 4
492// M32-DAG: %[[this:.*]] = load %struct.CtorWithClosure*, %struct.CtorWithClosure** %[[this_addr]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700493// M32-DAG: call %struct.CtorWithClosure* (%struct.CtorWithClosure*, ...) @"\01??0CtorWithClosure@@QAA@ZZ"(%struct.CtorWithClosure* %[[this]])
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700494// M32-DAG: ret void
495};
496
497#define DELETE_IMPLICIT_MEMBERS(ClassName) \
498 ClassName(ClassName &&) = delete; \
499 ClassName(ClassName &) = delete; \
500 ~ClassName() = delete; \
501 ClassName &operator=(ClassName &) = delete
502
503struct __declspec(dllexport) ClassWithClosure {
504 DELETE_IMPLICIT_MEMBERS(ClassWithClosure);
505 ClassWithClosure(...) {}
506// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??_FClassWithClosure@@QAEXXZ"
507// M32-DAG: %[[this_addr:.*]] = alloca %struct.ClassWithClosure*, align 4
508// M32-DAG: store %struct.ClassWithClosure* %this, %struct.ClassWithClosure** %[[this_addr]], align 4
509// M32-DAG: %[[this:.*]] = load %struct.ClassWithClosure*, %struct.ClassWithClosure** %[[this_addr]]
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700510// M32-DAG: call %struct.ClassWithClosure* (%struct.ClassWithClosure*, ...) @"\01??0ClassWithClosure@@QAA@ZZ"(%struct.ClassWithClosure* %[[this]])
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700511// M32-DAG: ret void
512};
513
514struct __declspec(dllexport) NestedOuter {
515 DELETE_IMPLICIT_MEMBERS(NestedOuter);
516 NestedOuter(void *p = 0) {}
517 struct __declspec(dllexport) NestedInner {
518 DELETE_IMPLICIT_MEMBERS(NestedInner);
519 NestedInner(void *p = 0) {}
520 };
521};
522
523// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??_FNestedOuter@@QAEXXZ"
524// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??_FNestedInner@NestedOuter@@QAEXXZ"
525
526template <typename T>
527struct SomeTemplate {
528 SomeTemplate(T o = T()) : o(o) {}
529 T o;
530};
531struct __declspec(dllexport) InheritFromTemplate : SomeTemplate<int> {};
532
533// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??_F?$SomeTemplate@H@@QAEXXZ"
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700534
535struct __declspec(dllexport) T {
536 // Copy assignment operator:
Stephen Hines176edba2014-12-01 14:53:08 -0800537 // M32-DAG: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.T* @"\01??4T@@QAEAAU0@ABU0@@Z"
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700538
539 // Explicitly defaulted copy constructur:
540 T(const T&) = default;
541 // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.T* @"\01??0T@@QAE@ABU0@@Z"
542
543 void a() {}
544 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?a@T@@QAEXXZ"
545
546 static int b;
547 // M32-DAG: @"\01?b@T@@2HA" = external dllexport global i32
548
549 static int c;
550 // M32-DAG: @"\01?c@T@@2HA" = dllexport global i32 0, align 4
551};
552
553USEVAR(T::b)
554int T::c;
555
556template <typename T> struct __declspec(dllexport) U { void foo() {} };
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700557struct __declspec(dllexport) V : public U<int> { };
Stephen Hines176edba2014-12-01 14:53:08 -0800558// U<int>'s assignment operator is emitted.
559// M32-DAG: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.U* @"\01??4?$U@H@@QAEAAU0@ABU0@@Z"
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700560
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700561struct __declspec(dllexport) W { virtual void foo(); };
562void W::foo() {}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700563// Default ctor:
564// M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.W* @"\01??0W@@QAE@XZ"
565// Copy ctor:
566// M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.W* @"\01??0W@@QAE@ABU0@@Z"
567// vftable:
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700568// M32-DAG: [[W_VTABLE:@.*]] = private unnamed_addr constant [2 x i8*] [i8* bitcast (%rtti.CompleteObjectLocator* @"\01??_R4W@@6B@" to i8*), i8* bitcast (void (%struct.W*)* @"\01?foo@W@@UAEXXZ" to i8*)], comdat($"\01??_7W@@6B@")
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700569// M32-DAG: @"\01??_7W@@6B@" = dllexport unnamed_addr alias getelementptr inbounds ([2 x i8*], [2 x i8*]* [[W_VTABLE]], i32 0, i32 1)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700570// G32-DAG: @_ZTV1W = dllexport unnamed_addr constant [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1W to i8*), i8* bitcast (void (%struct.W*)* @_ZN1W3fooEv to i8*)]
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700571
572struct __declspec(dllexport) X : public virtual W {};
573// vbtable:
574// M32-DAG: @"\01??_8X@@7B@" = weak_odr dllexport unnamed_addr constant [2 x i32] [i32 0, i32 4]
575
576struct __declspec(dllexport) Y {
577 // Move assignment operator:
Stephen Hines176edba2014-12-01 14:53:08 -0800578 // M32-DAG: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.Y* @"\01??4Y@@QAEAAU0@$$QAU0@@Z"
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700579
580 int x;
581};
582
583struct __declspec(dllexport) Z { virtual ~Z() {} };
584// The scalar deleting dtor does not get exported:
Stephen Hines176edba2014-12-01 14:53:08 -0800585// M32-DAG: define linkonce_odr x86_thiscallcc i8* @"\01??_GZ@@UAEPAXI@Z"
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700586
587
588// The user-defined dtor does get exported:
589// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??1Z@@UAE@XZ"
590
Stephen Hines176edba2014-12-01 14:53:08 -0800591namespace UseDtorAlias {
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700592 struct __declspec(dllexport) A { ~A(); };
593 struct __declspec(dllexport) B : A { ~B(); };
594 A::~A() { }
595 B::~B() { }
Stephen Hines176edba2014-12-01 14:53:08 -0800596 // Emit a alias definition of B's constructor.
597 // M32-DAG: @"\01??1B@UseDtorAlias@@QAE@XZ" = dllexport alias {{.*}} @"\01??1A@UseDtorAlias@@QAE@XZ"
598
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700599}
600
601struct __declspec(dllexport) DefaultedCtorsDtors {
602 DefaultedCtorsDtors() = default;
603 // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.DefaultedCtorsDtors* @"\01??0DefaultedCtorsDtors@@QAE@XZ"
604 ~DefaultedCtorsDtors() = default;
605 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??1DefaultedCtorsDtors@@QAE@XZ"
606};
607
608namespace ReferencedInlineMethodInNestedClass {
609 struct __declspec(dllexport) S {
610 void foo() {
611 t->bar();
612 }
613 struct T {
614 void bar() {}
615 };
616 T *t;
617 };
618 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?foo@S@ReferencedInlineMethodInNestedClass@@QAEXXZ"
619 // M32-DAG: define linkonce_odr x86_thiscallcc void @"\01?bar@T@S@ReferencedInlineMethodInNestedClass@@QAEXXZ"
620}
621
622// MS ignores DLL attributes on partial specializations.
623template <typename T> struct PartiallySpecializedClassTemplate {};
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700624template <typename T> struct __declspec(dllexport) PartiallySpecializedClassTemplate<T*> { void f(); };
625template <typename T> void PartiallySpecializedClassTemplate<T*>::f() {}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700626USEMEMFUNC(PartiallySpecializedClassTemplate<void*>, f);
627// M32-DAG: define linkonce_odr x86_thiscallcc void @"\01?f@?$PartiallySpecializedClassTemplate@PAX@@QAEXXZ"
628// G32-DAG: define weak_odr dllexport x86_thiscallcc void @_ZN33PartiallySpecializedClassTemplateIPvE1fEv
629
Stephen Hines176edba2014-12-01 14:53:08 -0800630// Attributes on explicit specializations are honored.
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700631template <typename T> struct ExplicitlySpecializedClassTemplate {};
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700632template <> struct __declspec(dllexport) ExplicitlySpecializedClassTemplate<void*> { void f(); };
633void ExplicitlySpecializedClassTemplate<void*>::f() {}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700634USEMEMFUNC(ExplicitlySpecializedClassTemplate<void*>, f);
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700635// M32-DAG: define dllexport x86_thiscallcc void @"\01?f@?$ExplicitlySpecializedClassTemplate@PAX@@QAEXXZ"
636// G32-DAG: define dllexport x86_thiscallcc void @_ZN34ExplicitlySpecializedClassTemplateIPvE1fEv
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700637
Stephen Hines176edba2014-12-01 14:53:08 -0800638// MS inherits DLL attributes to partial specializations.
639template <typename T> struct __declspec(dllexport) PartiallySpecializedExportedClassTemplate {};
640template <typename T> struct PartiallySpecializedExportedClassTemplate<T*> { void f() {} };
641USEMEMFUNC(PartiallySpecializedExportedClassTemplate<void*>, f);
642// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$PartiallySpecializedExportedClassTemplate@PAX@@QAEXXZ"
643// G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN41PartiallySpecializedExportedClassTemplateIPvE1fEv
644
645// MS ignores DLL attributes on partial specializations; inheritance still works though.
646template <typename T> struct __declspec(dllexport) PartiallySpecializedExportedClassTemplate2 {};
647template <typename T> struct __declspec(dllimport) PartiallySpecializedExportedClassTemplate2<T*> { void f(); };
648template <typename T> void PartiallySpecializedExportedClassTemplate2<T*>::f() {}
649USEMEMFUNC(PartiallySpecializedExportedClassTemplate2<void*>, f);
650// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$PartiallySpecializedExportedClassTemplate2@PAX@@QAEXXZ"
651// G32-DAG: declare dllimport x86_thiscallcc void @_ZN42PartiallySpecializedExportedClassTemplate2IPvE1fEv
652
653// Attributes on the instantiation take precedence over attributes on the template.
654template <typename T> struct __declspec(dllimport) ExplicitlyInstantiatedWithDifferentAttr { void f() {} };
655template struct __declspec(dllexport) ExplicitlyInstantiatedWithDifferentAttr<int>;
656USEMEMFUNC(ExplicitlyInstantiatedWithDifferentAttr<int>, f);
657// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ExplicitlyInstantiatedWithDifferentAttr@H@@QAEXXZ"
658
659// Don't create weak dllexport aliases. (PR21373)
660struct NonExportedBaseClass {
661 virtual ~NonExportedBaseClass();
662};
663NonExportedBaseClass::~NonExportedBaseClass() {}
664
665struct __declspec(dllexport) ExportedDerivedClass : NonExportedBaseClass {};
666// M32-DAG: weak_odr dllexport x86_thiscallcc void @"\01??1ExportedDerivedClass@@UAE@XZ"
667
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700668// Do not assert about generating code for constexpr functions twice during explicit instantiation (PR21718).
669template <typename T> struct ExplicitInstConstexprMembers {
670 // Copy assignment operator
671 // M32-DAG: define weak_odr dllexport x86_thiscallcc dereferenceable(1) %struct.ExplicitInstConstexprMembers* @"\01??4?$ExplicitInstConstexprMembers@X@@QAEAAU0@ABU0@@Z"
672
673 constexpr ExplicitInstConstexprMembers() {}
674 // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.ExplicitInstConstexprMembers* @"\01??0?$ExplicitInstConstexprMembers@X@@QAE@XZ"
675
676 ExplicitInstConstexprMembers(const ExplicitInstConstexprMembers&) = default;
677 // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.ExplicitInstConstexprMembers* @"\01??0?$ExplicitInstConstexprMembers@X@@QAE@ABU0@@Z"
678
679 constexpr int f() const { return 42; }
680 // M32-DAG: define weak_odr dllexport x86_thiscallcc i32 @"\01?f@?$ExplicitInstConstexprMembers@X@@QBEHXZ"
681};
682template struct __declspec(dllexport) ExplicitInstConstexprMembers<void>;
683
684template <typename T> struct ExplicitInstantiationDeclTemplate { void f() {} };
685extern template struct __declspec(dllexport) ExplicitInstantiationDeclTemplate<int>;
686USEMEMFUNC(ExplicitInstantiationDeclTemplate<int>, f);
687// M32-DAG: {{declare|define available_externally}} x86_thiscallcc void @"\01?f@?$ExplicitInstantiationDeclTemplate@H@@QAEXXZ"
688
689template <typename T> struct __declspec(dllexport) ExplicitInstantiationDeclExportedTemplate { void f() {} };
690extern template struct ExplicitInstantiationDeclExportedTemplate<int>;
691USEMEMFUNC(ExplicitInstantiationDeclExportedTemplate<int>, f);
692// M32-DAG: {{declare|define available_externally}} x86_thiscallcc void @"\01?f@?$ExplicitInstantiationDeclExportedTemplate@H@@QAEXXZ"
693
Stephen Hines176edba2014-12-01 14:53:08 -0800694
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700695//===----------------------------------------------------------------------===//
696// Classes with template base classes
697//===----------------------------------------------------------------------===//
698
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700699template <typename T> struct ClassTemplate { void func(); };
700template <typename T> void ClassTemplate<T>::func() {}
701template <typename T> struct __declspec(dllexport) ExportedClassTemplate { void func(); };
702template <typename T> void ExportedClassTemplate<T>::func() {}
Stephen Hines176edba2014-12-01 14:53:08 -0800703template <typename T> struct __declspec(dllimport) ImportedClassTemplate { void func(); };
704template <typename T> void ImportedClassTemplate<T>::func() {}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700705
706template <typename T> struct ExplicitlySpecializedTemplate { void func() {} };
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700707template <> struct ExplicitlySpecializedTemplate<int> { void func(); };
708void ExplicitlySpecializedTemplate<int>::func() {}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700709template <typename T> struct ExplicitlyExportSpecializedTemplate { void func() {} };
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700710template <> struct __declspec(dllexport) ExplicitlyExportSpecializedTemplate<int> { void func(); };
711void ExplicitlyExportSpecializedTemplate<int>::func() {}
Stephen Hines176edba2014-12-01 14:53:08 -0800712template <typename T> struct ExplicitlyImportSpecializedTemplate { void func(); };
713template <> struct __declspec(dllimport) ExplicitlyImportSpecializedTemplate<int> { void func(); };
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700714
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700715template <typename T> struct ExplicitlyInstantiatedTemplate { void func(); };
716template <typename T> void ExplicitlyInstantiatedTemplate<T>::func() {}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700717template struct ExplicitlyInstantiatedTemplate<int>;
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700718template <typename T> struct ExplicitlyExportInstantiatedTemplate { void func(); };
719template <typename T> void ExplicitlyExportInstantiatedTemplate<T>::func() {}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700720template struct __declspec(dllexport) ExplicitlyExportInstantiatedTemplate<int>;
Stephen Hines176edba2014-12-01 14:53:08 -0800721template <typename T> struct ExplicitlyImportInstantiatedTemplate { void func(); };
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700722template struct __declspec(dllimport) ExplicitlyImportInstantiatedTemplate<int>;
723
724
725// MS: ClassTemplate<int> gets exported.
726struct __declspec(dllexport) DerivedFromTemplate : public ClassTemplate<int> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800727USEMEMFUNC(DerivedFromTemplate, func)
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700728// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$ClassTemplate@H@@QAEXXZ"
729// G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN13ClassTemplateIiE4funcEv
730
731// ExportedTemplate is explicitly exported.
732struct __declspec(dllexport) DerivedFromExportedTemplate : public ExportedClassTemplate<int> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800733USEMEMFUNC(DerivedFromExportedTemplate, func)
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700734// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$ExportedClassTemplate@H@@QAEXXZ"
735// G32-DAG: define weak_odr dllexport x86_thiscallcc void @_ZN21ExportedClassTemplateIiE4funcEv
736
737// ImportedClassTemplate is explicitly imported.
738struct __declspec(dllexport) DerivedFromImportedTemplate : public ImportedClassTemplate<int> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800739USEMEMFUNC(DerivedFromImportedTemplate, func)
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700740// M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"\01?func@?$ImportedClassTemplate@H@@QAEXXZ"
741// G32-DAG: declare dllimport x86_thiscallcc void @_ZN21ImportedClassTemplateIiE4funcEv
742
743// Base class already instantiated without dll attribute.
744struct DerivedFromTemplateD : public ClassTemplate<double> {};
745struct __declspec(dllexport) DerivedFromTemplateD2 : public ClassTemplate<double> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800746USEMEMFUNC(DerivedFromTemplateD2, func)
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700747// M32-DAG: define linkonce_odr x86_thiscallcc void @"\01?func@?$ClassTemplate@N@@QAEXXZ"
748// G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN13ClassTemplateIdE4funcEv
749
750// MS: Base class already instantiated with different dll attribute.
751struct __declspec(dllimport) DerivedFromTemplateB : public ClassTemplate<bool> {};
752struct __declspec(dllexport) DerivedFromTemplateB2 : public ClassTemplate<bool> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800753USEMEMFUNC(DerivedFromTemplateB2, func)
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700754// M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"\01?func@?$ClassTemplate@_N@@QAEXXZ"
755// G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN13ClassTemplateIbE4funcEv
756
757// Base class already specialized without dll attribute.
758struct __declspec(dllexport) DerivedFromExplicitlySpecializedTemplate : public ExplicitlySpecializedTemplate<int> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800759USEMEMFUNC(DerivedFromExplicitlySpecializedTemplate, func)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700760// M32-DAG: define x86_thiscallcc void @"\01?func@?$ExplicitlySpecializedTemplate@H@@QAEXXZ"
761// G32-DAG: define x86_thiscallcc void @_ZN29ExplicitlySpecializedTemplateIiE4funcEv
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700762
763// Base class alredy specialized with export attribute.
764struct __declspec(dllexport) DerivedFromExplicitlyExportSpecializedTemplate : public ExplicitlyExportSpecializedTemplate<int> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800765USEMEMFUNC(DerivedFromExplicitlyExportSpecializedTemplate, func)
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700766// M32-DAG: define dllexport x86_thiscallcc void @"\01?func@?$ExplicitlyExportSpecializedTemplate@H@@QAEXXZ"
767// G32-DAG: define dllexport x86_thiscallcc void @_ZN35ExplicitlyExportSpecializedTemplateIiE4funcEv
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700768
769// Base class already specialized with import attribute.
770struct __declspec(dllexport) DerivedFromExplicitlyImportSpecializedTemplate : public ExplicitlyImportSpecializedTemplate<int> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800771USEMEMFUNC(DerivedFromExplicitlyImportSpecializedTemplate, func)
772// M32-DAG: declare dllimport x86_thiscallcc void @"\01?func@?$ExplicitlyImportSpecializedTemplate@H@@QAEXXZ"
773// G32-DAG: declare dllimport x86_thiscallcc void @_ZN35ExplicitlyImportSpecializedTemplateIiE4funcEv
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700774
775// Base class already instantiated without dll attribute.
776struct __declspec(dllexport) DerivedFromExplicitlyInstantiatedTemplate : public ExplicitlyInstantiatedTemplate<int> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800777USEMEMFUNC(DerivedFromExplicitlyInstantiatedTemplate, func)
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700778// M32-DAG: define weak_odr x86_thiscallcc void @"\01?func@?$ExplicitlyInstantiatedTemplate@H@@QAEXXZ"
779// G32-DAG: define weak_odr x86_thiscallcc void @_ZN30ExplicitlyInstantiatedTemplateIiE4funcEv
780
781// Base class already instantiated with export attribute.
782struct __declspec(dllexport) DerivedFromExplicitlyExportInstantiatedTemplate : public ExplicitlyExportInstantiatedTemplate<int> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800783USEMEMFUNC(DerivedFromExplicitlyExportInstantiatedTemplate, func)
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700784// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$ExplicitlyExportInstantiatedTemplate@H@@QAEXXZ"
785// G32-DAG: define weak_odr dllexport x86_thiscallcc void @_ZN36ExplicitlyExportInstantiatedTemplateIiE4funcEv
786
787// Base class already instantiated with import attribute.
788struct __declspec(dllexport) DerivedFromExplicitlyImportInstantiatedTemplate : public ExplicitlyImportInstantiatedTemplate<int> {};
Stephen Hines176edba2014-12-01 14:53:08 -0800789USEMEMFUNC(DerivedFromExplicitlyImportInstantiatedTemplate, func)
790// M32-DAG: declare dllimport x86_thiscallcc void @"\01?func@?$ExplicitlyImportInstantiatedTemplate@H@@QAEXXZ"
791// G32-DAG: declare dllimport x86_thiscallcc void @_ZN36ExplicitlyImportInstantiatedTemplateIiE4funcEv
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700792
793// MS: A dll attribute propagates through multiple levels of instantiation.
794template <typename T> struct TopClass { void func() {} };
795template <typename T> struct MiddleClass : public TopClass<T> { };
Stephen Hines176edba2014-12-01 14:53:08 -0800796struct __declspec(dllexport) BottomClass : public MiddleClass<int> { };
797USEMEMFUNC(BottomClass, func)
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700798// M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$TopClass@H@@QAEXXZ"
799// G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN8TopClassIiE4funcEv