]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGenCXX/dllexport.cpp
Vendor import of clang trunk r300422:
[FreeBSD/FreeBSD.git] / test / CodeGenCXX / dllexport.cpp
1 // RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-passes -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2015 -check-prefix=M32MSVC2015 %s
2 // RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-passes -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2013 -check-prefix=M32MSVC2013 %s
3
4 // RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2015 -check-prefix=M64MSVC2015 %s
5 // RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2013 -check-prefix=M64MSVC2013 %s
6
7 // RUN: %clang_cc1 -triple i686-windows-gnu    -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G32 %s
8 // RUN: %clang_cc1 -triple x86_64-windows-gnu  -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G64 %s
9
10 // Helper structs to make templates more expressive.
11 struct ImplicitInst_Exported {};
12 struct ExplicitDecl_Exported {};
13 struct ExplicitInst_Exported {};
14 struct ExplicitSpec_Exported {};
15 struct ExplicitSpec_Def_Exported {};
16 struct ExplicitSpec_InlineDef_Exported {};
17 struct ExplicitSpec_NotExported {};
18 struct External { int v; };
19
20 #define JOIN2(x, y) x##y
21 #define JOIN(x, y) JOIN2(x, y)
22 #define UNIQ(name) JOIN(name, __LINE__)
23 #define USEVAR(var) int UNIQ(use)() { return var; }
24 #define USE(func) void UNIQ(use)() { func(); }
25 #define USEMEMFUNC(class, func) void (class::*UNIQ(use)())() { return &class::func; }
26 #define INSTVAR(var) template int var;
27 #define INST(func) template void func();
28
29 // The vftable for struct W is comdat largest because we have RTTI.
30 // M32-DAG: $"\01??_7W@@6B@" = comdat largest
31
32
33 //===----------------------------------------------------------------------===//
34 // Globals
35 //===----------------------------------------------------------------------===//
36
37 // Declarations are not exported.
38 // MSC-NOT: @"\01?ExternGlobalDecl@@3HA"
39 // GNU-NOT: @ExternGlobalDecl
40 __declspec(dllexport) extern int ExternGlobalDecl;
41
42 // dllexport implies a definition.
43 // MSC-DAG: @"\01?GlobalDef@@3HA" = dllexport global i32 0, align 4
44 // GNU-DAG: @GlobalDef            = dllexport global i32 0, align 4
45 __declspec(dllexport) int GlobalDef;
46
47 // Export definition.
48 // MSC-DAG: @"\01?GlobalInit1@@3HA" = dllexport global i32 1, align 4
49 // GNU-DAG: @GlobalInit1            = dllexport global i32 1, align 4
50 __declspec(dllexport) int GlobalInit1 = 1;
51
52 // MSC-DAG: @"\01?GlobalInit2@@3HA" = dllexport global i32 1, align 4
53 // GNU-DAG: @GlobalInit2            = dllexport global i32 1, align 4
54 int __declspec(dllexport) GlobalInit2 = 1;
55
56 // Declare, then export definition.
57 // MSC-DAG: @"\01?GlobalDeclInit@@3HA" = dllexport global i32 1, align 4
58 // GNU-DAG: @GlobalDeclInit            = dllexport global i32 1, align 4
59 __declspec(dllexport) extern int GlobalDeclInit;
60 int GlobalDeclInit = 1;
61
62 // Redeclarations
63 // MSC-DAG: @"\01?GlobalRedecl1@@3HA" = dllexport global i32 0, align 4
64 // GNU-DAG: @GlobalRedecl1            = dllexport global i32 0, align 4
65 __declspec(dllexport) extern int GlobalRedecl1;
66 __declspec(dllexport)        int GlobalRedecl1;
67
68 // MSC-DAG: @"\01?GlobalRedecl2@@3HA" = dllexport global i32 0, align 4
69 // GNU-DAG: @GlobalRedecl2            = dllexport global i32 0, align 4
70 __declspec(dllexport) extern int GlobalRedecl2;
71                              int GlobalRedecl2;
72
73 // MSC-DAG: @"\01?ExternalGlobal@ns@@3HA" = dllexport global i32 0, align 4
74 // GNU-DAG: @_ZN2ns14ExternalGlobalE      = dllexport global i32 0, align 4
75 namespace ns { __declspec(dllexport) int ExternalGlobal; }
76
77 // MSC-DAG: @"\01?ExternalAutoTypeGlobal@@3UExternal@@A" = dllexport global %struct.External zeroinitializer, align 4
78 // GNU-DAG: @ExternalAutoTypeGlobal                      = dllexport global %struct.External zeroinitializer, align 4
79 __declspec(dllexport) auto ExternalAutoTypeGlobal = External();
80
81 int f();
82 // MSC-DAG: @"\01?x@?1??nonInlineStaticLocalsFunc@@YAHXZ@4HA" = internal {{(unnamed_addr )*}}global i32 0
83 // MSC-DAG: @"\01?$S1@?1??nonInlineStaticLocalsFunc@@YAHXZ@4IA" = internal {{(unnamed_addr )*}}global i32 0
84 int __declspec(dllexport) nonInlineStaticLocalsFunc() {
85   static int x = f();
86   return x++;
87 };
88
89 // MSC-DAG: @"\01?x@?1??inlineStaticLocalsFunc@@YAHXZ@4HA" = weak_odr dllexport global i32 0, comdat
90 // MSC-DAG: @"\01??_B?1??inlineStaticLocalsFunc@@YAHXZ@51" = weak_odr dllexport global i32 0, comdat
91 // Note: MinGW doesn't seem to export the static local here.
92 inline int __declspec(dllexport) inlineStaticLocalsFunc() {
93   static int x = f();
94   return x++;
95 }
96
97
98
99 //===----------------------------------------------------------------------===//
100 // Variable templates
101 //===----------------------------------------------------------------------===//
102
103 // Declarations are not exported.
104
105 // dllexport implies a definition.
106 // MSC-NOT: @"\01??$VarTmplDef@UExplicitInst_Exported@@@@3HA"
107 // GNU-NOT: @_Z10VarTmplDefI21ExplicitInst_ExportedE
108 template<typename T> __declspec(dllexport) int VarTmplDef;
109 INSTVAR(VarTmplDef<ExplicitInst_Exported>)
110
111 // MSC-DAG: @"\01??$VarTmplImplicitDef@UImplicitInst_Exported@@@@3HA" = external global
112 // GNU-DAG: @_Z18VarTmplImplicitDefI21ImplicitInst_ExportedE          = external global
113 template<typename T> __declspec(dllexport) int VarTmplImplicitDef;
114 USEVAR(VarTmplImplicitDef<ImplicitInst_Exported>)
115
116 // Export definition.
117 // MSC-DAG: @"\01??$VarTmplInit1@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
118 // GNU-DAG: @_Z12VarTmplInit1I21ExplicitInst_ExportedE          = weak_odr dllexport global i32 1, comdat, align 4
119 template<typename T> __declspec(dllexport) int VarTmplInit1 = 1;
120 INSTVAR(VarTmplInit1<ExplicitInst_Exported>)
121
122 // MSC-DAG: @"\01??$VarTmplInit2@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
123 // GNU-DAG: @_Z12VarTmplInit2I21ExplicitInst_ExportedE          = weak_odr dllexport global i32 1, comdat, align 4
124 template<typename T> int __declspec(dllexport) VarTmplInit2 = 1;
125 INSTVAR(VarTmplInit2<ExplicitInst_Exported>)
126
127 // Declare, then export definition.
128 // MSC-DAG: @"\01??$VarTmplDeclInit@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
129 // GNU-DAG: @_Z15VarTmplDeclInitI21ExplicitInst_ExportedE          = weak_odr dllexport global i32 1, comdat, align 4
130 template<typename T> __declspec(dllexport) extern int VarTmplDeclInit;
131 template<typename T>                              int VarTmplDeclInit = 1;
132 INSTVAR(VarTmplDeclInit<ExplicitInst_Exported>)
133
134 // Redeclarations
135 // MSC-DAG: @"\01??$VarTmplRedecl1@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
136 // GNU-DAG: @_Z14VarTmplRedecl1I21ExplicitInst_ExportedE          = weak_odr dllexport global i32 1, comdat, align 4
137 template<typename T> __declspec(dllexport) extern int VarTmplRedecl1;
138 template<typename T> __declspec(dllexport)        int VarTmplRedecl1 = 1;
139 INSTVAR(VarTmplRedecl1<ExplicitInst_Exported>)
140
141 // MSC-DAG: @"\01??$VarTmplRedecl2@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
142 // GNU-DAG: @_Z14VarTmplRedecl2I21ExplicitInst_ExportedE          = weak_odr dllexport global i32 1, comdat, align 4
143 template<typename T> __declspec(dllexport) extern int VarTmplRedecl2;
144 template<typename T>                              int VarTmplRedecl2 = 1;
145 INSTVAR(VarTmplRedecl2<ExplicitInst_Exported>)
146
147 // MSC-DAG: @"\01??$ExternalVarTmpl@UExplicitInst_Exported@@@ns@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
148 // GNU-DAG: @_ZN2ns15ExternalVarTmplI21ExplicitInst_ExportedEE        = weak_odr dllexport global i32 1, comdat, align 4
149 namespace ns { template<typename T> __declspec(dllexport) int ExternalVarTmpl = 1; }
150 INSTVAR(ns::ExternalVarTmpl<ExplicitInst_Exported>)
151
152 // MSC-DAG: @"\01??$ExternalAutoTypeVarTmpl@UExplicitInst_Exported@@@@3UExternal@@A" = weak_odr dllexport global %struct.External zeroinitializer, comdat, align 4
153 // GNU-DAG: @_Z23ExternalAutoTypeVarTmplI21ExplicitInst_ExportedE                    = weak_odr dllexport global %struct.External zeroinitializer, comdat, align 4
154 template<typename T> __declspec(dllexport) auto ExternalAutoTypeVarTmpl = External();
155 template External ExternalAutoTypeVarTmpl<ExplicitInst_Exported>;
156
157
158 template<typename T> int VarTmpl = 1;
159 template<typename T> __declspec(dllexport) int ExportedVarTmpl = 1;
160
161 // Export implicit instantiation of an exported variable template.
162 // MSC-DAG: @"\01??$ExportedVarTmpl@UImplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
163 // GNU-DAG: @_Z15ExportedVarTmplI21ImplicitInst_ExportedE          = weak_odr dllexport global i32 1, comdat, align 4
164 USEVAR(ExportedVarTmpl<ImplicitInst_Exported>)
165
166 // Export explicit instantiation declaration of an exported variable template.
167 // MSC-DAG: @"\01??$ExportedVarTmpl@UImplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
168 // GNU-DAG: @_Z15ExportedVarTmplI21ExplicitDecl_ExportedE          = weak_odr dllexport global i32 1, comdat, align 4
169 extern template int ExportedVarTmpl<ExplicitDecl_Exported>;
170        template int ExportedVarTmpl<ExplicitDecl_Exported>;
171
172 // Export explicit instantiation definition of an exported variable template.
173 // MSC-DAG: @"\01??$ExportedVarTmpl@UImplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
174 // GNU-DAG: @_Z15ExportedVarTmplI21ExplicitInst_ExportedE          = weak_odr dllexport global i32 1, comdat, align 4
175 template __declspec(dllexport) int ExportedVarTmpl<ExplicitInst_Exported>;
176
177 // Export specialization of an exported variable template.
178 // MSC-DAG: @"\01??$ExportedVarTmpl@UExplicitSpec_Exported@@@@3HA" = dllexport global i32 0, align 4
179 // GNU-DAG: @_Z15ExportedVarTmplI21ExplicitSpec_ExportedE          = dllexport global i32 0, align 4
180 template<> __declspec(dllexport) int ExportedVarTmpl<ExplicitSpec_Exported>;
181
182 // MSC-DAG: @"\01??$ExportedVarTmpl@UExplicitSpec_Def_Exported@@@@3HA" = dllexport global i32 1, align 4
183 // GNU-DAG: @_Z15ExportedVarTmplI25ExplicitSpec_Def_ExportedE          = dllexport global i32 1, align 4
184 template<> __declspec(dllexport) int ExportedVarTmpl<ExplicitSpec_Def_Exported> = 1;
185
186 // Not exporting specialization of an exported variable template without
187 // explicit dllexport.
188 // MSC-DAG: @"\01??$ExportedVarTmpl@UExplicitSpec_NotExported@@@@3HA" = global i32 0, align 4
189 // GNU-DAG: @_Z15ExportedVarTmplI24ExplicitSpec_NotExportedE          = global i32 0, align 4
190 template<> int ExportedVarTmpl<ExplicitSpec_NotExported>;
191
192
193 // Export explicit instantiation declaration of a non-exported variable template.
194 // MSC-DAG: @"\01??$VarTmpl@UExplicitDecl_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
195 // GNU-DAG: @_Z7VarTmplI21ExplicitDecl_ExportedE           = weak_odr dllexport global i32 1, comdat, align 4
196 extern template __declspec(dllexport) int VarTmpl<ExplicitDecl_Exported>;
197        template __declspec(dllexport) int VarTmpl<ExplicitDecl_Exported>;
198
199 // Export explicit instantiation definition of a non-exported variable template.
200 // MSC-DAG: @"\01??$VarTmpl@UExplicitInst_Exported@@@@3HA" = weak_odr dllexport global i32 1, comdat, align 4
201 // GNU-DAG: @_Z7VarTmplI21ExplicitInst_ExportedE           = weak_odr dllexport global i32 1, comdat, align 4
202 template __declspec(dllexport) int VarTmpl<ExplicitInst_Exported>;
203
204 // Export specialization of a non-exported variable template.
205 // MSC-DAG: @"\01??$VarTmpl@UExplicitSpec_Exported@@@@3HA" = dllexport global i32 0, align 4
206 // GNU-DAG: @_Z7VarTmplI21ExplicitSpec_ExportedE           = dllexport global i32 0, align 4
207 template<> __declspec(dllexport) int VarTmpl<ExplicitSpec_Exported>;
208
209 // MSC-DAG: @"\01??$VarTmpl@UExplicitSpec_Def_Exported@@@@3HA" = dllexport global i32 1, align 4
210 // GNU-DAG: @_Z7VarTmplI25ExplicitSpec_Def_ExportedE           = dllexport global i32 1, align 4
211 template<> __declspec(dllexport) int VarTmpl<ExplicitSpec_Def_Exported> = 1;
212
213
214
215 //===----------------------------------------------------------------------===//
216 // Functions
217 //===----------------------------------------------------------------------===//
218
219 // Declarations are not exported.
220
221 // Export function definition.
222 // MSC-DAG: define dllexport void @"\01?def@@YAXXZ"()
223 // GNU-DAG: define dllexport void @_Z3defv()
224 __declspec(dllexport) void def() {}
225
226 // extern "C"
227 // MSC-DAG: define dllexport void @externC()
228 // GNU-DAG: define dllexport void @externC()
229 extern "C" __declspec(dllexport) void externC() {}
230
231 // Export inline function.
232 // MSC-DAG: define weak_odr dllexport void @"\01?inlineFunc@@YAXXZ"()
233 // GNU-DAG: define weak_odr dllexport void @_Z10inlineFuncv()
234 __declspec(dllexport) inline void inlineFunc() {}
235
236 // MSC-DAG: define weak_odr dllexport void @"\01?inlineDecl@@YAXXZ"()
237 // GNU-DAG: define weak_odr dllexport void @_Z10inlineDeclv()
238 __declspec(dllexport) inline void inlineDecl();
239                              void inlineDecl() {}
240
241 // MSC-DAG: define weak_odr dllexport void @"\01?inlineDef@@YAXXZ"()
242 // GNU-DAG: define weak_odr dllexport void @_Z9inlineDefv()
243 __declspec(dllexport) void inlineDef();
244                inline void inlineDef() {}
245
246 // Redeclarations
247 // MSC-DAG: define dllexport void @"\01?redecl1@@YAXXZ"()
248 // GNU-DAG: define dllexport void @_Z7redecl1v()
249 __declspec(dllexport) void redecl1();
250 __declspec(dllexport) void redecl1() {}
251
252 // MSC-DAG: define dllexport void @"\01?redecl2@@YAXXZ"()
253 // GNU-DAG: define dllexport void @_Z7redecl2v()
254 __declspec(dllexport) void redecl2();
255                       void redecl2() {}
256
257 // Friend functions
258 // MSC-DAG: define dllexport void @"\01?friend1@@YAXXZ"()
259 // GNU-DAG: define dllexport void @_Z7friend1v()
260 // MSC-DAG: define dllexport void @"\01?friend2@@YAXXZ"()
261 // GNU-DAG: define dllexport void @_Z7friend2v()
262 struct FuncFriend {
263   friend __declspec(dllexport) void friend1();
264   friend __declspec(dllexport) void friend2();
265 };
266 __declspec(dllexport) void friend1() {}
267                       void friend2() {}
268
269 // Implicit declarations can be redeclared with dllexport.
270 // MSC-DAG: define dllexport noalias i8* @"\01??2@{{YAPAXI|YAPEAX_K}}@Z"(
271 // GNU-DAG: define dllexport noalias i8* @_Znw{{[yj]}}(
272 void* alloc(__SIZE_TYPE__ n);
273 __declspec(dllexport) void* operator new(__SIZE_TYPE__ n) { return alloc(n); }
274
275 // MSC-DAG: define dllexport void @"\01?externalFunc@ns@@YAXXZ"()
276 // GNU-DAG: define dllexport void @_ZN2ns12externalFuncEv()
277 namespace ns { __declspec(dllexport) void externalFunc() {} }
278
279
280
281 //===----------------------------------------------------------------------===//
282 // Function templates
283 //===----------------------------------------------------------------------===//
284
285 // Export function template definition.
286 // MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplDef@UExplicitInst_Exported@@@@YAXXZ"()
287 // GNU-DAG: define weak_odr dllexport void @_Z11funcTmplDefI21ExplicitInst_ExportedEvv()
288 template<typename T> __declspec(dllexport) void funcTmplDef() {}
289 INST(funcTmplDef<ExplicitInst_Exported>)
290
291 // Export inline function template.
292 // MSC-DAG: define weak_odr dllexport void @"\01??$inlineFuncTmpl1@UExplicitInst_Exported@@@@YAXXZ"()
293 // GNU-DAG: define weak_odr dllexport void @_Z15inlineFuncTmpl1I21ExplicitInst_ExportedEvv()
294 template<typename T> __declspec(dllexport) inline void inlineFuncTmpl1() {}
295 INST(inlineFuncTmpl1<ExplicitInst_Exported>)
296
297 // MSC-DAG: define weak_odr dllexport void @"\01??$inlineFuncTmpl2@UExplicitInst_Exported@@@@YAXXZ"()
298 // GNU-DAG: define weak_odr dllexport void @_Z15inlineFuncTmpl2I21ExplicitInst_ExportedEvv()
299 template<typename T> inline void __attribute__((dllexport)) inlineFuncTmpl2() {}
300 INST(inlineFuncTmpl2<ExplicitInst_Exported>)
301
302 // MSC-DAG: define weak_odr dllexport void @"\01??$inlineFuncTmplDecl@UExplicitInst_Exported@@@@YAXXZ"()
303 // GNU-DAG: define weak_odr dllexport void @_Z18inlineFuncTmplDeclI21ExplicitInst_ExportedEvv()
304 template<typename T> __declspec(dllexport) inline void inlineFuncTmplDecl();
305 template<typename T>                              void inlineFuncTmplDecl() {}
306 INST(inlineFuncTmplDecl<ExplicitInst_Exported>)
307
308 // MSC-DAG: define weak_odr dllexport void @"\01??$inlineFuncTmplDef@UExplicitInst_Exported@@@@YAXXZ"()
309 // GNU-DAG: define weak_odr dllexport void @_Z17inlineFuncTmplDefI21ExplicitInst_ExportedEvv()
310 template<typename T> __declspec(dllexport) void inlineFuncTmplDef();
311 template<typename T>                inline void inlineFuncTmplDef() {}
312 INST(inlineFuncTmplDef<ExplicitInst_Exported>)
313
314
315 // Redeclarations
316 // MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplRedecl1@UExplicitInst_Exported@@@@YAXXZ"()
317 // GNU-DAG: define weak_odr dllexport void @_Z15funcTmplRedecl1I21ExplicitInst_ExportedEvv()
318 template<typename T> __declspec(dllexport) void funcTmplRedecl1();
319 template<typename T> __declspec(dllexport) void funcTmplRedecl1() {}
320 INST(funcTmplRedecl1<ExplicitInst_Exported>)
321
322 // MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplRedecl2@UExplicitInst_Exported@@@@YAXXZ"()
323 // GNU-DAG: define weak_odr dllexport void @_Z15funcTmplRedecl2I21ExplicitInst_ExportedEvv()
324 template<typename T> __declspec(dllexport) void funcTmplRedecl2();
325 template<typename T>                       void funcTmplRedecl2() {}
326 INST(funcTmplRedecl2<ExplicitInst_Exported>)
327
328 // MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplRedecl3@UExplicitInst_Exported@@@@YAXXZ"()
329 // GNU-DAG: define weak_odr dllexport void @_Z15funcTmplRedecl3I21ExplicitInst_ExportedEvv()
330 template<typename T> __declspec(dllexport) void funcTmplRedecl3();
331 template<typename T>                       void funcTmplRedecl3() {}
332 INST(funcTmplRedecl3<ExplicitInst_Exported>)
333
334
335 // Function template friends
336 // MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplFriend1@UExplicitInst_Exported@@@@YAXXZ"()
337 // GNU-DAG: define weak_odr dllexport void @_Z15funcTmplFriend1I21ExplicitInst_ExportedEvv()
338 // MSC-DAG: define weak_odr dllexport void @"\01??$funcTmplFriend2@UExplicitInst_Exported@@@@YAXXZ"()
339 // GNU-DAG: define weak_odr dllexport void @_Z15funcTmplFriend2I21ExplicitInst_ExportedEvv()
340 struct FuncTmplFriend {
341   template<typename T> friend __declspec(dllexport) void funcTmplFriend1();
342   template<typename T> friend __declspec(dllexport) void funcTmplFriend2();
343 };
344 template<typename T> __declspec(dllexport) void funcTmplFriend1() {}
345 template<typename T>                       void funcTmplFriend2() {}
346 INST(funcTmplFriend1<ExplicitInst_Exported>)
347 INST(funcTmplFriend2<ExplicitInst_Exported>)
348
349 // MSC-DAG: define weak_odr dllexport void @"\01??$externalFuncTmpl@UExplicitInst_Exported@@@ns@@YAXXZ"()
350 // GNU-DAG: define weak_odr dllexport void @_ZN2ns16externalFuncTmplI21ExplicitInst_ExportedEEvv()
351 namespace ns { template<typename T> __declspec(dllexport) void externalFuncTmpl() {} }
352 INST(ns::externalFuncTmpl<ExplicitInst_Exported>)
353
354
355 template<typename T> void funcTmpl() {}
356 template<typename T> __declspec(dllexport) void exportedFuncTmpl() {}
357
358 // Export implicit instantiation of an exported function template.
359 // MSC-DAG: define weak_odr dllexport void @"\01??$exportedFuncTmpl@UImplicitInst_Exported@@@@YAXXZ"()
360 // GNU-DAG: define weak_odr dllexport void @_Z16exportedFuncTmplI21ImplicitInst_ExportedEvv()
361 USE(exportedFuncTmpl<ImplicitInst_Exported>)
362
363 // Export explicit instantiation declaration of an exported function template.
364 // MSC-DAG: define weak_odr dllexport void @"\01??$exportedFuncTmpl@UExplicitDecl_Exported@@@@YAXXZ"()
365 // GNU-DAG: define weak_odr dllexport void @_Z16exportedFuncTmplI21ExplicitDecl_ExportedEvv()
366 extern template void exportedFuncTmpl<ExplicitDecl_Exported>();
367        template void exportedFuncTmpl<ExplicitDecl_Exported>();
368
369 // Export explicit instantiation definition of an exported function template.
370 // MSC-DAG: define weak_odr dllexport void @"\01??$exportedFuncTmpl@UExplicitInst_Exported@@@@YAXXZ"()
371 // GNU-DAG: define weak_odr dllexport void @_Z16exportedFuncTmplI21ExplicitInst_ExportedEvv()
372 template void exportedFuncTmpl<ExplicitInst_Exported>();
373
374 // Export specialization of an exported function template.
375 // MSC-DAG: define dllexport void @"\01??$exportedFuncTmpl@UExplicitSpec_Def_Exported@@@@YAXXZ"()
376 // GNU-DAG: define dllexport void @_Z16exportedFuncTmplI25ExplicitSpec_Def_ExportedEvv()
377 template<> __declspec(dllexport) void exportedFuncTmpl<ExplicitSpec_Def_Exported>() {}
378
379 // MSC-DAG: define weak_odr dllexport void @"\01??$exportedFuncTmpl@UExplicitSpec_InlineDef_Exported@@@@YAXXZ"()
380 // GNU-DAG: define weak_odr dllexport void @_Z16exportedFuncTmplI31ExplicitSpec_InlineDef_ExportedEvv()
381 template<> __declspec(dllexport) inline void exportedFuncTmpl<ExplicitSpec_InlineDef_Exported>() {}
382
383 // Not exporting specialization of an exported function template without
384 // explicit dllexport.
385 // MSC-DAG: define void @"\01??$exportedFuncTmpl@UExplicitSpec_NotExported@@@@YAXXZ"()
386 // GNU-DAG: define void @_Z16exportedFuncTmplI24ExplicitSpec_NotExportedEvv()
387 template<> void exportedFuncTmpl<ExplicitSpec_NotExported>() {}
388
389
390 // Export explicit instantiation declaration of a non-exported function template.
391 // MSC-DAG: define weak_odr dllexport void @"\01??$funcTmpl@UExplicitDecl_Exported@@@@YAXXZ"()
392 // GNU-DAG: define weak_odr dllexport void @_Z8funcTmplI21ExplicitDecl_ExportedEvv()
393 extern template __declspec(dllexport) void funcTmpl<ExplicitDecl_Exported>();
394        template __declspec(dllexport) void funcTmpl<ExplicitDecl_Exported>();
395
396 // Export explicit instantiation definition of a non-exported function template.
397 // MSC-DAG: define weak_odr dllexport void @"\01??$funcTmpl@UExplicitInst_Exported@@@@YAXXZ"()
398 // GNU-DAG: define weak_odr dllexport void @_Z8funcTmplI21ExplicitInst_ExportedEvv()
399 template __declspec(dllexport) void funcTmpl<ExplicitInst_Exported>();
400
401 // Export specialization of a non-exported function template.
402 // MSC-DAG: define dllexport void @"\01??$funcTmpl@UExplicitSpec_Def_Exported@@@@YAXXZ"()
403 // GNU-DAG: define dllexport void @_Z8funcTmplI25ExplicitSpec_Def_ExportedEvv()
404 template<> __declspec(dllexport) void funcTmpl<ExplicitSpec_Def_Exported>() {}
405
406 // MSC-DAG: define weak_odr dllexport void @"\01??$funcTmpl@UExplicitSpec_InlineDef_Exported@@@@YAXXZ"()
407 // GNU-DAG: define weak_odr dllexport void @_Z8funcTmplI31ExplicitSpec_InlineDef_ExportedEvv()
408 template<> __declspec(dllexport) inline void funcTmpl<ExplicitSpec_InlineDef_Exported>() {}
409
410
411
412 //===----------------------------------------------------------------------===//
413 // Precedence
414 //===----------------------------------------------------------------------===//
415
416 // dllexport takes precedence over the dllimport if both are specified.
417 // MSC-DAG: @"\01?PrecedenceGlobal1A@@3HA" = dllexport global i32 0, align 4
418 // MSC-DAG: @"\01?PrecedenceGlobal1B@@3HA" = dllexport global i32 0, align 4
419 // GNU-DAG: @PrecedenceGlobal1A            = dllexport global i32 0, align 4
420 // GNU-DAG: @PrecedenceGlobal1B            = dllexport global i32 0, align 4
421 __attribute__((dllimport, dllexport))       int PrecedenceGlobal1A; // dllimport ignored
422 __declspec(dllimport) __declspec(dllexport) int PrecedenceGlobal1B; // dllimport ignored
423
424 // MSC-DAG: @"\01?PrecedenceGlobal2A@@3HA" = dllexport global i32 0, align 4
425 // MSC-DAG: @"\01?PrecedenceGlobal2B@@3HA" = dllexport global i32 0, align 4
426 // GNU-DAG: @PrecedenceGlobal2A            = dllexport global i32 0, align 4
427 // GNU-DAG: @PrecedenceGlobal2B            = dllexport global i32 0, align 4
428 __attribute__((dllexport, dllimport))       int PrecedenceGlobal2A; // dllimport ignored
429 __declspec(dllexport) __declspec(dllimport) int PrecedenceGlobal2B; // dllimport ignored
430
431 // MSC-DAG: @"\01?PrecedenceGlobalRedecl1@@3HA" = dllexport global i32 0, align 4
432 // GNU-DAG: @PrecedenceGlobalRedecl1            = dllexport global i32 0, align 4
433 __declspec(dllexport) extern int PrecedenceGlobalRedecl1;
434 __declspec(dllimport)        int PrecedenceGlobalRedecl1 = 0;
435
436 // MSC-DAG: @"\01?PrecedenceGlobalRedecl2@@3HA" = dllexport global i32 0, align 4
437 // GNU-DAG: @PrecedenceGlobalRedecl2            = dllexport global i32 0, align 4
438 __declspec(dllimport) extern int PrecedenceGlobalRedecl2;
439 __declspec(dllexport)        int PrecedenceGlobalRedecl2;
440
441 // MSC-DAG: @"\01?PrecedenceGlobalMixed1@@3HA" = dllexport global i32 0, align 4
442 // GNU-DAG: @PrecedenceGlobalMixed1            = dllexport global i32 0, align 4
443 __attribute__((dllexport)) extern int PrecedenceGlobalMixed1;
444 __declspec(dllimport)             int PrecedenceGlobalMixed1 = 0;
445
446 // MSC-DAG: @"\01?PrecedenceGlobalMixed2@@3HA" = dllexport global i32 0, align 4
447 // GNU-DAG: @PrecedenceGlobalMixed2            = dllexport global i32 0, align 4
448 __attribute__((dllimport)) extern int PrecedenceGlobalMixed2;
449 __declspec(dllexport)             int PrecedenceGlobalMixed2;
450
451 // MSC-DAG: define dllexport void @"\01?precedence1A@@YAXXZ"
452 // MSC-DAG: define dllexport void @"\01?precedence1B@@YAXXZ"
453 // GNU-DAG: define dllexport void @_Z12precedence1Av()
454 // GNU-DAG: define dllexport void @_Z12precedence1Bv()
455 void __attribute__((dllimport, dllexport))       precedence1A() {}
456 void __declspec(dllimport) __declspec(dllexport) precedence1B() {}
457
458 // MSC-DAG: define dllexport void @"\01?precedence2A@@YAXXZ"
459 // MSC-DAG: define dllexport void @"\01?precedence2B@@YAXXZ"
460 // GNU-DAG: define dllexport void @_Z12precedence2Av()
461 // GNU-DAG: define dllexport void @_Z12precedence2Bv()
462 void __attribute__((dllexport, dllimport))       precedence2A() {}
463 void __declspec(dllexport) __declspec(dllimport) precedence2B() {}
464
465 // MSC-DAG: define dllexport void @"\01?precedenceRedecl1@@YAXXZ"
466 // GNU-DAG: define dllexport void @_Z17precedenceRedecl1v()
467 void __declspec(dllimport) precedenceRedecl1();
468 void __declspec(dllexport) precedenceRedecl1() {}
469
470 // MSC-DAG: define dllexport void @"\01?precedenceRedecl2@@YAXXZ"
471 // GNU-DAG: define dllexport void @_Z17precedenceRedecl2v()
472 void __declspec(dllexport) precedenceRedecl2();
473 void __declspec(dllimport) precedenceRedecl2() {}
474
475
476
477 //===----------------------------------------------------------------------===//
478 // Classes
479 //===----------------------------------------------------------------------===//
480
481 struct S {
482   void __declspec(dllexport) a() {}
483   // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?a@S@@QAEXXZ"
484
485   struct T {
486     void __declspec(dllexport) a() {}
487     // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?a@T@S@@QAEXXZ"
488   };
489 };
490
491 template <typename T>
492 struct SomeTemplate {
493   SomeTemplate(T o = T()) : o(o) {}
494   T o;
495 };
496 // MSVC2015-DAG: define weak_odr dllexport {{.+}} @"\01??4?$SomeTemplate@H@@Q{{.+}}@$$Q{{.+}}@@Z"
497 // MSVC2013-DAG: define weak_odr dllexport {{.+}} @"\01??4?$SomeTemplate@H@@Q{{.+}}0@A{{.+}}0@@Z"
498 struct __declspec(dllexport) InheritFromTemplate : SomeTemplate<int> {};
499
500 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??_F?$SomeTemplate@H@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
501
502 namespace PR23801 {
503 template <typename>
504 struct S {
505   ~S() {}
506 };
507 struct A {
508   A(int);
509   S<int> s;
510 };
511 struct __declspec(dllexport) B {
512   B(A = 0) {}
513 };
514
515 }
516 //
517 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??_FB@PR23801@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
518
519 struct __declspec(dllexport) T {
520   // Copy assignment operator:
521   // M32-DAG: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.T* @"\01??4T@@QAEAAU0@ABU0@@Z"
522
523   // Explicitly defaulted copy constructur:
524   T(const T&) = default;
525   // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.T* @"\01??0T@@QAE@ABU0@@Z"
526
527   void a() {}
528   // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?a@T@@QAEXXZ"
529
530   static int b;
531   // M32-DAG: @"\01?b@T@@2HA" = external global i32
532
533   static int c;
534   // M32-DAG: @"\01?c@T@@2HA" = dllexport global i32 0, align 4
535 };
536
537 USEVAR(T::b)
538 int T::c;
539
540 // Export template class with static member variable
541 // MSC-DAG: @"\01?StaticClassVarExpTmplClass@?$TmplClass@H@@2HA" = weak_odr dllexport global i32 0, comdat, align 4
542 // GNU-DAG: @_ZN9TmplClassIiE26StaticClassVarExpTmplClassE = weak_odr dllexport global i32 0, comdat, align 4
543 template<typename T>
544 struct __declspec(dllexport) TmplClass
545 {
546   static T StaticClassVarExpTmplClass;
547 };
548
549 template<typename T>
550 T TmplClass<T>::StaticClassVarExpTmplClass;
551
552 // Export a definition of a template function.
553 // MSC-DAG: define weak_odr dllexport i32 @"\01??$TypeFunTmpl@H@@YAHH@Z"
554 // GNU-DAG: define weak_odr dllexport i32 @_Z11TypeFunTmplIiET_S0_
555 template<typename T>
556 T __declspec(dllexport) TypeFunTmpl(T t) { return t + t; }
557
558 // Instantiate the exported template class and the exported template function.
559 int useExportedTmplStaticAndFun()
560 {
561   return TmplClass<int>::StaticClassVarExpTmplClass + TypeFunTmpl<int>(10);
562 }
563
564 template <typename T> struct __declspec(dllexport) U { void foo() {} };
565 struct __declspec(dllexport) V : public U<int> { };
566 // U<int>'s assignment operator is emitted.
567 // M32-DAG: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.U* @"\01??4?$U@H@@QAEAAU0@ABU0@@Z"
568
569 struct __declspec(dllexport) W { virtual void foo(); };
570 void W::foo() {}
571 // Default ctor:
572 // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.W* @"\01??0W@@QAE@XZ"
573 // Copy ctor:
574 // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.W* @"\01??0W@@QAE@ABU0@@Z"
575 // vftable:
576 // M32-DAG: [[W_VTABLE:@.*]] = private unnamed_addr constant { [2 x i8*] } { [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@")
577 // M32-DAG: @"\01??_7W@@6B@" = dllexport unnamed_addr alias i8*, getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* [[W_VTABLE]], i32 0, i32 0, i32 1)
578 // G32-DAG: @_ZTV1W = dllexport unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1W to i8*), i8* bitcast (void (%struct.W*)* @_ZN1W3fooEv to i8*)] }
579
580 struct __declspec(dllexport) X : public virtual W {};
581 // vbtable:
582 // M32-DAG: @"\01??_8X@@7B@" = weak_odr dllexport unnamed_addr constant [2 x i32] [i32 0, i32 4]
583
584 struct __declspec(dllexport) Y {
585   // Move assignment operator:
586   // MSVC2015-DAG: define weak_odr dllexport {{.+}} @"\01??4Y@@Q{{.+}}@$$Q{{.+}}@@Z"
587   // MSVC2013-DAG: define weak_odr dllexport {{.+}} @"\01??4Y@@Q{{.+}}0@A{{.+}}0@@Z"
588
589   int x;
590 };
591
592 struct __declspec(dllexport) Z { virtual ~Z() {} };
593 // The scalar deleting dtor does not get exported:
594 // M32-DAG: define linkonce_odr x86_thiscallcc i8* @"\01??_GZ@@UAEPAXI@Z"
595
596
597 // The user-defined dtor does get exported:
598 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??1Z@@UAE@XZ"
599
600 namespace UseDtorAlias {
601   struct __declspec(dllexport) A { ~A(); };
602   struct __declspec(dllexport) B : A { ~B(); };
603   A::~A() { }
604   B::~B() { }
605   // Emit a alias definition of B's constructor.
606   // M32-DAG: @"\01??1B@UseDtorAlias@@QAE@XZ" = dllexport alias {{.*}} @"\01??1A@UseDtorAlias@@QAE@XZ"
607 }
608
609 struct __declspec(dllexport) DefaultedCtorsDtors {
610   DefaultedCtorsDtors() = default;
611   // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.DefaultedCtorsDtors* @"\01??0DefaultedCtorsDtors@@QAE@XZ"
612   ~DefaultedCtorsDtors() = default;
613   // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??1DefaultedCtorsDtors@@QAE@XZ"
614 };
615
616 // Export defaulted member function definitions declared inside class.
617 struct __declspec(dllexport) ExportDefaultedInclassDefs {
618   ExportDefaultedInclassDefs() = default;
619   // M32VS2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
620   // M64VS2013-DAG: define weak_odr dllexport                %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
621   // M32VS2015-NOT: define weak_odr dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
622   // M64VS2015-NOT: define weak_odr dllexport                %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
623
624   ~ExportDefaultedInclassDefs() = default;
625   // M32VS2013-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??1ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* %this)
626   // M64VS2013-DAG: define weak_odr dllexport                void @"\01??1ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* %this)
627   // M32VS2015-NOT: define weak_odr dllexport x86_thiscallcc void @"\01??1ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* %this)
628   // M64VS2015-NOT: define weak_odr dllexport                void @"\01??1ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* %this)
629
630   ExportDefaultedInclassDefs(const ExportDefaultedInclassDefs&) = default;
631   // M32VS2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QAE@ABU0@@Z"(%struct.ExportDefaultedInclassDefs* returned %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
632   // M64VS2013-DAG: define weak_odr dllexport                %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QEAA@AEBU0@@Z"(%struct.ExportDefaultedInclassDefs* returned %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
633   // M32VS2015-NOT: define weak_odr dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QAE@ABU0@@Z"(%struct.ExportDefaultedInclassDefs* returned %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
634   // M64VS2015-NOT: define weak_odr dllexport                %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QEAA@AEBU0@@Z"(%struct.ExportDefaultedInclassDefs* returned %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
635
636   ExportDefaultedInclassDefs& operator=(const ExportDefaultedInclassDefs&) = default;
637   // M32-DAG: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.ExportDefaultedInclassDefs* @"\01??4ExportDefaultedInclassDefs@@QAEAAU0@ABU0@@Z"(%struct.ExportDefaultedInclassDefs* %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
638   // M64-DAG: define weak_odr dllexport                dereferenceable({{[0-9]+}}) %struct.ExportDefaultedInclassDefs* @"\01??4ExportDefaultedInclassDefs@@QEAAAEAU0@AEBU0@@Z"(%struct.ExportDefaultedInclassDefs* %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
639 };
640
641 namespace ReferencedInlineMethodInNestedClass {
642   struct __declspec(dllexport) S {
643     void foo() {
644       t->bar();
645     }
646     struct T {
647       void bar() {}
648     };
649     T *t;
650   };
651   // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?foo@S@ReferencedInlineMethodInNestedClass@@QAEXXZ"
652   // M32-DAG: define linkonce_odr x86_thiscallcc void @"\01?bar@T@S@ReferencedInlineMethodInNestedClass@@QAEXXZ"
653 }
654
655 // MS ignores DLL attributes on partial specializations.
656 template <typename T> struct PartiallySpecializedClassTemplate {};
657 template <typename T> struct __declspec(dllexport) PartiallySpecializedClassTemplate<T*> { void f(); };
658 template <typename T> void PartiallySpecializedClassTemplate<T*>::f() {}
659 USEMEMFUNC(PartiallySpecializedClassTemplate<void*>, f);
660 // M32-DAG: define linkonce_odr x86_thiscallcc void @"\01?f@?$PartiallySpecializedClassTemplate@PAX@@QAEXXZ"
661 // G32-DAG: define weak_odr dllexport x86_thiscallcc void @_ZN33PartiallySpecializedClassTemplateIPvE1fEv
662
663 // Attributes on explicit specializations are honored.
664 template <typename T> struct ExplicitlySpecializedClassTemplate {};
665 template <> struct __declspec(dllexport) ExplicitlySpecializedClassTemplate<void*> { void f(); };
666 void ExplicitlySpecializedClassTemplate<void*>::f() {}
667 USEMEMFUNC(ExplicitlySpecializedClassTemplate<void*>, f);
668 // M32-DAG: define dllexport x86_thiscallcc void @"\01?f@?$ExplicitlySpecializedClassTemplate@PAX@@QAEXXZ"
669 // G32-DAG: define dllexport x86_thiscallcc void @_ZN34ExplicitlySpecializedClassTemplateIPvE1fEv
670
671 // MS inherits DLL attributes to partial specializations.
672 template <typename T> struct __declspec(dllexport) PartiallySpecializedExportedClassTemplate {};
673 template <typename T> struct PartiallySpecializedExportedClassTemplate<T*> { void f() {} };
674 USEMEMFUNC(PartiallySpecializedExportedClassTemplate<void*>, f);
675 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$PartiallySpecializedExportedClassTemplate@PAX@@QAEXXZ"
676 // G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN41PartiallySpecializedExportedClassTemplateIPvE1fEv
677
678 // MS ignores DLL attributes on partial specializations; inheritance still works though.
679 template <typename T> struct __declspec(dllexport) PartiallySpecializedExportedClassTemplate2 {};
680 template <typename T> struct __declspec(dllimport) PartiallySpecializedExportedClassTemplate2<T*> { void f(); };
681 template <typename T> void PartiallySpecializedExportedClassTemplate2<T*>::f() {}
682 USEMEMFUNC(PartiallySpecializedExportedClassTemplate2<void*>, f);
683 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$PartiallySpecializedExportedClassTemplate2@PAX@@QAEXXZ"
684 // G32-DAG: declare dllimport x86_thiscallcc void @_ZN42PartiallySpecializedExportedClassTemplate2IPvE1fEv
685
686 // Attributes on the instantiation take precedence over attributes on the template.
687 template <typename T> struct __declspec(dllimport) ExplicitlyInstantiatedWithDifferentAttr { void f() {} };
688 template struct __declspec(dllexport) ExplicitlyInstantiatedWithDifferentAttr<int>;
689 USEMEMFUNC(ExplicitlyInstantiatedWithDifferentAttr<int>, f);
690 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ExplicitlyInstantiatedWithDifferentAttr@H@@QAEXXZ"
691
692 // Don't create weak dllexport aliases. (PR21373)
693 struct NonExportedBaseClass {
694   virtual ~NonExportedBaseClass();
695 };
696 NonExportedBaseClass::~NonExportedBaseClass() {}
697
698 struct __declspec(dllexport) ExportedDerivedClass : NonExportedBaseClass {};
699 // M32-DAG: weak_odr dllexport x86_thiscallcc void @"\01??1ExportedDerivedClass@@UAE@XZ"
700
701 // Do not assert about generating code for constexpr functions twice during explicit instantiation (PR21718).
702 template <typename T> struct ExplicitInstConstexprMembers {
703   // Copy assignment operator
704   // M32-DAG: define weak_odr dllexport x86_thiscallcc dereferenceable(1) %struct.ExplicitInstConstexprMembers* @"\01??4?$ExplicitInstConstexprMembers@X@@QAEAAU0@ABU0@@Z"
705
706   constexpr ExplicitInstConstexprMembers() {}
707   // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.ExplicitInstConstexprMembers* @"\01??0?$ExplicitInstConstexprMembers@X@@QAE@XZ"
708
709   ExplicitInstConstexprMembers(const ExplicitInstConstexprMembers&) = default;
710   // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.ExplicitInstConstexprMembers* @"\01??0?$ExplicitInstConstexprMembers@X@@QAE@ABU0@@Z"
711
712   constexpr int f() const { return 42; }
713   // M32-DAG: define weak_odr dllexport x86_thiscallcc i32 @"\01?f@?$ExplicitInstConstexprMembers@X@@QBEHXZ"
714 };
715 template struct __declspec(dllexport) ExplicitInstConstexprMembers<void>;
716
717 template <typename T> struct ExplicitInstantiationDeclTemplate { void f() {} };
718 extern template struct __declspec(dllexport) ExplicitInstantiationDeclTemplate<int>;
719 USEMEMFUNC(ExplicitInstantiationDeclTemplate<int>, f);
720 // M32-DAG: {{declare|define available_externally}} x86_thiscallcc void @"\01?f@?$ExplicitInstantiationDeclTemplate@H@@QAEXXZ"
721
722 template <typename T> struct __declspec(dllexport) ExplicitInstantiationDeclExportedTemplate { void f() {} };
723 extern template struct ExplicitInstantiationDeclExportedTemplate<int>;
724 USEMEMFUNC(ExplicitInstantiationDeclExportedTemplate<int>, f);
725 // M32-DAG: {{declare|define available_externally}} x86_thiscallcc void @"\01?f@?$ExplicitInstantiationDeclExportedTemplate@H@@QAEXXZ"
726
727 template <typename T> struct ExplicitInstantiationDeclExportedDefTemplate { void f() {} ExplicitInstantiationDeclExportedDefTemplate() {} };
728 extern template struct ExplicitInstantiationDeclExportedDefTemplate<int>;
729 template struct __declspec(dllexport) ExplicitInstantiationDeclExportedDefTemplate<int>;
730 USEMEMFUNC(ExplicitInstantiationDeclExportedDefTemplate<int>, f);
731 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ExplicitInstantiationDeclExportedDefTemplate@H@@QAEXXZ"
732 // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.ExplicitInstantiationDeclExportedDefTemplate* @"\01??0?$ExplicitInstantiationDeclExportedDefTemplate@H@@QAE@XZ"
733 // G32-DAG: define weak_odr x86_thiscallcc void @_ZN44ExplicitInstantiationDeclExportedDefTemplateIiE1fEv
734
735 template <typename T> struct ImplicitInstantiationExportedExplicitInstantiationDefTemplate { virtual void f() {} };
736 ImplicitInstantiationExportedExplicitInstantiationDefTemplate<int> ImplicitInstantiationExportedExplicitInstantiationDefTemplateInstance;
737 template struct __declspec(dllexport) ImplicitInstantiationExportedExplicitInstantiationDefTemplate<int>;
738 USEMEMFUNC(ImplicitInstantiationExportedExplicitInstantiationDefTemplate<int>, f);
739 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ImplicitInstantiationExportedExplicitInstantiationDefTemplate@H@@UAEXXZ"
740 // G32-DAG: define weak_odr x86_thiscallcc void @_ZN61ImplicitInstantiationExportedExplicitInstantiationDefTemplateIiE1fEv
741
742 template <typename T> struct __declspec(dllexport) ImplicitInstantiationExplicitInstantiationDefExportedTemplate { virtual void f() {} };
743 ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int> ImplicitInstantiationExplicitInstantiationDefExportedTemplateInstance;
744 template struct ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int>;
745 USEMEMFUNC(ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int>, f);
746 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ImplicitInstantiationExplicitInstantiationDefExportedTemplate@H@@UAEXXZ"
747 // G32-DAG: define weak_odr x86_thiscallcc void @_ZN61ImplicitInstantiationExplicitInstantiationDefExportedTemplateIiE1fEv
748
749 template <typename T> struct __declspec(dllexport) ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate { virtual void f() {} };
750 ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate<int> ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplateInstance;
751 template struct __declspec(dllexport) ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate<int>;
752 USEMEMFUNC(ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate<int>, f);
753 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate@H@@UAEXXZ"
754 // G32-DAG: define weak_odr x86_thiscallcc void @_ZN69ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplateIiE1fEv
755
756 namespace { struct InternalLinkageType {}; }
757 struct __declspec(dllexport) PR23308 {
758   void f(InternalLinkageType*);
759 };
760 void PR23308::f(InternalLinkageType*) {}
761 long use(PR23308* p) { p->f(nullptr); }
762 // M32-DAG: define internal x86_thiscallcc void @"\01?f@PR23308@@QAEXPAUInternalLinkageType@?A@@@Z"
763
764 template <typename T> struct PR23770BaseTemplate { void f() {} };
765 template <typename T> struct PR23770DerivedTemplate : PR23770BaseTemplate<int> {};
766 extern template struct PR23770DerivedTemplate<int>;
767 template struct __declspec(dllexport) PR23770DerivedTemplate<int>;
768 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$PR23770BaseTemplate@H@@QAEXXZ"
769
770 namespace InClassInits {
771
772 struct __declspec(dllexport) S {
773   int x = 42;
774 };
775 // M32-DAG: define weak_odr dllexport x86_thiscallcc %"struct.InClassInits::S"* @"\01??0S@InClassInits@@QAE@XZ"
776
777 // dllexport an already instantiated class template.
778 template <typename T> struct Base {
779   int x = 42;
780 };
781 Base<int> base;
782 struct __declspec(dllexport) T : Base<int> { };
783 // M32-DAG: define weak_odr dllexport x86_thiscallcc %"struct.InClassInits::Base"* @"\01??0?$Base@H@InClassInits@@QAE@XZ"
784
785 struct A { A(int); };
786 struct __declspec(dllexport) U {
787   // Class with both default constructor closure and in-class initializer.
788   U(A = 0) {}
789   int x = 0;
790 };
791 // M32-DAG: define weak_odr dllexport x86_thiscallcc %"struct.InClassInits::U"* @"\01??0U@InClassInits@@QAE@UA@1@@Z"
792
793 struct Evil {
794   template <typename T> struct Base {
795     int x = 0;
796   };
797   struct S : Base<int> {};
798   // The already instantiated Base<int> becomes dllexported below, but the
799   // in-class initializer for Base<>::x still hasn't been parsed, so emitting
800   // the default ctor must still be delayed.
801   struct __declspec(dllexport) T : Base<int> {};
802 };
803 // M32-DAG: define weak_odr dllexport x86_thiscallcc %"struct.InClassInits::Evil::Base"* @"\01??0?$Base@H@Evil@InClassInits@@QAE@XZ"
804
805 template <typename T> struct Foo {};
806 template <typename T> struct Bar {
807   Bar<T> &operator=(Foo<T>) {}
808 };
809 struct __declspec(dllexport) Baz {
810   Bar<int> n;
811 };
812 // After parsing Baz, in ActOnFinishCXXNonNestedClass we would synthesize
813 // Baz's operator=, causing instantiation of Foo<int> after which
814 // ActOnFinishCXXNonNestedClass is called, and we would bite our own tail.
815 // M32-DAG: define weak_odr dllexport x86_thiscallcc dereferenceable(1) %"struct.InClassInits::Baz"* @"\01??4Baz@InClassInits@@QAEAAU01@ABU01@@Z"
816 }
817
818 // We had an issue where instantiating A would force emission of B's delayed
819 // exported methods.
820 namespace pr26490 {
821 template <typename T> struct A { };
822 struct __declspec(dllexport) B {
823   B(int = 0) {}
824   A<int> m_fn1() {}
825 };
826 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??_FB@pr26490@@QAEXXZ"
827 }
828
829 // dllexport trumps dllexport on an explicit instantiation.
830 template <typename T> struct ExplicitInstantiationTwoAttributes { void f() {} };
831 template struct __declspec(dllexport) __declspec(dllimport) ExplicitInstantiationTwoAttributes<int>;
832 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ExplicitInstantiationTwoAttributes@H@@QAEXXZ"
833
834
835 //===----------------------------------------------------------------------===//
836 // Classes with template base classes
837 //===----------------------------------------------------------------------===//
838
839 template <typename T> struct ClassTemplate { void func(); };
840 template <typename T> void ClassTemplate<T>::func() {}
841 template <typename T> struct __declspec(dllexport) ExportedClassTemplate { void func(); };
842 template <typename T> void ExportedClassTemplate<T>::func() {}
843 template <typename T> struct __declspec(dllimport) ImportedClassTemplate { void func(); };
844 template <typename T> void ImportedClassTemplate<T>::func() {}
845
846 template <typename T> struct ExplicitlySpecializedTemplate { void func() {} };
847 template <> struct ExplicitlySpecializedTemplate<int> { void func(); };
848 void ExplicitlySpecializedTemplate<int>::func() {}
849 template <typename T> struct ExplicitlyExportSpecializedTemplate { void func() {} };
850 template <> struct __declspec(dllexport) ExplicitlyExportSpecializedTemplate<int> { void func(); };
851 void ExplicitlyExportSpecializedTemplate<int>::func() {}
852 template <typename T> struct ExplicitlyImportSpecializedTemplate { void func(); };
853 template <> struct __declspec(dllimport) ExplicitlyImportSpecializedTemplate<int> { void func(); };
854
855 template <typename T> struct ExplicitlyInstantiatedTemplate { void func(); };
856 template <typename T> void ExplicitlyInstantiatedTemplate<T>::func() {}
857 template struct ExplicitlyInstantiatedTemplate<int>;
858 template <typename T> struct ExplicitlyExportInstantiatedTemplate { void func(); };
859 template <typename T> void ExplicitlyExportInstantiatedTemplate<T>::func() {}
860 template struct __declspec(dllexport) ExplicitlyExportInstantiatedTemplate<int>;
861 template <typename T> struct ExplicitlyImportInstantiatedTemplate { void func(); };
862 template struct __declspec(dllimport) ExplicitlyImportInstantiatedTemplate<int>;
863
864
865 // MS: ClassTemplate<int> gets exported.
866 struct __declspec(dllexport) DerivedFromTemplate : public ClassTemplate<int> {};
867 USEMEMFUNC(DerivedFromTemplate, func)
868 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$ClassTemplate@H@@QAEXXZ"
869 // G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN13ClassTemplateIiE4funcEv
870
871 // ExportedTemplate is explicitly exported.
872 struct __declspec(dllexport) DerivedFromExportedTemplate : public ExportedClassTemplate<int> {};
873 USEMEMFUNC(DerivedFromExportedTemplate, func)
874 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$ExportedClassTemplate@H@@QAEXXZ"
875 // G32-DAG: define weak_odr dllexport x86_thiscallcc void @_ZN21ExportedClassTemplateIiE4funcEv
876
877 // ImportedClassTemplate is explicitly imported.
878 struct __declspec(dllexport) DerivedFromImportedTemplate : public ImportedClassTemplate<int> {};
879 USEMEMFUNC(DerivedFromImportedTemplate, func)
880 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"\01?func@?$ImportedClassTemplate@H@@QAEXXZ"
881 // G32-DAG: declare dllimport x86_thiscallcc void @_ZN21ImportedClassTemplateIiE4funcEv
882
883 // Base class already implicitly instantiated without dll attribute.
884 struct DerivedFromTemplateD : public ClassTemplate<double> {};
885 struct __declspec(dllexport) DerivedFromTemplateD2 : public ClassTemplate<double> {};
886 USEMEMFUNC(DerivedFromTemplateD2, func)
887 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$ClassTemplate@N@@QAEXXZ"
888 // G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN13ClassTemplateIdE4funcEv
889
890 // MS: Base class already instantiated with different dll attribute.
891 struct __declspec(dllimport) DerivedFromTemplateB : public ClassTemplate<bool> {};
892 struct __declspec(dllexport) DerivedFromTemplateB2 : public ClassTemplate<bool> {};
893 USEMEMFUNC(DerivedFromTemplateB2, func)
894 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"\01?func@?$ClassTemplate@_N@@QAEXXZ"
895 // G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN13ClassTemplateIbE4funcEv
896
897 // Base class already specialized without dll attribute.
898 struct __declspec(dllexport) DerivedFromExplicitlySpecializedTemplate : public ExplicitlySpecializedTemplate<int> {};
899 USEMEMFUNC(DerivedFromExplicitlySpecializedTemplate, func)
900 // M32-DAG: define x86_thiscallcc void @"\01?func@?$ExplicitlySpecializedTemplate@H@@QAEXXZ"
901 // G32-DAG: define x86_thiscallcc void @_ZN29ExplicitlySpecializedTemplateIiE4funcEv
902
903 // Base class alredy specialized with export attribute.
904 struct __declspec(dllexport) DerivedFromExplicitlyExportSpecializedTemplate : public ExplicitlyExportSpecializedTemplate<int> {};
905 USEMEMFUNC(DerivedFromExplicitlyExportSpecializedTemplate, func)
906 // M32-DAG: define dllexport x86_thiscallcc void @"\01?func@?$ExplicitlyExportSpecializedTemplate@H@@QAEXXZ"
907 // G32-DAG: define dllexport x86_thiscallcc void @_ZN35ExplicitlyExportSpecializedTemplateIiE4funcEv
908
909 // Base class already specialized with import attribute.
910 struct __declspec(dllexport) DerivedFromExplicitlyImportSpecializedTemplate : public ExplicitlyImportSpecializedTemplate<int> {};
911 USEMEMFUNC(DerivedFromExplicitlyImportSpecializedTemplate, func)
912 // M32-DAG: declare dllimport x86_thiscallcc void @"\01?func@?$ExplicitlyImportSpecializedTemplate@H@@QAEXXZ"
913 // G32-DAG: declare dllimport x86_thiscallcc void @_ZN35ExplicitlyImportSpecializedTemplateIiE4funcEv
914
915 // Base class already instantiated without dll attribute.
916 struct __declspec(dllexport) DerivedFromExplicitlyInstantiatedTemplate : public ExplicitlyInstantiatedTemplate<int> {};
917 USEMEMFUNC(DerivedFromExplicitlyInstantiatedTemplate, func)
918 // M32-DAG: define weak_odr x86_thiscallcc void @"\01?func@?$ExplicitlyInstantiatedTemplate@H@@QAEXXZ"
919 // G32-DAG: define weak_odr x86_thiscallcc void @_ZN30ExplicitlyInstantiatedTemplateIiE4funcEv
920
921 // Base class already instantiated with export attribute.
922 struct __declspec(dllexport) DerivedFromExplicitlyExportInstantiatedTemplate : public ExplicitlyExportInstantiatedTemplate<int> {};
923 USEMEMFUNC(DerivedFromExplicitlyExportInstantiatedTemplate, func)
924 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$ExplicitlyExportInstantiatedTemplate@H@@QAEXXZ"
925 // G32-DAG: define weak_odr dllexport x86_thiscallcc void @_ZN36ExplicitlyExportInstantiatedTemplateIiE4funcEv
926
927 // Base class already instantiated with import attribute.
928 struct __declspec(dllexport) DerivedFromExplicitlyImportInstantiatedTemplate : public ExplicitlyImportInstantiatedTemplate<int> {};
929 USEMEMFUNC(DerivedFromExplicitlyImportInstantiatedTemplate, func)
930 // M32-DAG: declare dllimport x86_thiscallcc void @"\01?func@?$ExplicitlyImportInstantiatedTemplate@H@@QAEXXZ"
931 // G32-DAG: declare dllimport x86_thiscallcc void @_ZN36ExplicitlyImportInstantiatedTemplateIiE4funcEv
932
933 // MS: A dll attribute propagates through multiple levels of instantiation.
934 template <typename T> struct TopClass { void func() {} };
935 template <typename T> struct MiddleClass : public TopClass<T> { };
936 struct __declspec(dllexport) BottomClass : public MiddleClass<int> { };
937 USEMEMFUNC(BottomClass, func)
938 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$TopClass@H@@QAEXXZ"
939 // G32-DAG: define linkonce_odr x86_thiscallcc void @_ZN8TopClassIiE4funcEv
940
941 template <typename T> struct ExplicitInstantiationDeclTemplateBase { void func() {} };
942 extern template struct ExplicitInstantiationDeclTemplateBase<int>;
943 struct __declspec(dllexport) DerivedFromExplicitInstantiationDeclTemplateBase : public ExplicitInstantiationDeclTemplateBase<int> {};
944 template struct ExplicitInstantiationDeclTemplateBase<int>;
945 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?func@?$ExplicitInstantiationDeclTemplateBase@H@@QAEXXZ"
946 // G32-DAG: define weak_odr x86_thiscallcc void @_ZN37ExplicitInstantiationDeclTemplateBaseIiE4funcEv
947
948 // PR26076
949 struct LayerSelectionBound;
950 template <typename> struct Selection {};
951 typedef Selection<LayerSelectionBound> LayerSelection;
952 struct LayerImpl;
953 struct __declspec(dllexport) LayerTreeImpl {
954   struct __declspec(dllexport) ElementLayers {
955     LayerImpl *main = nullptr;
956   };
957   LayerSelection foo;
958 };
959 // M32-DAG: define weak_odr dllexport x86_thiscallcc %"struct.LayerTreeImpl::ElementLayers"* @"\01??0ElementLayers@LayerTreeImpl@@QAE@XZ"
960 // M64-DAG: define weak_odr dllexport %"struct.LayerTreeImpl::ElementLayers"* @"\01??0ElementLayers@LayerTreeImpl@@QEAA@XZ"
961
962 class __declspec(dllexport) ACE_Shared_Object {
963 public:
964   virtual ~ACE_Shared_Object();
965 };
966 class __declspec(dllexport) ACE_Service_Object : public ACE_Shared_Object {};
967 // Implicit move constructor declaration.
968 // MSVC2015-DAG: define weak_odr dllexport {{.+}}ACE_Service_Object@@Q{{.+}}@$$Q
969 // The declarations should not be exported.
970 // MSVC2013-NOT: define weak_odr dllexport {{.+}}ACE_Service_Object@@Q{{.+}}@$$Q