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