Debian Codegraph @

clang/test/CodeGenCXX/dllimport.cpp

raw
1 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-msvc -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -DMSABI -w | FileCheck --check-prefix=MSC --check-prefix=M32 %s
2 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-windows-msvc -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -DMSABI -w | FileCheck --check-prefix=MSC --check-prefix=M64 %s
3 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-gnu -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G32 %s
4 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-windows-gnu -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU %s
5 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-pc-cygwin -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=C32 %s
6 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-pc-cygwin -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU %s
7 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-msvc -fno-rtti -fno-threadsafe-statics -fms-extensions -fms-compatibility-version=18.00 -emit-llvm -std=c++1y -O1 -disable-llvm-passes -o - %s -DMSABI -w | FileCheck --check-prefix=MO1 --check-prefix=M18 %s
8 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-msvc -fno-rtti -fno-threadsafe-statics -fms-extensions -fms-compatibility-version=19.00 -emit-llvm -std=c++1y -O1 -disable-llvm-passes -o - %s -DMSABI -w | FileCheck --check-prefix=MO1 --check-prefix=M19 %s
9 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-gnu -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O1 -disable-llvm-passes -o - %s -w | FileCheck --check-prefix=GO1 %s
10 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-scei-ps4 -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=PS %s
11 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple x86_64-sie-ps5 -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=PS %s
12
13 // CHECK-NOT doesn't play nice with CHECK-DAG, so use separate run lines.
14 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-msvc -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -DMSABI -w | FileCheck --check-prefix=MSC2 %s
15 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-windows-gnu -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU2 %s
16 // RUN: %clang_cc1 -no-enable-noundef-analysis -triple i686-pc-cygwin -fno-rtti -fno-threadsafe-statics -fms-extensions -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU2 %s
17
18 // Helper structs to make templates more expressive.
19 struct ImplicitInst_Imported {};
20 struct ImplicitInst_NotImported {};
21 struct ExplicitDecl_Imported {};
22 struct ExplicitInst_Imported {};
23 struct ExplicitSpec_Imported {};
24 struct ExplicitSpec_Def_Imported {};
25 struct ExplicitSpec_InlineDef_Imported {};
26 struct ExplicitSpec_NotImported {};
27
28 #define JOIN2(x, y) x##y
29 #define JOIN(x, y) JOIN2(x, y)
30 #define UNIQ(name) JOIN(name, __LINE__)
31 #define USEVARTYPE(type, var) type UNIQ(use)() { return var; }
32 #define USEVAR(var) USEVARTYPE(int, var)
33 #define USE(func) void UNIQ(use)() { func(); }
34 #define USE1(func) void UNIQ(use)() { func(nullptr); }
35 #define USEMEMFUNC(class, func) void (class::*UNIQ(use)())() { return &class::func; }
36 #define USESTATICMEMFUNC(class, func) void (*UNIQ(use)())() { return &class::func; }
37 #define USECLASS(class) void UNIQ(USE)() { class x; }
38 #define USECOPYASSIGN(class) class& (class::*UNIQ(use)())(const class&) { return &class::operator=; }
39 #define USEMOVEASSIGN(class) class& (class::*UNIQ(use)())(class&&) { return &class::operator=; }
40
41 //===----------------------------------------------------------------------===//
42 // Globals
43 //===----------------------------------------------------------------------===//
44
45 // Import declaration.
46 // MSC-DAG: @"?ExternGlobalDecl@@3HA" = external dllimport global i32
47 // GNU-DAG: @ExternGlobalDecl = external dllimport global i32
48 __declspec(dllimport) extern int ExternGlobalDecl;
49 USEVAR(ExternGlobalDecl)
50
51 // dllimport implies a declaration.
52 // MSC-DAG: @"?GlobalDecl@@3HA" = external dllimport global i32
53 // GNU-DAG: @GlobalDecl = external dllimport global i32
54 __declspec(dllimport) int GlobalDecl;
55 USEVAR(GlobalDecl)
56
57 // Redeclarations
58 // MSC-DAG: @"?GlobalRedecl1@@3HA" = external dllimport global i32
59 // GNU-DAG: @GlobalRedecl1 = external dllimport global i32
60 __declspec(dllimport) extern int GlobalRedecl1;
61 __declspec(dllimport) extern int GlobalRedecl1;
62 USEVAR(GlobalRedecl1)
63
64 // MSC-DAG: @"?GlobalRedecl2a@@3HA" = external dllimport global i32
65 // GNU-DAG: @GlobalRedecl2a = external dllimport global i32
66 __declspec(dllimport) int GlobalRedecl2a;
67 __declspec(dllimport) int GlobalRedecl2a;
68 USEVAR(GlobalRedecl2a)
69
70 // M32-DAG: @"?GlobalRedecl2b@@3PAHA" = external dllimport global ptr
71 // M64-DAG: @"?GlobalRedecl2b@@3PEAHEA" = external dllimport global ptr
72 // GNU-DAG: @GlobalRedecl2b = external dllimport global ptr
73 int *__attribute__((dllimport)) GlobalRedecl2b;
74 int *__attribute__((dllimport)) GlobalRedecl2b;
75 USEVARTYPE(int*, GlobalRedecl2b)
76
77 // MSC-DAG: @"?GlobalRedecl2c@@3HA" = external dllimport global i32
78 // GNU-DAG: @GlobalRedecl2c = external dllimport global i32
79 int GlobalRedecl2c __attribute__((dllimport));
80 int GlobalRedecl2c __attribute__((dllimport));
81 USEVAR(GlobalRedecl2c)
82
83 // NB: MSC issues a warning and makes GlobalRedecl3 dllexport. We follow GCC
84 // and drop the dllimport with a warning.
85 // MSC-DAG: @"?GlobalRedecl3@@3HA" = external dso_local global i32
86 // GNU-DAG: @GlobalRedecl3 = external global i32
87 __declspec(dllimport) extern int GlobalRedecl3;
88 extern int GlobalRedecl3; // dllimport ignored
89 USEVAR(GlobalRedecl3)
90
91 // MSC-DAG: @"?ExternalGlobal@ns@@3HA" = external dllimport global i32
92 // GNU-DAG: @_ZN2ns14ExternalGlobalE = external dllimport global i32
93 namespace ns { __declspec(dllimport) int ExternalGlobal; }
94 USEVAR(ns::ExternalGlobal)
95
96 int __declspec(dllimport) f();
97 // MO1-DAG: @"?x@?1??inlineStaticLocalsFunc@@YAHXZ@4HA" = available_externally dllimport global i32 0
98 // MO1-DAG: @"??_B?1??inlineStaticLocalsFunc@@YAHXZ@51" = available_externally dllimport global i32 0
99 inline int __declspec(dllimport) inlineStaticLocalsFunc() {
100 static int x = f();
101 return x++;
102 };
103 USE(inlineStaticLocalsFunc);
104
105 // The address of a dllimport global cannot be used in constant initialization.
106 // M32-DAG: @"?arr@?1??initializationFunc@@YAPAHXZ@4QBQAHB" = internal global [1 x ptr] zeroinitializer
107 // GNU-DAG: @_ZZ18initializationFuncvE3arr = internal global [1 x ptr] zeroinitializer
108 int *initializationFunc() {
109 static int *const arr[] = {&ExternGlobalDecl};
110 return arr[0];
111 }
112 USE(initializationFunc);
113
114
115 //===----------------------------------------------------------------------===//
116 // Variable templates
117 //===----------------------------------------------------------------------===//
118
119 // Import declaration.
120 // MSC-DAG: @"??$ExternVarTmplDecl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
121 // GNU-DAG: @_Z17ExternVarTmplDeclI21ImplicitInst_ImportedE = external dllimport global i32
122 template<typename T> __declspec(dllimport) extern int ExternVarTmplDecl;
123 USEVAR(ExternVarTmplDecl<ImplicitInst_Imported>)
124
125 // dllimport implies a declaration.
126 // MSC-DAG: @"??$VarTmplDecl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
127 // GNU-DAG: @_Z11VarTmplDeclI21ImplicitInst_ImportedE = external dllimport global i32
128 template<typename T> __declspec(dllimport) int VarTmplDecl;
129 USEVAR(VarTmplDecl<ImplicitInst_Imported>)
130
131 // Redeclarations
132 // MSC-DAG: @"??$VarTmplRedecl1@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
133 // GNU-DAG: @_Z14VarTmplRedecl1I21ImplicitInst_ImportedE = external dllimport global i32
134 template<typename T> __declspec(dllimport) extern int VarTmplRedecl1;
135 template<typename T> __declspec(dllimport) extern int VarTmplRedecl1;
136 USEVAR(VarTmplRedecl1<ImplicitInst_Imported>)
137
138 // MSC-DAG: @"??$VarTmplRedecl2@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
139 // GNU-DAG: @_Z14VarTmplRedecl2I21ImplicitInst_ImportedE = external dllimport global i32
140 template<typename T> __declspec(dllimport) int VarTmplRedecl2;
141 template<typename T> __declspec(dllimport) int VarTmplRedecl2;
142 USEVAR(VarTmplRedecl2<ImplicitInst_Imported>)
143
144 // MSC-DAG: @"??$VarTmplRedecl3@UImplicitInst_Imported@@@@3HA" = external dso_local global i32
145 // GNU-DAG: @_Z14VarTmplRedecl3I21ImplicitInst_ImportedE = external global i32
146 template<typename T> __declspec(dllimport) extern int VarTmplRedecl3;
147 template<typename T> extern int VarTmplRedecl3; // dllimport ignored
148 USEVAR(VarTmplRedecl3<ImplicitInst_Imported>)
149
150
151 // MSC-DAG: @"??$ExternalVarTmpl@UImplicitInst_Imported@@@ns@@3HA" = external dllimport global i32
152 // GNU-DAG: @_ZN2ns15ExternalVarTmplI21ImplicitInst_ImportedEE = external dllimport global i32
153 namespace ns { template<typename T> __declspec(dllimport) int ExternalVarTmpl; }
154 USEVAR(ns::ExternalVarTmpl<ImplicitInst_Imported>)
155
156
157 template<typename T> int VarTmpl;
158 template<typename T> __declspec(dllimport) int ImportedVarTmpl;
159
160 // Import implicit instantiation of an imported variable template.
161 // MSC-DAG: @"??$ImportedVarTmpl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32
162 // GNU-DAG: @_Z15ImportedVarTmplI21ImplicitInst_ImportedE = external dllimport global i32
163 USEVAR(ImportedVarTmpl<ImplicitInst_Imported>)
164
165 // Import explicit instantiation declaration of an imported variable template.
166 // MSC-DAG: @"??$ImportedVarTmpl@UExplicitDecl_Imported@@@@3HA" = external dllimport global i32
167 // GNU-DAG: @_Z15ImportedVarTmplI21ExplicitDecl_ImportedE = external dllimport global i32
168 extern template int ImportedVarTmpl<ExplicitDecl_Imported>;
169 USEVAR(ImportedVarTmpl<ExplicitDecl_Imported>)
170
171 // An explicit instantiation definition of an imported variable template cannot
172 // be imported because the template must be defined which is illegal.
173
174 // Import specialization of an imported variable template.
175 // MSC-DAG: @"??$ImportedVarTmpl@UExplicitSpec_Imported@@@@3HA" = external dllimport global i32
176 // GNU-DAG: @_Z15ImportedVarTmplI21ExplicitSpec_ImportedE = external dllimport global i32
177 template<> __declspec(dllimport) int ImportedVarTmpl<ExplicitSpec_Imported>;
178 USEVAR(ImportedVarTmpl<ExplicitSpec_Imported>)
179
180 // Not importing specialization of an imported variable template without
181 // explicit dllimport.
182 // MSC-DAG: @"??$ImportedVarTmpl@UExplicitSpec_NotImported@@@@3HA" = dso_local global i32 0, align 4
183 // GNU-DAG: @_Z15ImportedVarTmplI24ExplicitSpec_NotImportedE = dso_local global i32 0, align 4
184 template<> int ImportedVarTmpl<ExplicitSpec_NotImported>;
185 USEVAR(ImportedVarTmpl<ExplicitSpec_NotImported>)
186
187 // Import explicit instantiation declaration of a non-imported variable template.
188 // MSC-DAG: @"??$VarTmpl@UExplicitDecl_Imported@@@@3HA" = external dllimport global i32
189 // GNU-DAG: @_Z7VarTmplI21ExplicitDecl_ImportedE = external dllimport global i32
190 extern template __declspec(dllimport) int VarTmpl<ExplicitDecl_Imported>;
191 USEVAR(VarTmpl<ExplicitDecl_Imported>)
192
193 // Import explicit instantiation definition of a non-imported variable template.
194 // MSC-DAG: @"??$VarTmpl@UExplicitInst_Imported@@@@3HA" = external dllimport global i32
195 // GNU-DAG: @_Z7VarTmplI21ExplicitInst_ImportedE = external dllimport global i32
196 template __declspec(dllimport) int VarTmpl<ExplicitInst_Imported>;
197 USEVAR(VarTmpl<ExplicitInst_Imported>)
198
199 // Import specialization of a non-imported variable template.
200 // MSC-DAG: @"??$VarTmpl@UExplicitSpec_Imported@@@@3HA" = external dllimport global i32
201 // GNU-DAG: @_Z7VarTmplI21ExplicitSpec_ImportedE = external dllimport global i32
202 template<> __declspec(dllimport) int VarTmpl<ExplicitSpec_Imported>;
203 USEVAR(VarTmpl<ExplicitSpec_Imported>)
204
205
206
207 //===----------------------------------------------------------------------===//
208 // Functions
209 //===----------------------------------------------------------------------===//
210
211 // GNU-DAG: declare dso_local void @_ZdlPv{{[jym]}}(ptr, i{{32|64}})
212
213 // Import function declaration.
214 // MSC-DAG: declare dllimport void @"?decl@@YAXXZ"()
215 // GNU-DAG: declare dllimport void @_Z4declv()
216 __declspec(dllimport) void decl();
217 USE(decl)
218
219 // extern "C"
220 // MSC-DAG: declare dllimport void @externC()
221 // GNU-DAG: declare dllimport void @externC()
222 extern "C" __declspec(dllimport) void externC();
223 USE(externC)
224
225 // Import inline function.
226 // MSC-DAG: declare dllimport void @"?inlineFunc@@YAXXZ"()
227 // GNU-DAG: define linkonce_odr dso_local void @_Z10inlineFuncv()
228 // MO1-DAG: define available_externally dllimport void @"?inlineFunc@@YAXXZ"()
229 // GO1-DAG: define linkonce_odr dso_local void @_Z10inlineFuncv()
230 __declspec(dllimport) inline void inlineFunc() {}
231 USE(inlineFunc)
232
233 // MSC-DAG: declare dllimport void @"?inlineDecl@@YAXXZ"()
234 // GNU-DAG: define linkonce_odr dso_local void @_Z10inlineDeclv()
235 // MO1-DAG: define available_externally dllimport void @"?inlineDecl@@YAXXZ"()
236 // GO1-DAG: define linkonce_odr dso_local void @_Z10inlineDeclv()
237 __declspec(dllimport) inline void inlineDecl();
238 void inlineDecl() {}
239 USE(inlineDecl)
240
241 // MSC-DAG: declare dllimport void @"?inlineDef@@YAXXZ"()
242 // GNU-DAG: define linkonce_odr dso_local void @_Z9inlineDefv()
243 // MO1-DAG: define available_externally dllimport void @"?inlineDef@@YAXXZ"()
244 // GO1-DAG: define linkonce_odr dso_local void @_Z9inlineDefv()
245 __declspec(dllimport) void inlineDef();
246 inline void inlineDef() {}
247 USE(inlineDef)
248
249 // inline attributes
250 // MSC-DAG: declare dllimport void @"?noinline@@YAXXZ"()
251 // GNU-DAG: define linkonce_odr dso_local void @_Z8noinlinev()
252 __declspec(dllimport) __attribute__((noinline)) inline void noinline() {}
253 USE(noinline)
254
255 // MSC2-NOT: @"?alwaysInline@@YAXXZ"()
256 // GNU2-NOT: @_Z12alwaysInlinev()
257 __declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline() {}
258 USE(alwaysInline)
259
260 // Redeclarations
261 // MSC-DAG: declare dllimport void @"?redecl1@@YAXXZ"()
262 // GNU-DAG: declare dllimport void @_Z7redecl1v()
263 __declspec(dllimport) void redecl1();
264 __declspec(dllimport) void redecl1();
265 USE(redecl1)
266
267 // NB: MSC issues a warning and makes redecl2/redecl3 dllexport. We follow GCC
268 // and drop the dllimport with a warning.
269 // MSC-DAG: declare dso_local void @"?redecl2@@YAXXZ"()
270 // GNU-DAG: declare dso_local void @_Z7redecl2v()
271 __declspec(dllimport) void redecl2();
272 void redecl2();
273 USE(redecl2)
274
275 // MSC-DAG: define dso_local dllexport void @"?redecl3@@YAXXZ"()
276 // GNU-DAG: define dso_local void @_Z7redecl3v()
277 __declspec(dllimport) void redecl3();
278 void redecl3() {} // dllimport ignored
279 USE(redecl3)
280
281
282 // Friend functions
283 // MSC-DAG: declare dllimport void @"?friend1@@YAXXZ"()
284 // GNU-DAG: declare dllimport void @_Z7friend1v()
285 // MSC-DAG: declare dso_local void @"?friend2@@YAXXZ"()
286 // GNU-DAG: declare dso_local void @_Z7friend2v()
287 // MSC-DAG: define dso_local dllexport void @"?friend3@@YAXXZ"()
288 // GNU-DAG: define dso_local void @_Z7friend3v()
289 // MSC-DAG: declare dso_local void @"?friend4@@YAXXZ"()
290 // GNU-DAG: declare dso_local void @_Z7friend4v()
291 // MSC-DAG: declare dllimport void @"?friend5@@YAXXZ"()
292 // GNU-DAG: declare dllimport void @_Z7friend5v()
293
294 struct FuncFriend {
295 friend __declspec(dllimport) void friend1();
296 friend __declspec(dllimport) void friend2();
297 friend __declspec(dllimport) void friend3();
298 };
299 __declspec(dllimport) void friend1();
300 void friend2(); // dllimport ignored
301 void friend3() {} // dllimport ignored
302
303 __declspec(dllimport) void friend4();
304 __declspec(dllimport) void friend5();
305 struct FuncFriendRedecl {
306 friend void friend4(); // dllimport ignored
307 friend void ::friend5();
308 };
309 USE(friend1)
310 USE(friend2)
311 USE(friend3)
312 USE(friend4)
313 USE(friend5)
314
315 // Implicit declarations can be redeclared with dllimport.
316 // MSC-DAG: declare dllimport nonnull ptr @"??2@{{YAPAXI|YAPEAX_K}}@Z"(
317 // GNU-DAG: declare dllimport nonnull ptr @_Znw{{[yjm]}}(
318 __declspec(dllimport) void* operator new(__SIZE_TYPE__ n);
319 void UNIQ(use)() { ::operator new(42); }
320
321 // MSC-DAG: declare dllimport void @"?externalFunc@ns@@YAXXZ"()
322 // GNU-DAG: declare dllimport void @_ZN2ns12externalFuncEv()
323 namespace ns { __declspec(dllimport) void externalFunc(); }
324 USE(ns::externalFunc)
325
326 // A dllimport function referencing non-imported vars or functions must not be available_externally.
327
328 __declspec(dllimport) int ImportedVar;
329 int NonImportedVar;
330 __declspec(dllimport) int ImportedFunc();
331 int NonImportedFunc();
332 struct ClassWithNonImportedMethod { int f(); };
333
334 __declspec(dllimport) inline int ReferencingImportedVar() { return ImportedVar; }
335 // MO1-DAG: define available_externally dllimport i32 @"?ReferencingImportedVar@@YAHXZ"
336 __declspec(dllimport) inline int ReferencingNonImportedVar() { return NonImportedVar; }
337 // MO1-DAG: declare dllimport i32 @"?ReferencingNonImportedVar@@YAHXZ"()
338 __declspec(dllimport) inline int ReferencingImportedFunc() { return ImportedFunc(); }
339 // MO1-DAG: define available_externally dllimport i32 @"?ReferencingImportedFunc@@YAHXZ"
340 __declspec(dllimport) inline int ReferencingNonImportedFunc() { return NonImportedFunc(); }
341 // MO1-DAG: declare dllimport i32 @"?ReferencingNonImportedFunc@@YAHXZ"()
342 __declspec(dllimport) inline int ReferencingNonImportedMethod(ClassWithNonImportedMethod *x) { return x->f(); }
343 // MO1-DAG: declare dllimport i32 @"?ReferencingNonImportedMethod
344 __declspec(dllimport) inline int ReferencingClassMemberPtr(int (ClassWithNonImportedMethod::*p)(), ClassWithNonImportedMethod *x) { return (x->*p)(); }
345 // MO1-DAG: define available_externally dllimport i32 @"?ReferencingClassMemberPtr@@YAHP8ClassWithNonImportedMethod@@AEHXZPAU1@@Z"
346 USE(ReferencingImportedVar)
347 USE(ReferencingNonImportedVar)
348 USE(ReferencingImportedFunc)
349 USE(ReferencingNonImportedFunc)
350 USE1(ReferencingNonImportedMethod)
351 void UNIQ(use)() { ReferencingClassMemberPtr(&ClassWithNonImportedMethod::f, nullptr); }
352 // References to operator new and delete count too, despite not being DeclRefExprs.
353 __declspec(dllimport) inline int *ReferencingNonImportedNew() { return new int[2]; }
354 // MO1-DAG: declare dllimport ptr @"?ReferencingNonImportedNew@@YAPAHXZ"
355 __declspec(dllimport) inline int *ReferencingNonImportedDelete() { delete (int*)nullptr; }
356 // MO1-DAG: declare dllimport ptr @"?ReferencingNonImportedDelete@@YAPAHXZ"
357 USE(ReferencingNonImportedNew)
358 USE(ReferencingNonImportedDelete)
359 __declspec(dllimport) void* operator new[](__SIZE_TYPE__);
360 __declspec(dllimport) void operator delete(void*);
361 __declspec(dllimport) inline int *ReferencingImportedNew() { return new int[2]; }
362 // MO1-DAG: define available_externally dllimport ptr @"?ReferencingImportedNew@@YAPAHXZ"
363 __declspec(dllimport) inline int *ReferencingImportedDelete() { delete (int*)nullptr; }
364 // MO1-DAG: declare dllimport ptr @"?ReferencingImportedDelete@@YAPAHXZ"
365 USE(ReferencingImportedNew)
366 USE(ReferencingImportedDelete)
367 struct ClassWithDtor { ~ClassWithDtor() {} };
368 struct __declspec(dllimport) ClassWithNonDllImportField { using X = ClassWithDtor; X t[2]; };
369 struct __declspec(dllimport) ClassWithNonDllImportBase : public ClassWithDtor { };
370 USECLASS(ClassWithNonDllImportField);
371 USECLASS(ClassWithNonDllImportBase);
372 // MO1-DAG: declare dllimport x86_thiscallcc void @"??1ClassWithNonDllImportBase@@QAE@XZ"(ptr {{[^,]*}})
373 // MO1-DAG: declare dllimport x86_thiscallcc void @"??1ClassWithNonDllImportField@@QAE@XZ"(ptr {{[^,]*}})
374 struct ClassWithCtor { ClassWithCtor() {} };
375 struct __declspec(dllimport) ClassWithNonDllImportFieldWithCtor { ClassWithCtor t; };
376 USECLASS(ClassWithNonDllImportFieldWithCtor);
377 // MO1-DAG: declare dllimport x86_thiscallcc ptr @"??0ClassWithNonDllImportFieldWithCtor@@QAE@XZ"(ptr {{[^,]*}} returned {{[^,]*}})
378 struct ClassWithImplicitDtor { __declspec(dllimport) ClassWithImplicitDtor(); ClassWithDtor member; };
379 __declspec(dllimport) inline void ReferencingDtorThroughDefinition() { ClassWithImplicitDtor x; };
380 USE(ReferencingDtorThroughDefinition)
381 // MO1-DAG: declare dllimport void @"?ReferencingDtorThroughDefinition@@YAXXZ"()
382 __declspec(dllimport) inline void ReferencingDtorThroughTemporary() { ClassWithImplicitDtor(); };
383 USE(ReferencingDtorThroughTemporary)
384 // MO1-DAG: declare dllimport void @"?ReferencingDtorThroughTemporary@@YAXXZ"()
385
386 // A dllimport function with a TLS variable must not be available_externally.
387 __declspec(dllimport) inline void FunctionWithTLSVar() { static __thread int x = 42; }
388 // MO1-DAG: declare dllimport void @"?FunctionWithTLSVar@@YAXXZ"
389 __declspec(dllimport) inline void FunctionWithNormalVar() { static int x = 42; }
390 // MO1-DAG: define available_externally dllimport void @"?FunctionWithNormalVar@@YAXXZ"
391 USE(FunctionWithTLSVar)
392 USE(FunctionWithNormalVar)
393
394 // always_inline and __force_inline take precedence.
395 __declspec(dllimport) inline int ReferencingNonImportedFuncAlwaysInline() __attribute__((always_inline)) { return NonImportedFunc(); }
396 USE(ReferencingNonImportedFuncAlwaysInline)
397 // MO1-DAG: define available_externally dllimport i32 @"?ReferencingNonImportedFuncAlwaysInline@@YAHXZ"
398 __declspec(dllimport) __forceinline int ReferencingNonImportedFuncForceInline() { return NonImportedFunc(); }
399 USE(ReferencingNonImportedFuncForceInline)
400 // MO1-DAG: define available_externally dllimport i32 @"?ReferencingNonImportedFuncForceInline@@YAHXZ"
401
402 //===----------------------------------------------------------------------===//
403 // Function templates
404 //===----------------------------------------------------------------------===//
405
406 // Import function template declaration.
407 // MSC-DAG: declare dllimport void @"??$funcTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
408 // GNU-DAG: declare dllimport void @_Z12funcTmplDeclI21ImplicitInst_ImportedEvv()
409 template<typename T> __declspec(dllimport) void funcTmplDecl();
410 USE(funcTmplDecl<ImplicitInst_Imported>)
411
412 // Function template definitions cannot be imported.
413
414 // Import inline function template.
415 // MSC-DAG: declare dllimport void @"??$inlineFuncTmpl1@UImplicitInst_Imported@@@@YAXXZ"()
416 // GNU-DAG: define linkonce_odr dso_local void @_Z15inlineFuncTmpl1I21ImplicitInst_ImportedEvv()
417 // MO1-DAG: define available_externally dllimport void @"??$inlineFuncTmpl1@UImplicitInst_Imported@@@@YAXXZ"()
418 // GO1-DAG: define linkonce_odr dso_local void @_Z15inlineFuncTmpl1I21ImplicitInst_ImportedEvv()
419 template<typename T> __declspec(dllimport) inline void inlineFuncTmpl1() {}
420 USE(inlineFuncTmpl1<ImplicitInst_Imported>)
421
422 // MSC-DAG: declare dllimport void @"??$inlineFuncTmpl2@UImplicitInst_Imported@@@@YAXXZ"()
423 // GNU-DAG: define linkonce_odr dso_local void @_Z15inlineFuncTmpl2I21ImplicitInst_ImportedEvv()
424 // MO1-DAG: define available_externally dllimport void @"??$inlineFuncTmpl2@UImplicitInst_Imported@@@@YAXXZ"()
425 // GO1-DAG: define linkonce_odr dso_local void @_Z15inlineFuncTmpl2I21ImplicitInst_ImportedEvv()
426 template<typename T> inline void __attribute__((dllimport)) inlineFuncTmpl2() {}
427 USE(inlineFuncTmpl2<ImplicitInst_Imported>)
428
429 // MSC-DAG: define linkonce_odr dso_local void @"??$inlineFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
430 // GNU-DAG: define linkonce_odr dso_local void @_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv()
431 // MO1-DAG: define linkonce_odr dso_local void @"??$inlineFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
432 // GO1-DAG: define linkonce_odr dso_local void @_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv()
433 template<typename T> __declspec(dllimport) inline void inlineFuncTmplDecl();
434 template<typename T> void inlineFuncTmplDecl() {}
435 USE(inlineFuncTmplDecl<ImplicitInst_Imported>)
436
437 // MSC-DAG: define linkonce_odr dso_local void @"??$inlineFuncTmplDef@UImplicitInst_Imported@@@@YAXXZ"()
438 // GNU-DAG: define linkonce_odr dso_local void @_Z17inlineFuncTmplDefI21ImplicitInst_ImportedEvv()
439 // MO1-DAG: define linkonce_odr dso_local void @"??$inlineFuncTmplDef@UImplicitInst_Imported@@@@YAXXZ"()
440 // GO1-DAG: define linkonce_odr dso_local void @_Z17inlineFuncTmplDefI21ImplicitInst_ImportedEvv()
441 template<typename T> __declspec(dllimport) void inlineFuncTmplDef();
442 template<typename T> inline void inlineFuncTmplDef() {}
443 USE(inlineFuncTmplDef<ImplicitInst_Imported>)
444
445
446 // Redeclarations
447 // MSC-DAG: declare dllimport void @"??$funcTmplRedecl1@UImplicitInst_Imported@@@@YAXXZ"()
448 // GNU-DAG: declare dllimport void @_Z15funcTmplRedecl1I21ImplicitInst_ImportedEvv()
449 template<typename T> __declspec(dllimport) void funcTmplRedecl1();
450 template<typename T> __declspec(dllimport) void funcTmplRedecl1();
451 USE(funcTmplRedecl1<ImplicitInst_Imported>)
452
453 // MSC-DAG: declare dso_local void @"??$funcTmplRedecl2@UImplicitInst_NotImported@@@@YAXXZ"()
454 // GNU-DAG: declare dso_local void @_Z15funcTmplRedecl2I24ImplicitInst_NotImportedEvv()
455 template<typename T> __declspec(dllimport) void funcTmplRedecl2();
456 template<typename T> void funcTmplRedecl2(); // dllimport ignored
457 USE(funcTmplRedecl2<ImplicitInst_NotImported>)
458
459 // MSC-DAG: define linkonce_odr dso_local void @"??$funcTmplRedecl3@UImplicitInst_NotImported@@@@YAXXZ"()
460 // GNU-DAG: define linkonce_odr dso_local void @_Z15funcTmplRedecl3I24ImplicitInst_NotImportedEvv()
461 template<typename T> __declspec(dllimport) void funcTmplRedecl3();
462 template<typename T> void funcTmplRedecl3() {} // dllimport ignored
463 USE(funcTmplRedecl3<ImplicitInst_NotImported>)
464
465
466 // Function template friends
467 // MSC-DAG: declare dllimport void @"??$funcTmplFriend1@UImplicitInst_Imported@@@@YAXXZ"()
468 // GNU-DAG: declare dllimport void @_Z15funcTmplFriend1I21ImplicitInst_ImportedEvv()
469 // MSC-DAG: declare dso_local void @"??$funcTmplFriend2@UImplicitInst_NotImported@@@@YAXXZ"()
470 // GNU-DAG: declare dso_local void @_Z15funcTmplFriend2I24ImplicitInst_NotImportedEvv()
471 // MSC-DAG: define linkonce_odr dso_local void @"??$funcTmplFriend3@UImplicitInst_NotImported@@@@YAXXZ"()
472 // GNU-DAG: define linkonce_odr dso_local void @_Z15funcTmplFriend3I24ImplicitInst_NotImportedEvv()
473 // MSC-DAG: define linkonce_odr dso_local void @"??$funcTmplFriend4@UImplicitInst_Imported@@@@YAXXZ"()
474 // GNU-DAG: define linkonce_odr dso_local void @_Z15funcTmplFriend4I21ImplicitInst_ImportedEvv()
475 struct FuncTmplFriend {
476 template<typename T> friend __declspec(dllimport) void funcTmplFriend1();
477 template<typename T> friend __declspec(dllimport) void funcTmplFriend2();
478 template<typename T> friend __declspec(dllimport) void funcTmplFriend3();
479 template<typename T> friend __declspec(dllimport) inline void funcTmplFriend4();
480 };
481 template<typename T> __declspec(dllimport) void funcTmplFriend1();
482 template<typename T> void funcTmplFriend2(); // dllimport ignored
483 template<typename T> void funcTmplFriend3() {} // dllimport ignored
484 template<typename T> inline void funcTmplFriend4() {}
485 USE(funcTmplFriend1<ImplicitInst_Imported>)
486 USE(funcTmplFriend2<ImplicitInst_NotImported>)
487 USE(funcTmplFriend3<ImplicitInst_NotImported>)
488 USE(funcTmplFriend4<ImplicitInst_Imported>)
489
490 // MSC-DAG: declare dllimport void @"??$externalFuncTmpl@UImplicitInst_Imported@@@ns@@YAXXZ"()
491 // GNU-DAG: declare dllimport void @_ZN2ns16externalFuncTmplI21ImplicitInst_ImportedEEvv()
492 namespace ns { template<typename T> __declspec(dllimport) void externalFuncTmpl(); }
493 USE(ns::externalFuncTmpl<ImplicitInst_Imported>)
494
495
496 template<typename T> void funcTmpl() {}
497 template<typename T> inline void inlineFuncTmpl() {}
498 template<typename T> __declspec(dllimport) void importedFuncTmplDecl();
499 template<typename T> __declspec(dllimport) inline void importedFuncTmpl() {}
500
501 // Import implicit instantiation of an imported function template.
502 // MSC-DAG: declare dllimport void @"??$importedFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"()
503 // GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI21ImplicitInst_ImportedEvv()
504 USE(importedFuncTmplDecl<ImplicitInst_Imported>)
505
506 // MSC-DAG: declare dllimport void @"??$importedFuncTmpl@UImplicitInst_Imported@@@@YAXXZ"()
507 // GNU-DAG: define linkonce_odr dso_local void @_Z16importedFuncTmplI21ImplicitInst_ImportedEvv()
508 // MO1-DAG: define available_externally dllimport void @"??$importedFuncTmpl@UImplicitInst_Imported@@@@YAXXZ"()
509 // GO1-DAG: define linkonce_odr dso_local void @_Z16importedFuncTmplI21ImplicitInst_ImportedEvv()
510 USE(importedFuncTmpl<ImplicitInst_Imported>)
511
512 // Import explicit instantiation declaration of an imported function template.
513 // MSC-DAG: declare dllimport void @"??$importedFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
514 // GNU-DAG: declare dso_local void @_Z16importedFuncTmplI21ExplicitDecl_ImportedEvv()
515 // MO1-DAG: define available_externally dllimport void @"??$importedFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
516 // GO1-DAG: define available_externally dso_local void @_Z16importedFuncTmplI21ExplicitDecl_ImportedEvv()
517 extern template void importedFuncTmpl<ExplicitDecl_Imported>();
518 USE(importedFuncTmpl<ExplicitDecl_Imported>)
519
520 // Import explicit instantiation definition of an imported function template.
521 // MSC-DAG: declare dllimport void @"??$importedFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
522 // GNU-DAG: define weak_odr dso_local void @_Z16importedFuncTmplI21ExplicitInst_ImportedEvv()
523 // MO1-DAG: define available_externally dllimport void @"??$importedFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
524 // GO1-DAG: define weak_odr dso_local void @_Z16importedFuncTmplI21ExplicitInst_ImportedEvv()
525 template void importedFuncTmpl<ExplicitInst_Imported>();
526 USE(importedFuncTmpl<ExplicitInst_Imported>)
527
528
529 // Import specialization of an imported function template.
530 // MSC-DAG: declare dllimport void @"??$importedFuncTmplDecl@UExplicitSpec_Imported@@@@YAXXZ"()
531 // GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI21ExplicitSpec_ImportedEvv()
532 template<> __declspec(dllimport) void importedFuncTmplDecl<ExplicitSpec_Imported>();
533 USE(importedFuncTmplDecl<ExplicitSpec_Imported>)
534
535 // MSC-DAG-FIXME: declare dllimport void @"??$importedFuncTmplDecl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
536 // MO1-DAG-FIXME: define available_externally dllimport void @"??$importedFuncTmplDecl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
537 #ifdef MSABI
538 //template<> __declspec(dllimport) void importedFuncTmplDecl<ExplicitSpec_Def_Imported>() {}
539 //USE(importedFuncTmplDecl<ExplicitSpec_Def_Imported>)
540 #endif
541
542 // MSC-DAG: declare dllimport void @"??$importedFuncTmplDecl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
543 // GNU-DAG: define linkonce_odr dso_local void @_Z20importedFuncTmplDeclI31ExplicitSpec_InlineDef_ImportedEvv()
544 // MO1-DAG: define available_externally dllimport void @"??$importedFuncTmplDecl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
545 // GO1-DAG: define linkonce_odr dso_local void @_Z20importedFuncTmplDeclI31ExplicitSpec_InlineDef_ImportedEvv()
546 template<> __declspec(dllimport) inline void importedFuncTmplDecl<ExplicitSpec_InlineDef_Imported>() {}
547 USE(importedFuncTmplDecl<ExplicitSpec_InlineDef_Imported>)
548
549
550 // MSC-DAG: declare dllimport void @"??$importedFuncTmpl@UExplicitSpec_Imported@@@@YAXXZ"()
551 // GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitSpec_ImportedEvv()
552 template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Imported>();
553 USE(importedFuncTmpl<ExplicitSpec_Imported>)
554
555 // MSC-DAG-FIXME: declare dllimport void @"??$importedFuncTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
556 // MO1-DAG-FIXME: define available_externally dllimport void @"??$importedFuncTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
557 #ifdef MSABI
558 //template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Def_Imported>() {}
559 //USE(importedFuncTmpl<ExplicitSpec_Def_Imported>)
560 #endif
561
562 // MSC-DAG: declare dllimport void @"??$importedFuncTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
563 // GNU-DAG: define linkonce_odr dso_local void @_Z16importedFuncTmplI31ExplicitSpec_InlineDef_ImportedEvv()
564 // MO1-DAG: define available_externally dllimport void @"??$importedFuncTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
565 // GO1-DAG: define linkonce_odr dso_local void @_Z16importedFuncTmplI31ExplicitSpec_InlineDef_ImportedEvv()
566 template<> __declspec(dllimport) inline void importedFuncTmpl<ExplicitSpec_InlineDef_Imported>() {}
567 USE(importedFuncTmpl<ExplicitSpec_InlineDef_Imported>)
568
569
570 // Not importing specialization of an imported function template without
571 // explicit dllimport.
572 // MSC-DAG: define dso_local void @"??$importedFuncTmpl@UExplicitSpec_NotImported@@@@YAXXZ"()
573 // GNU-DAG: define dso_local void @_Z16importedFuncTmplI24ExplicitSpec_NotImportedEvv()
574 template<> void importedFuncTmpl<ExplicitSpec_NotImported>() {}
575 USE(importedFuncTmpl<ExplicitSpec_NotImported>)
576
577
578 // Import explicit instantiation declaration of a non-imported function template.
579 // MSC-DAG: declare dllimport void @"??$funcTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
580 // MSC-DAG: declare dllimport void @"??$inlineFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
581 // GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitDecl_ImportedEvv()
582 // GNU-DAG: declare dso_local void @_Z14inlineFuncTmplI21ExplicitDecl_ImportedEvv()
583 // MO1-DAG: define available_externally dllimport void @"??$inlineFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"()
584 // GO1-DAG: define available_externally dso_local void @_Z14inlineFuncTmplI21ExplicitDecl_ImportedEvv()
585 extern template __declspec(dllimport) void funcTmpl<ExplicitDecl_Imported>();
586 extern template __declspec(dllimport) void inlineFuncTmpl<ExplicitDecl_Imported>();
587 USE(funcTmpl<ExplicitDecl_Imported>)
588 USE(inlineFuncTmpl<ExplicitDecl_Imported>)
589
590
591 // Import explicit instantiation definition of a non-imported function template.
592 // MSC-DAG: declare dllimport void @"??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"()
593 // MSC-DAG: declare dllimport void @"??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
594 // GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv()
595 // GNU-DAG: define weak_odr dso_local void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv()
596 // MO1-DAG: declare dllimport void @"??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"()
597 // MO1-DAG: define available_externally dllimport void @"??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
598 // GO1-DAG: define available_externally dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv()
599 // GO1-DAG: define weak_odr dso_local void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv()
600 template __declspec(dllimport) void funcTmpl<ExplicitInst_Imported>();
601 template __declspec(dllimport) void inlineFuncTmpl<ExplicitInst_Imported>();
602 USE(funcTmpl<ExplicitInst_Imported>)
603 USE(inlineFuncTmpl<ExplicitInst_Imported>)
604
605
606 // Import specialization of a non-imported function template.
607 // MSC-DAG: declare dllimport void @"??$funcTmpl@UExplicitSpec_Imported@@@@YAXXZ"()
608 // GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitSpec_ImportedEvv()
609 template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Imported>();
610 USE(funcTmpl<ExplicitSpec_Imported>)
611
612 // MSC-DAG-FIXME: declare dllimport void @"??$funcTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
613 // MO1-DAG-FIXME: define available_externally dllimport void @"??$funcTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"()
614 #ifdef MSABI
615 //template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Def_Imported>() {}
616 //USE(funcTmpl<ExplicitSpec_Def_Imported>)
617 #endif
618
619 // MSC-DAG: declare dllimport void @"??$funcTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
620 // GNU-DAG: define linkonce_odr dso_local void @_Z8funcTmplI31ExplicitSpec_InlineDef_ImportedEvv()
621 // MO1-DAG: define available_externally dllimport void @"??$funcTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"()
622 // GO1-DAG: define linkonce_odr dso_local void @_Z8funcTmplI31ExplicitSpec_InlineDef_ImportedEvv()
623 template<> __declspec(dllimport) inline void funcTmpl<ExplicitSpec_InlineDef_Imported>() {}
624 USE(funcTmpl<ExplicitSpec_InlineDef_Imported>)
625
626 #ifdef MSABI
627 namespace pr35435 {
628 struct X;
629 template <typename T> struct __declspec(dllimport) S {
630 void foo(T *t) { t->problem(); }
631 };
632 template void S<X>::foo(X*); // Cannot be instantiated because X is incomplete; dllimport means it's treated as an instantiation decl.
633 }
634 #endif
635
636
637 //===----------------------------------------------------------------------===//
638 // Classes
639 //===----------------------------------------------------------------------===//
640
641 struct __declspec(dllimport) T {
642 void a() {}
643 // MO1-DAG: define available_externally dllimport x86_thiscallcc void @"?a@T@@QAEXXZ"
644
645 static void StaticMethod();
646 // MSC-DAG: declare dllimport void @"?StaticMethod@T@@SAXXZ"()
647 // GNU-DAG: declare dllimport void @_ZN1T12StaticMethodEv()
648
649 static int b;
650 // MO1-DAG: @"?b@T@@2HA" = external dllimport global i32
651
652 T& operator=(const T&) = default;
653 // MO1-DAG: define available_externally dllimport x86_thiscallcc nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @"??4T@@QAEAAU0@ABU0@@Z"
654 // PS-DAG: declare dllimport nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN1TaSERKS_
655
656 T& operator=(T&&) = default;
657 // Note: Don't mark inline move operators dllimport because MSVC versions before 2015 don't export them.
658 // M18-DAG: define linkonce_odr dso_local x86_thiscallcc nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @"??4T@@QAEAAU0@$$QAU0@@Z"
659 // M19-DAG: define available_externally dllimport x86_thiscallcc nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @"??4T@@QAEAAU0@$$QAU0@@Z"
660 // PS-DAG: declare dllimport nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN1TaSEOS_
661 };
662 USEMEMFUNC(T, a)
663 USESTATICMEMFUNC(T, StaticMethod)
664 USEVAR(T::b)
665 USECOPYASSIGN(T)
666 USEMOVEASSIGN(T)
667
668 template <typename T> struct __declspec(dllimport) U { void foo() {} };
669 // MO1-DAG: define available_externally dllimport x86_thiscallcc void @"?foo@?$U@H@@QAEXXZ"
670 struct __declspec(dllimport) V : public U<int> { };
671 USEMEMFUNC(V, foo)
672
673 struct __declspec(dllimport) W { virtual void foo() {} };
674 USECLASS(W)
675 // vftable:
676 // MO1-DAG: @"??_SW@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] } { [1 x ptr] [ptr @"?foo@W@@UAEXXZ"] }
677 // GO1-DAG: @_ZTV1W = available_externally dllimport unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1W3fooEv] }
678
679 struct __declspec(dllimport) KeyFuncClass {
680 constexpr KeyFuncClass() {}
681 virtual void foo();
682 };
683 extern constexpr KeyFuncClass keyFuncClassVar = {};
684 // G32-DAG: @_ZTV12KeyFuncClass = external dllimport unnamed_addr constant { [3 x ptr] }
685 // C32-DAG: @_ZTV12KeyFuncClass = external dllimport unnamed_addr constant { [3 x ptr] }
686
687 struct __declspec(dllimport) X : public virtual W {};
688 USECLASS(X)
689 // vbtable:
690 // MO1-DAG: @"??_8X@@7B@" = available_externally dllimport unnamed_addr constant [2 x i32] [i32 0, i32 4]
691
692 struct __declspec(dllimport) Y {
693 int x;
694 };
695
696 struct __declspec(dllimport) Z { virtual ~Z() {} };
697 USECLASS(Z)
698 // User-defined dtor:
699 // MO1-DAG: define available_externally dllimport x86_thiscallcc void @"??1Z@@UAE@XZ"
700
701 namespace DontUseDtorAlias {
702 struct __declspec(dllimport) A { ~A(); };
703 struct __declspec(dllimport) B : A { ~B(); };
704 inline A::~A() { }
705 inline B::~B() { }
706 // Emit a real definition of B's constructor; don't alias it to A's.
707 // MO1-DAG: available_externally dllimport x86_thiscallcc void @"??1B@DontUseDtorAlias@@QAE@XZ"
708 USECLASS(B)
709 }
710
711 namespace Vtordisp {
712 // Don't dllimport the vtordisp.
713 // MO1-DAG: define linkonce_odr dso_local x86_thiscallcc void @"?f@?$C@H@Vtordisp@@$4PPPPPPPM@A@AEXXZ"
714
715 class __declspec(dllimport) Base {
716 virtual void f() {}
717 };
718 template <typename T>
719 class __declspec(dllimport) C : virtual public Base {
720 public:
721 C() {}
722 virtual void f() {}
723 };
724 USECLASS(C<int>);
725 }
726
727 namespace ClassTemplateStaticDef {
728 // Regular template static field:
729 template <typename T> struct __declspec(dllimport) S {
730 static int x;
731 };
732 template <typename T> int S<T>::x;
733 // MSC-DAG: @"?x@?$S@H@ClassTemplateStaticDef@@2HA" = external dllimport global i32
734 int f() { return S<int>::x; }
735
736 // Partial class template specialization static field:
737 template <typename A> struct T;
738 template <typename A> struct __declspec(dllimport) T<A*> {
739 static int x;
740 };
741 template <typename A> int T<A*>::x;
742 // GNU-DAG: @_ZN22ClassTemplateStaticDef1TIPvE1xE = external dllimport global i32
743 int g() { return T<void*>::x; }
744 }
745
746 namespace PR19933 {
747 // Don't dynamically initialize dllimport vars.
748 // MSC2-NOT: @llvm.global_ctors
749 // GNU2-NOT: @llvm.global_ctors
750
751 struct NonPOD { NonPOD(); };
752 template <typename T> struct A { static NonPOD x; };
753 template <typename T> NonPOD A<T>::x;
754 template struct __declspec(dllimport) A<int>;
755 USEVARTYPE(NonPOD, A<int>::x);
756 // MSC-DAG: @"?x@?$A@H@PR19933@@2UNonPOD@2@A" = external dllimport global %"struct.PR19933::NonPOD"
757
758 int f();
759 template <typename T> struct B { static int x; };
760 template <typename T> int B<T>::x = f();
761 template struct __declspec(dllimport) B<int>;
762 USEVAR(B<int>::x);
763 // MSC-DAG: @"?x@?$B@H@PR19933@@2HA" = external dllimport global i32
764
765 constexpr int g() { return 42; }
766 template <typename T> struct C { static int x; };
767 template <typename T> int C<T>::x = g();
768 template struct __declspec(dllimport) C<int>;
769 USEVAR(C<int>::x);
770 // MSC-DAG: @"?x@?$C@H@PR19933@@2HA" = external dllimport global i32
771
772 template <int I> struct D { static int x, y; };
773 template <int I> int D<I>::x = I + 1;
774 template <int I> int D<I>::y = I + f();
775 template struct __declspec(dllimport) D<42>;
776 USEVAR(D<42>::x);
777 USEVAR(D<42>::y);
778 // MSC-DAG: @"?x@?$D@$0CK@@PR19933@@2HA" = external dllimport global i32
779 // MSC-DAG: @"?y@?$D@$0CK@@PR19933@@2HA" = external dllimport global i32
780 }
781
782 namespace PR21355 {
783 struct __declspec(dllimport) S {
784 virtual ~S();
785 };
786 S::~S() {}
787
788 // S::~S is a key function, so we would ordinarily emit a strong definition for
789 // the vtable. However, S is imported, so the vtable should be too.
790
791 // GNU-DAG: @_ZTVN7PR213551SE = available_externally dllimport unnamed_addr constant { [4 x ptr] }
792 }
793
794 namespace PR21366 {
795 struct __declspec(dllimport) S {
796 void outOfLineMethod();
797 void inlineMethod() {}
798 inline void anotherInlineMethod();
799 void outOfClassInlineMethod();
800 };
801 void S::anotherInlineMethod() {}
802 inline void S::outOfClassInlineMethod() {}
803 }
804
805 namespace PR27319 {
806 // Make sure we don't assert due to not having checked for operator delete on
807 // the destructor.
808 template <typename> struct A {
809 virtual ~A() = default;
810 };
811 extern template struct __declspec(dllimport) A<int>;
812 void f() { new A<int>(); }
813 // MO1-DAG: @"??_S?$A@H@PR27319@@6B@" = linkonce_odr unnamed_addr constant { [1 x ptr] }
814 }
815
816 // MS ignores DLL attributes on partial specializations.
817 template <typename T> struct PartiallySpecializedClassTemplate {};
818 template <typename T> struct __declspec(dllimport) PartiallySpecializedClassTemplate<T*> { void f(); };
819 USEMEMFUNC(PartiallySpecializedClassTemplate<void*>, f);
820 // M32-DAG: declare dso_local x86_thiscallcc void @"?f@?$PartiallySpecializedClassTemplate@PAX@@QAEXXZ"
821 // G32-DAG: declare dllimport x86_thiscallcc void @_ZN33PartiallySpecializedClassTemplateIPvE1fEv
822 // C32-DAG: declare dllimport void @_ZN33PartiallySpecializedClassTemplateIPvE1fEv
823
824 // Attributes on explicit specializations are honored.
825 template <typename T> struct ExplicitlySpecializedClassTemplate {};
826 template <> struct __declspec(dllimport) ExplicitlySpecializedClassTemplate<void*> { void f(); };
827 USEMEMFUNC(ExplicitlySpecializedClassTemplate<void*>, f);
828 // M32-DAG: declare dllimport x86_thiscallcc void @"?f@?$ExplicitlySpecializedClassTemplate@PAX@@QAEXXZ"
829 // G32-DAG: declare dllimport x86_thiscallcc void @_ZN34ExplicitlySpecializedClassTemplateIPvE1fEv
830 // C32-DAG: declare dllimport void @_ZN34ExplicitlySpecializedClassTemplateIPvE1fEv
831
832 // MS inherits DLL attributes to partial specializations.
833 template <typename T> struct __declspec(dllimport) PartiallySpecializedImportedClassTemplate {};
834 template <typename T> struct PartiallySpecializedImportedClassTemplate<T*> { void f() {} };
835 USEMEMFUNC(PartiallySpecializedImportedClassTemplate<void*>, f);
836 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"?f@?$PartiallySpecializedImportedClassTemplate@PAX@@QAEXXZ"
837 // G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN41PartiallySpecializedImportedClassTemplateIPvE1fEv
838 // C32-DAG: define linkonce_odr dso_local void @_ZN41PartiallySpecializedImportedClassTemplateIPvE1fEv
839
840 // Attributes on the instantiation take precedence over attributes on the template.
841 template <typename T> struct __declspec(dllexport) ExplicitlyInstantiatedWithDifferentAttr { void f() {} };
842 template struct __declspec(dllimport) ExplicitlyInstantiatedWithDifferentAttr<int>;
843 USEMEMFUNC(ExplicitlyInstantiatedWithDifferentAttr<int>, f);
844 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"?f@?$ExplicitlyInstantiatedWithDifferentAttr@H@@QAEXXZ"
845
846 template <typename T> struct ExplicitInstantiationDeclImportedDefTemplate { void f() {} ExplicitInstantiationDeclImportedDefTemplate() {}};
847 extern template struct ExplicitInstantiationDeclImportedDefTemplate<int>;
848 template struct __declspec(dllimport) ExplicitInstantiationDeclImportedDefTemplate<int>;
849 USECLASS(ExplicitInstantiationDeclImportedDefTemplate<int>);
850 USEMEMFUNC(ExplicitInstantiationDeclImportedDefTemplate<int>, f);
851 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"?f@?$ExplicitInstantiationDeclImportedDefTemplate@H@@QAEXXZ"
852 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc ptr @"??0?$ExplicitInstantiationDeclImportedDefTemplate@H@@QAE@XZ"
853 // G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN44ExplicitInstantiationDeclImportedDefTemplateIiE1fEv
854 // C32-DAG: define weak_odr dso_local void @_ZN44ExplicitInstantiationDeclImportedDefTemplateIiE1fEv
855
856 template <typename T> struct __declspec(dllimport) ExplicitInstantiationDeclExportedDefImportedTemplate { void f() {} ExplicitInstantiationDeclExportedDefImportedTemplate() {} };
857 extern template struct __declspec(dllimport) ExplicitInstantiationDeclExportedDefImportedTemplate <int>;
858 template struct __declspec(dllexport) ExplicitInstantiationDeclExportedDefImportedTemplate<int>;
859 USECLASS(ExplicitInstantiationDeclExportedDefImportedTemplate<int>);
860 USEMEMFUNC(ExplicitInstantiationDeclExportedDefImportedTemplate<int>, f);
861 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"?f@?$ExplicitInstantiationDeclExportedDefImportedTemplate@H@@QAEXXZ"
862 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc ptr @"??0?$ExplicitInstantiationDeclExportedDefImportedTemplate@H@@QAE@XZ"
863
864 template <typename T> struct PR23770BaseTemplate { void f() {} };
865 template <typename T> struct PR23770DerivedTemplate : PR23770BaseTemplate<int> {};
866 extern template struct PR23770DerivedTemplate<int>;
867 template struct __declspec(dllimport) PR23770DerivedTemplate<int>;
868 USEMEMFUNC(PR23770BaseTemplate<int>, f);
869 // M32-DAG: declare dllimport x86_thiscallcc void @"?f@?$PR23770BaseTemplate@H@@QAEXXZ"
870
871 namespace PR27810 {
872 template <class T>
873 struct basic_ostream {
874 struct sentry {
875 sentry() { }
876 void foo() { }
877 };
878 };
879 template class __declspec(dllimport) basic_ostream<char>;
880 // The explicit instantiation definition acts as an explicit instantiation
881 // *declaration*, dllimport is not inherited by the inner class, and no
882 // functions are emitted unless they are used.
883
884 USEMEMFUNC(basic_ostream<char>::sentry, foo);
885 // M32-DAG: define linkonce_odr dso_local x86_thiscallcc void @"?foo@sentry@?$basic_ostream@D@PR27810@@QAEXXZ"
886 // M32-NOT: ??0sentry@?$basic_ostream@D@PR27810@@QAE@XZ
887 }
888
889 namespace PR27811 {
890 template <class T> struct codecvt {
891 virtual ~codecvt() { }
892 };
893 template class __declspec(dllimport) codecvt<char>;
894
895 // dllimport means this explicit instantiation definition gets treated as a
896 // declaration. Thus, the vtable should not be marked used, and in fact
897 // nothing for this class should be emitted at all since it's not used.
898 // M32-NOT: codecvt
899 }
900
901 //===----------------------------------------------------------------------===//
902 // Classes with template base classes
903 //===----------------------------------------------------------------------===//
904
905 template <typename T> struct ClassTemplate { void func() {} };
906 template <typename T> struct __declspec(dllexport) ExportedClassTemplate { void func(); };
907 template <typename T> void ExportedClassTemplate<T>::func() {}
908 template <typename T> struct __declspec(dllimport) ImportedClassTemplate { void func(); };
909
910 template <typename T> struct ExplicitlySpecializedTemplate { void func() {} };
911 template <> struct ExplicitlySpecializedTemplate<int> { void func() {} };
912 template <typename T> struct ExplicitlyExportSpecializedTemplate { void func() {} };
913 template <> struct __declspec(dllexport) ExplicitlyExportSpecializedTemplate<int> { void func(); };
914 void ExplicitlyExportSpecializedTemplate<int>::func() {}
915 template <typename T> struct ExplicitlyImportSpecializedTemplate { void func() {} };
916 template <> struct __declspec(dllimport) ExplicitlyImportSpecializedTemplate<int> { void func(); };
917
918 template <typename T> struct ExplicitlyInstantiatedTemplate { void func() {} };
919 template struct ExplicitlyInstantiatedTemplate<int>;
920 template <typename T> struct ExplicitlyExportInstantiatedTemplate { void func(); };
921 template <typename T> void ExplicitlyExportInstantiatedTemplate<T>::func() {}
922 template struct __declspec(dllexport) ExplicitlyExportInstantiatedTemplate<int>;
923 template <typename T> struct ExplicitlyImportInstantiatedTemplate { void func(); };
924 template struct __declspec(dllimport) ExplicitlyImportInstantiatedTemplate<int>;
925
926
927 // MS: ClassTemplate<int> gets imported.
928 struct __declspec(dllimport) DerivedFromTemplate : public ClassTemplate<int> {};
929 USEMEMFUNC(ClassTemplate<int>, func)
930 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"?func@?$ClassTemplate@H@@QAEXXZ"
931 // G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN13ClassTemplateIiE4funcEv
932 // C32-DAG: define linkonce_odr dso_local void @_ZN13ClassTemplateIiE4funcEv
933 // PS-DAG: declare dllimport void @_ZN13ClassTemplateIiE4funcEv
934
935 // ImportedTemplate is explicitly imported.
936 struct __declspec(dllimport) DerivedFromImportedTemplate : public ImportedClassTemplate<int> {};
937 USEMEMFUNC(ImportedClassTemplate<int>, func)
938 // M32-DAG: declare dllimport x86_thiscallcc void @"?func@?$ImportedClassTemplate@H@@QAEXXZ"
939 // G32-DAG: declare dllimport x86_thiscallcc void @_ZN21ImportedClassTemplateIiE4funcEv
940 // C32-DAG: declare dllimport void @_ZN21ImportedClassTemplateIiE4funcEv
941 // PS-DAG: declare dllimport void @_ZN21ImportedClassTemplateIiE4funcEv
942
943 // ExportedTemplate is explicitly exported.
944 struct __declspec(dllimport) DerivedFromExportedTemplate : public ExportedClassTemplate<int> {};
945 USEMEMFUNC(ExportedClassTemplate<int>, func)
946 // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?func@?$ExportedClassTemplate@H@@QAEXXZ"
947 // G32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @_ZN21ExportedClassTemplateIiE4funcEv
948 // C32-DAG: define weak_odr dso_local dllexport void @_ZN21ExportedClassTemplateIiE4funcEv
949 // PS-DAG: define weak_odr dllexport void @_ZN21ExportedClassTemplateIiE4funcEv
950
951 // Base class already implicitly instantiated without attribute.
952 struct DerivedFromTemplateD : public ClassTemplate<double> {};
953 struct __declspec(dllimport) DerivedFromTemplateD2 : public ClassTemplate<double> {};
954 USEMEMFUNC(ClassTemplate<double>, func)
955 // M32-DAG: declare dllimport x86_thiscallcc void @"?func@?$ClassTemplate@N@@QAEXXZ"
956 // G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN13ClassTemplateIdE4funcEv
957 // C32-DAG: define linkonce_odr dso_local void @_ZN13ClassTemplateIdE4funcEv
958 // PS-DAG: declare dllimport void @_ZN13ClassTemplateIdE4funcEv
959
960 // MS: Base class already instantiated with dfferent attribute.
961 struct __declspec(dllexport) DerivedFromTemplateB : public ClassTemplate<bool> {};
962 struct __declspec(dllimport) DerivedFromTemplateB2 : public ClassTemplate<bool> {};
963 USEMEMFUNC(ClassTemplate<bool>, func)
964 // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?func@?$ClassTemplate@_N@@QAEXXZ"
965 // G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN13ClassTemplateIbE4funcEv
966 // C32-DAG: define linkonce_odr dso_local void @_ZN13ClassTemplateIbE4funcEv
967 // PS-DAG: define weak_odr dllexport void @_ZN13ClassTemplateIbE4funcEv
968
969 // Base class already specialized without dll attribute.
970 struct __declspec(dllimport) DerivedFromExplicitlySpecializedTemplate : public ExplicitlySpecializedTemplate<int> {};
971 USEMEMFUNC(ExplicitlySpecializedTemplate<int>, func)
972 // M32-DAG: define linkonce_odr dso_local x86_thiscallcc void @"?func@?$ExplicitlySpecializedTemplate@H@@QAEXXZ"
973 // G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN29ExplicitlySpecializedTemplateIiE4funcEv
974 // C32-DAG: define linkonce_odr dso_local void @_ZN29ExplicitlySpecializedTemplateIiE4funcEv
975 // PS-DAG: define linkonce_odr void @_ZN29ExplicitlySpecializedTemplateIiE4funcEv
976
977 // Base class alredy specialized with export attribute.
978 struct __declspec(dllimport) DerivedFromExplicitlyExportSpecializedTemplate : public ExplicitlyExportSpecializedTemplate<int> {};
979 USEMEMFUNC(ExplicitlyExportSpecializedTemplate<int>, func)
980 // M32-DAG: define dso_local dllexport x86_thiscallcc void @"?func@?$ExplicitlyExportSpecializedTemplate@H@@QAEXXZ"
981 // G32-DAG: define dso_local dllexport x86_thiscallcc void @_ZN35ExplicitlyExportSpecializedTemplateIiE4funcEv
982 // C32-DAG: define dso_local dllexport void @_ZN35ExplicitlyExportSpecializedTemplateIiE4funcEv
983 // PS-DAG: define dso_local dllexport void @_ZN35ExplicitlyExportSpecializedTemplateIiE4funcEv
984
985 // Base class already specialized with import attribute.
986 struct __declspec(dllimport) DerivedFromExplicitlyImportSpecializedTemplate : public ExplicitlyImportSpecializedTemplate<int> {};
987 USEMEMFUNC(ExplicitlyImportSpecializedTemplate<int>, func)
988 // M32-DAG: declare dllimport x86_thiscallcc void @"?func@?$ExplicitlyImportSpecializedTemplate@H@@QAEXXZ"
989 // G32-DAG: declare dllimport x86_thiscallcc void @_ZN35ExplicitlyImportSpecializedTemplateIiE4funcEv
990 // C32-DAG: declare dllimport void @_ZN35ExplicitlyImportSpecializedTemplateIiE4funcEv
991 // PS-DAG: declare dllimport void @_ZN35ExplicitlyImportSpecializedTemplateIiE4funcEv
992
993 // Base class already instantiated without dll attribute.
994 struct __declspec(dllimport) DerivedFromExplicitlyInstantiatedTemplate : public ExplicitlyInstantiatedTemplate<int> {};
995 USEMEMFUNC(ExplicitlyInstantiatedTemplate<int>, func)
996 // M32-DAG: define weak_odr dso_local x86_thiscallcc void @"?func@?$ExplicitlyInstantiatedTemplate@H@@QAEXXZ"
997 // G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN30ExplicitlyInstantiatedTemplateIiE4funcEv
998 // C32-DAG: define weak_odr dso_local void @_ZN30ExplicitlyInstantiatedTemplateIiE4funcEv
999 // PS-DAG: define weak_odr void @_ZN30ExplicitlyInstantiatedTemplateIiE4funcEv
1000
1001 // Base class already instantiated with export attribute.
1002 struct __declspec(dllimport) DerivedFromExplicitlyExportInstantiatedTemplate : public ExplicitlyExportInstantiatedTemplate<int> {};
1003 USEMEMFUNC(ExplicitlyExportInstantiatedTemplate<int>, func)
1004 // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?func@?$ExplicitlyExportInstantiatedTemplate@H@@QAEXXZ"
1005 // G32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @_ZN36ExplicitlyExportInstantiatedTemplateIiE4funcEv
1006 // C32-DAG: define weak_odr dso_local dllexport void @_ZN36ExplicitlyExportInstantiatedTemplateIiE4funcEv
1007 // PS-DAG: define weak_odr dllexport void @_ZN36ExplicitlyExportInstantiatedTemplateIiE4funcEv
1008
1009 // Base class already instantiated with import attribute.
1010 struct __declspec(dllimport) DerivedFromExplicitlyImportInstantiatedTemplate : public ExplicitlyImportInstantiatedTemplate<int> {};
1011 USEMEMFUNC(ExplicitlyImportInstantiatedTemplate<int>, func)
1012 // M32-DAG: declare dllimport x86_thiscallcc void @"?func@?$ExplicitlyImportInstantiatedTemplate@H@@QAEXXZ"
1013 // G32-DAG: declare dllimport x86_thiscallcc void @_ZN36ExplicitlyImportInstantiatedTemplateIiE4funcEv
1014 // C32-DAG: declare dllimport void @_ZN36ExplicitlyImportInstantiatedTemplateIiE4funcEv
1015 // PS-DAG: declare dllimport void @_ZN36ExplicitlyImportInstantiatedTemplateIiE4funcEv
1016
1017 // MS: A dll attribute propagates through multiple levels of instantiation.
1018 template <typename T> struct TopClass { void func() {} };
1019 template <typename T> struct MiddleClass : public TopClass<T> { };
1020 struct __declspec(dllimport) BottomClass : public MiddleClass<int> { };
1021 USEMEMFUNC(TopClass<int>, func)
1022 // M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"?func@?$TopClass@H@@QAEXXZ"
1023 // G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN8TopClassIiE4funcEv
1024 // C32-DAG: define linkonce_odr dso_local void @_ZN8TopClassIiE4funcEv
1025 // PS-DAG: declare dllimport void @_ZN8TopClassIiE4funcEv
1026
1027 template <typename T> struct ExplicitInstantiationDeclTemplateBase { void func() {} };
1028 extern template struct ExplicitInstantiationDeclTemplateBase<int>;
1029 struct __declspec(dllimport) DerivedFromExplicitInstantiationDeclTemplateBase : public ExplicitInstantiationDeclTemplateBase<int> {};
1030 template struct ExplicitInstantiationDeclTemplateBase<int>;
1031 USEMEMFUNC(ExplicitInstantiationDeclTemplateBase<int>, func)
1032 // M32-DAG: declare dllimport x86_thiscallcc void @"?func@?$ExplicitInstantiationDeclTemplateBase@H@@QAEXXZ"
1033 // G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN37ExplicitInstantiationDeclTemplateBaseIiE4funcEv
1034 // C32-DAG: define weak_odr dso_local void @_ZN37ExplicitInstantiationDeclTemplateBaseIiE4funcEv
1035 // PS-DAG: declare dllimport void @_ZN37ExplicitInstantiationDeclTemplateBaseIiE4funcEv
1036
1037 template <typename T> struct ExplicitInstantiationDeclTemplateBase2 { void func() {} };
1038 extern template struct ExplicitInstantiationDeclTemplateBase2<int>;
1039 struct __declspec(dllimport) DerivedFromExplicitInstantiationDeclTemplateBase2 : public ExplicitInstantiationDeclTemplateBase2<int> {};
1040 template struct __declspec(dllexport) ExplicitInstantiationDeclTemplateBase2<int>;
1041 USEMEMFUNC(ExplicitInstantiationDeclTemplateBase2<int>, func)
1042 // M32-DAG: declare dllimport x86_thiscallcc void @"?func@?$ExplicitInstantiationDeclTemplateBase2@H@@QAEXXZ"
1043 // G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN38ExplicitInstantiationDeclTemplateBase2IiE4funcEv
1044 // C32-DAG: define weak_odr dso_local void @_ZN38ExplicitInstantiationDeclTemplateBase2IiE4funcEv
1045 // PS-DAG: declare dllimport void @_ZN38ExplicitInstantiationDeclTemplateBase2IiE4funcEv
1046
1047 namespace pr39496 {
1048 // Make sure dll attribute are inherited by static locals also in template
1049 // specializations.
1050 template <typename> struct __declspec(dllimport) S { int foo() { static int x; return x++; } };
1051 int foo() { S<int> s; return s.foo(); }
1052 // MO1-DAG: @"?x@?{{1|2}}??foo@?$S@H@pr39496@@Q{{[A-Z]*}}HXZ@4HA" = available_externally dllimport global i32 0, align 4
1053
1054 template <typename> struct T { int foo() { static int x; return x++; } };
1055 extern template struct __declspec(dllimport) T<int>;
1056 int bar() { T<int> t; return t.foo(); }
1057 // MO1-DAG: @"?x@?{{1|2}}??foo@?$T@H@pr39496@@Q{{[A-Z]*}}HXZ@4HA" = available_externally dllimport global i32 0, align 4
1058
1059 template <typename T> struct __declspec(dllimport) U {
1060 void foo() {
1061 // Don't inherit dllimport to src before attaching the initializer.
1062 static constexpr char src[] = {"hello"};
1063 T arr[sizeof(src)];
1064 }
1065 };
1066 void baz() { U<int> u; u.foo(); } // No diagnostic.
1067
1068 }