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