1 // RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s -DMSABI | FileCheck --check-prefix=MSC --check-prefix=M32 %s 2 // RUN: %clang_cc1 -triple x86_64-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s -DMSABI | FileCheck --check-prefix=MSC --check-prefix=M64 %s 3 // RUN: %clang_cc1 -triple i686-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck --check-prefix=GNU --check-prefix=G32 %s 4 // RUN: %clang_cc1 -triple x86_64-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck --check-prefix=GNU --check-prefix=G64 %s 5 // RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O1 -o - %s -DMSABI | FileCheck --check-prefix=MO1 %s 6 // RUN: %clang_cc1 -triple i686-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O1 -o - %s | FileCheck --check-prefix=GO1 %s 7 8 // CHECK-NOT doesn't play nice with CHECK-DAG, so use separate run lines. 9 // RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s -DMSABI | FileCheck --check-prefix=MSC2 %s 10 // RUN: %clang_cc1 -triple i686-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck --check-prefix=GNU2 %s 11 12 // Helper structs to make templates more expressive. 13 struct ImplicitInst_Imported {}; 14 struct ImplicitInst_NotImported {}; 15 struct ExplicitDecl_Imported {}; 16 struct ExplicitInst_Imported {}; 17 struct ExplicitSpec_Imported {}; 18 struct ExplicitSpec_Def_Imported {}; 19 struct ExplicitSpec_InlineDef_Imported {}; 20 struct ExplicitSpec_NotImported {}; 21 22 #define JOIN2(x, y) x##y 23 #define JOIN(x, y) JOIN2(x, y) 24 #define UNIQ(name) JOIN(name, __LINE__) 25 #define USEVARTYPE(type, var) type UNIQ(use)() { return var; } 26 #define USEVAR(var) USEVARTYPE(int, var) 27 #define USE(func) void UNIQ(use)() { func(); } 28 #define USEMEMFUNC(class, func) void (class::*UNIQ(use)())() { return &class::func; } 29 #define USECLASS(class) void UNIQ(USE)() { class x; } 30 31 //===----------------------------------------------------------------------===// 32 // Globals 33 //===----------------------------------------------------------------------===// 34 35 // Import declaration. 36 // MSC-DAG: @"\01?ExternGlobalDecl@@3HA" = external dllimport global i32 37 // GNU-DAG: @ExternGlobalDecl = external dllimport global i32 38 __declspec(dllimport) extern int ExternGlobalDecl; 39 USEVAR(ExternGlobalDecl) 40 41 // dllimport implies a declaration. 42 // MSC-DAG: @"\01?GlobalDecl@@3HA" = external dllimport global i32 43 // GNU-DAG: @GlobalDecl = external dllimport global i32 44 __declspec(dllimport) int GlobalDecl; 45 USEVAR(GlobalDecl) 46 47 // Redeclarations 48 // MSC-DAG: @"\01?GlobalRedecl1@@3HA" = external dllimport global i32 49 // GNU-DAG: @GlobalRedecl1 = external dllimport global i32 50 __declspec(dllimport) extern int GlobalRedecl1; 51 __declspec(dllimport) extern int GlobalRedecl1; 52 USEVAR(GlobalRedecl1) 53 54 // MSC-DAG: @"\01?GlobalRedecl2a@@3HA" = external dllimport global i32 55 // GNU-DAG: @GlobalRedecl2a = external dllimport global i32 56 __declspec(dllimport) int GlobalRedecl2a; 57 __declspec(dllimport) int GlobalRedecl2a; 58 USEVAR(GlobalRedecl2a) 59 60 // M32-DAG: @"\01?GlobalRedecl2b@@3PAHA" = external dllimport global i32* 61 // M64-DAG: @"\01?GlobalRedecl2b@@3PEAHEA" = external dllimport global i32* 62 // GNU-DAG: @GlobalRedecl2b = external dllimport global i32* 63 int *__attribute__((dllimport)) GlobalRedecl2b; 64 int *__attribute__((dllimport)) GlobalRedecl2b; 65 USEVARTYPE(int*, GlobalRedecl2b) 66 67 // MSC-DAG: @"\01?GlobalRedecl2c@@3HA" = external dllimport global i32 68 // GNU-DAG: @GlobalRedecl2c = external dllimport global i32 69 int GlobalRedecl2c __attribute__((dllimport)); 70 int GlobalRedecl2c __attribute__((dllimport)); 71 USEVAR(GlobalRedecl2c) 72 73 // NB: MSC issues a warning and makes GlobalRedecl3 dllexport. We follow GCC 74 // and drop the dllimport with a warning. 75 // MSC-DAG: @"\01?GlobalRedecl3@@3HA" = external global i32 76 // GNU-DAG: @GlobalRedecl3 = external global i32 77 __declspec(dllimport) extern int GlobalRedecl3; 78 extern int GlobalRedecl3; // dllimport ignored 79 USEVAR(GlobalRedecl3) 80 81 // MSC-DAG: @"\01?ExternalGlobal@ns@@3HA" = external dllimport global i32 82 // GNU-DAG: @_ZN2ns14ExternalGlobalE = external dllimport global i32 83 namespace ns { __declspec(dllimport) int ExternalGlobal; } 84 USEVAR(ns::ExternalGlobal) 85 86 87 88 //===----------------------------------------------------------------------===// 89 // Variable templates 90 //===----------------------------------------------------------------------===// 91 92 // Import declaration. 93 // MSC-DAG: @"\01??$ExternVarTmplDecl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32 94 // GNU-DAG: @_Z17ExternVarTmplDeclI21ImplicitInst_ImportedE = external dllimport global i32 95 template<typename T> __declspec(dllimport) extern int ExternVarTmplDecl; 96 USEVAR(ExternVarTmplDecl<ImplicitInst_Imported>) 97 98 // dllimport implies a declaration. 99 // MSC-DAG: @"\01??$VarTmplDecl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32 100 // GNU-DAG: @_Z11VarTmplDeclI21ImplicitInst_ImportedE = external dllimport global i32 101 template<typename T> __declspec(dllimport) int VarTmplDecl; 102 USEVAR(VarTmplDecl<ImplicitInst_Imported>) 103 104 // Redeclarations 105 // MSC-DAG: @"\01??$VarTmplRedecl1@UImplicitInst_Imported@@@@3HA" = external dllimport global i32 106 // GNU-DAG: @_Z14VarTmplRedecl1I21ImplicitInst_ImportedE = external dllimport global i32 107 template<typename T> __declspec(dllimport) extern int VarTmplRedecl1; 108 template<typename T> __declspec(dllimport) extern int VarTmplRedecl1; 109 USEVAR(VarTmplRedecl1<ImplicitInst_Imported>) 110 111 // MSC-DAG: @"\01??$VarTmplRedecl2@UImplicitInst_Imported@@@@3HA" = external dllimport global i32 112 // GNU-DAG: @_Z14VarTmplRedecl2I21ImplicitInst_ImportedE = external dllimport global i32 113 template<typename T> __declspec(dllimport) int VarTmplRedecl2; 114 template<typename T> __declspec(dllimport) int VarTmplRedecl2; 115 USEVAR(VarTmplRedecl2<ImplicitInst_Imported>) 116 117 // MSC-DAG: @"\01??$VarTmplRedecl3@UImplicitInst_Imported@@@@3HA" = external global i32 118 // GNU-DAG: @_Z14VarTmplRedecl3I21ImplicitInst_ImportedE = external global i32 119 template<typename T> __declspec(dllimport) extern int VarTmplRedecl3; 120 template<typename T> extern int VarTmplRedecl3; // dllimport ignored 121 USEVAR(VarTmplRedecl3<ImplicitInst_Imported>) 122 123 124 // MSC-DAG: @"\01??$ExternalVarTmpl@UImplicitInst_Imported@@@ns@@3HA" = external dllimport global i32 125 // GNU-DAG: @_ZN2ns15ExternalVarTmplI21ImplicitInst_ImportedEE = external dllimport global i32 126 namespace ns { template<typename T> __declspec(dllimport) int ExternalVarTmpl; } 127 USEVAR(ns::ExternalVarTmpl<ImplicitInst_Imported>) 128 129 130 template<typename T> int VarTmpl; 131 template<typename T> __declspec(dllimport) int ImportedVarTmpl; 132 133 // Import implicit instantiation of an imported variable template. 134 // MSC-DAG: @"\01??$ImportedVarTmpl@UImplicitInst_Imported@@@@3HA" = external dllimport global i32 135 // GNU-DAG: @_Z15ImportedVarTmplI21ImplicitInst_ImportedE = external dllimport global i32 136 USEVAR(ImportedVarTmpl<ImplicitInst_Imported>) 137 138 // Import explicit instantiation declaration of an imported variable template. 139 // MSC-DAG: @"\01??$ImportedVarTmpl@UExplicitDecl_Imported@@@@3HA" = external dllimport global i32 140 // GNU-DAG: @_Z15ImportedVarTmplI21ExplicitDecl_ImportedE = external dllimport global i32 141 extern template int ImportedVarTmpl<ExplicitDecl_Imported>; 142 USEVAR(ImportedVarTmpl<ExplicitDecl_Imported>) 143 144 // An explicit instantiation definition of an imported variable template cannot 145 // be imported because the template must be defined which is illegal. 146 147 // Import specialization of an imported variable template. 148 // MSC-DAG: @"\01??$ImportedVarTmpl@UExplicitSpec_Imported@@@@3HA" = external dllimport global i32 149 // GNU-DAG: @_Z15ImportedVarTmplI21ExplicitSpec_ImportedE = external dllimport global i32 150 template<> __declspec(dllimport) int ImportedVarTmpl<ExplicitSpec_Imported>; 151 USEVAR(ImportedVarTmpl<ExplicitSpec_Imported>) 152 153 // Not importing specialization of an imported variable template without 154 // explicit dllimport. 155 // MSC-DAG: @"\01??$ImportedVarTmpl@UExplicitSpec_NotImported@@@@3HA" = global i32 0, align 4 156 // GNU-DAG: @_Z15ImportedVarTmplI24ExplicitSpec_NotImportedE = global i32 0, align 4 157 template<> int ImportedVarTmpl<ExplicitSpec_NotImported>; 158 USEVAR(ImportedVarTmpl<ExplicitSpec_NotImported>) 159 160 // Import explicit instantiation declaration of a non-imported variable template. 161 // MSC-DAG: @"\01??$VarTmpl@UExplicitDecl_Imported@@@@3HA" = external dllimport global i32 162 // GNU-DAG: @_Z7VarTmplI21ExplicitDecl_ImportedE = external dllimport global i32 163 extern template __declspec(dllimport) int VarTmpl<ExplicitDecl_Imported>; 164 USEVAR(VarTmpl<ExplicitDecl_Imported>) 165 166 // Import explicit instantiation definition of a non-imported variable template. 167 // MSC-DAG: @"\01??$VarTmpl@UExplicitInst_Imported@@@@3HA" = external dllimport global i32 168 // GNU-DAG: @_Z7VarTmplI21ExplicitInst_ImportedE = external dllimport global i32 169 template __declspec(dllimport) int VarTmpl<ExplicitInst_Imported>; 170 USEVAR(VarTmpl<ExplicitInst_Imported>) 171 172 // Import specialization of a non-imported variable template. 173 // MSC-DAG: @"\01??$VarTmpl@UExplicitSpec_Imported@@@@3HA" = external dllimport global i32 174 // GNU-DAG: @_Z7VarTmplI21ExplicitSpec_ImportedE = external dllimport global i32 175 template<> __declspec(dllimport) int VarTmpl<ExplicitSpec_Imported>; 176 USEVAR(VarTmpl<ExplicitSpec_Imported>) 177 178 179 180 //===----------------------------------------------------------------------===// 181 // Functions 182 //===----------------------------------------------------------------------===// 183 184 // Import function declaration. 185 // MSC-DAG: declare dllimport void @"\01?decl@@YAXXZ"() 186 // GNU-DAG: declare dllimport void @_Z4declv() 187 __declspec(dllimport) void decl(); 188 USE(decl) 189 190 // extern "C" 191 // MSC-DAG: declare dllimport void @externC() 192 // GNU-DAG: declare dllimport void @externC() 193 extern "C" __declspec(dllimport) void externC(); 194 USE(externC) 195 196 // Import inline function. 197 // MSC-DAG: declare dllimport void @"\01?inlineFunc@@YAXXZ"() 198 // GNU-DAG: declare dllimport void @_Z10inlineFuncv() 199 // MO1-DAG: define available_externally dllimport void @"\01?inlineFunc@@YAXXZ"() 200 // GO1-DAG: define available_externally dllimport void @_Z10inlineFuncv() 201 __declspec(dllimport) inline void inlineFunc() {} 202 USE(inlineFunc) 203 204 // MSC-DAG: declare dllimport void @"\01?inlineDecl@@YAXXZ"() 205 // GNU-DAG: declare dllimport void @_Z10inlineDeclv() 206 // MO1-DAG: define available_externally dllimport void @"\01?inlineDecl@@YAXXZ"() 207 // GO1-DAG: define available_externally dllimport void @_Z10inlineDeclv() 208 __declspec(dllimport) inline void inlineDecl(); 209 void inlineDecl() {} 210 USE(inlineDecl) 211 212 // MSC-DAG: declare dllimport void @"\01?inlineDef@@YAXXZ"() 213 // GNU-DAG: declare dllimport void @_Z9inlineDefv() 214 // MO1-DAG: define available_externally dllimport void @"\01?inlineDef@@YAXXZ"() 215 // GO1-DAG: define available_externally dllimport void @_Z9inlineDefv() 216 __declspec(dllimport) void inlineDef(); 217 inline void inlineDef() {} 218 USE(inlineDef) 219 220 // inline attributes 221 // MSC-DAG: declare dllimport void @"\01?noinline@@YAXXZ"() 222 // GNU-DAG: declare dllimport void @_Z8noinlinev() 223 __declspec(dllimport) __attribute__((noinline)) inline void noinline() {} 224 USE(noinline) 225 226 // MSC2-NOT: @"\01?alwaysInline@@YAXXZ"() 227 // GNU2-NOT: @_Z12alwaysInlinev() 228 __declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline() {} 229 USE(alwaysInline) 230 231 // Redeclarations 232 // MSC-DAG: declare dllimport void @"\01?redecl1@@YAXXZ"() 233 // GNU-DAG: declare dllimport void @_Z7redecl1v() 234 __declspec(dllimport) void redecl1(); 235 __declspec(dllimport) void redecl1(); 236 USE(redecl1) 237 238 // NB: MSC issues a warning and makes redecl2/redecl3 dllexport. We follow GCC 239 // and drop the dllimport with a warning. 240 // MSC-DAG: declare void @"\01?redecl2@@YAXXZ"() 241 // GNU-DAG: declare void @_Z7redecl2v() 242 __declspec(dllimport) void redecl2(); 243 void redecl2(); 244 USE(redecl2) 245 246 // MSC-DAG: define void @"\01?redecl3@@YAXXZ"() 247 // GNU-DAG: define void @_Z7redecl3v() 248 __declspec(dllimport) void redecl3(); 249 void redecl3() {} // dllimport ignored 250 USE(redecl3) 251 252 253 // Friend functions 254 // MSC-DAG: declare dllimport void @"\01?friend1@@YAXXZ"() 255 // GNU-DAG: declare dllimport void @_Z7friend1v() 256 // MSC-DAG: declare void @"\01?friend2@@YAXXZ"() 257 // GNU-DAG: declare void @_Z7friend2v() 258 // MSC-DAG: define void @"\01?friend3@@YAXXZ"() 259 // GNU-DAG: define void @_Z7friend3v() 260 struct FuncFriend { 261 friend __declspec(dllimport) void friend1(); 262 friend __declspec(dllimport) void friend2(); 263 friend __declspec(dllimport) void friend3(); 264 }; 265 __declspec(dllimport) void friend1(); 266 void friend2(); // dllimport ignored 267 void friend3() {} // dllimport ignored 268 USE(friend1) 269 USE(friend2) 270 USE(friend3) 271 272 // Implicit declarations can be redeclared with dllimport. 273 // MSC-DAG: declare dllimport noalias i8* @"\01??2@{{YAPAXI|YAPEAX_K}}@Z"( 274 // GNU-DAG: declare dllimport noalias i8* @_Znw{{[yj]}}( 275 __declspec(dllimport) void* operator new(__SIZE_TYPE__ n); 276 void UNIQ(use)() { ::operator new(42); } 277 278 // MSC-DAG: declare dllimport void @"\01?externalFunc@ns@@YAXXZ"() 279 // GNU-DAG: declare dllimport void @_ZN2ns12externalFuncEv() 280 namespace ns { __declspec(dllimport) void externalFunc(); } 281 USE(ns::externalFunc) 282 283 284 285 //===----------------------------------------------------------------------===// 286 // Function templates 287 //===----------------------------------------------------------------------===// 288 289 // Import function template declaration. 290 // MSC-DAG: declare dllimport void @"\01??$funcTmplDecl@UImplicitInst_Imported@@@@YAXXZ"() 291 // GNU-DAG: declare dllimport void @_Z12funcTmplDeclI21ImplicitInst_ImportedEvv() 292 template<typename T> __declspec(dllimport) void funcTmplDecl(); 293 USE(funcTmplDecl<ImplicitInst_Imported>) 294 295 // Function template definitions cannot be imported. 296 297 // Import inline function template. 298 // MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl1@UImplicitInst_Imported@@@@YAXXZ"() 299 // GNU-DAG: declare dllimport void @_Z15inlineFuncTmpl1I21ImplicitInst_ImportedEvv() 300 // MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl1@UImplicitInst_Imported@@@@YAXXZ"() 301 // GO1-DAG: define available_externally dllimport void @_Z15inlineFuncTmpl1I21ImplicitInst_ImportedEvv() 302 template<typename T> __declspec(dllimport) inline void inlineFuncTmpl1() {} 303 USE(inlineFuncTmpl1<ImplicitInst_Imported>) 304 305 // MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl2@UImplicitInst_Imported@@@@YAXXZ"() 306 // GNU-DAG: declare dllimport void @_Z15inlineFuncTmpl2I21ImplicitInst_ImportedEvv() 307 // MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl2@UImplicitInst_Imported@@@@YAXXZ"() 308 // GO1-DAG: define available_externally dllimport void @_Z15inlineFuncTmpl2I21ImplicitInst_ImportedEvv() 309 template<typename T> inline void __attribute__((dllimport)) inlineFuncTmpl2() {} 310 USE(inlineFuncTmpl2<ImplicitInst_Imported>) 311 312 // MSC-DAG: declare dllimport void @"\01??$inlineFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"() 313 // GNU-DAG: declare dllimport void @_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv() 314 // MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"() 315 // GO1-DAG: define available_externally dllimport void @_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv() 316 template<typename T> __declspec(dllimport) inline void inlineFuncTmplDecl(); 317 template<typename T> void inlineFuncTmplDecl() {} 318 USE(inlineFuncTmplDecl<ImplicitInst_Imported>) 319 320 // MSC-DAG: declare dllimport void @"\01??$inlineFuncTmplDef@UImplicitInst_Imported@@@@YAXXZ"() 321 // GNU-DAG: declare dllimport void @_Z17inlineFuncTmplDefI21ImplicitInst_ImportedEvv() 322 // MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmplDef@UImplicitInst_Imported@@@@YAXXZ"() 323 // GO1-DAG: define available_externally dllimport void @_Z17inlineFuncTmplDefI21ImplicitInst_ImportedEvv() 324 template<typename T> __declspec(dllimport) void inlineFuncTmplDef(); 325 template<typename T> inline void inlineFuncTmplDef() {} 326 USE(inlineFuncTmplDef<ImplicitInst_Imported>) 327 328 329 // Redeclarations 330 // MSC-DAG: declare dllimport void @"\01??$funcTmplRedecl1@UImplicitInst_Imported@@@@YAXXZ"() 331 // GNU-DAG: declare dllimport void @_Z15funcTmplRedecl1I21ImplicitInst_ImportedEvv() 332 template<typename T> __declspec(dllimport) void funcTmplRedecl1(); 333 template<typename T> __declspec(dllimport) void funcTmplRedecl1(); 334 USE(funcTmplRedecl1<ImplicitInst_Imported>) 335 336 // MSC-DAG: declare void @"\01??$funcTmplRedecl2@UImplicitInst_NotImported@@@@YAXXZ"() 337 // GNU-DAG: declare void @_Z15funcTmplRedecl2I24ImplicitInst_NotImportedEvv() 338 template<typename T> __declspec(dllimport) void funcTmplRedecl2(); 339 template<typename T> void funcTmplRedecl2(); // dllimport ignored 340 USE(funcTmplRedecl2<ImplicitInst_NotImported>) 341 342 // MSC-DAG: define linkonce_odr void @"\01??$funcTmplRedecl3@UImplicitInst_NotImported@@@@YAXXZ"() 343 // GNU-DAG: define linkonce_odr void @_Z15funcTmplRedecl3I24ImplicitInst_NotImportedEvv() 344 template<typename T> __declspec(dllimport) void funcTmplRedecl3(); 345 template<typename T> void funcTmplRedecl3() {} // dllimport ignored 346 USE(funcTmplRedecl3<ImplicitInst_NotImported>) 347 348 349 // Function template friends 350 // MSC-DAG: declare dllimport void @"\01??$funcTmplFriend1@UImplicitInst_Imported@@@@YAXXZ"() 351 // GNU-DAG: declare dllimport void @_Z15funcTmplFriend1I21ImplicitInst_ImportedEvv() 352 // MSC-DAG: declare void @"\01??$funcTmplFriend2@UImplicitInst_NotImported@@@@YAXXZ"() 353 // GNU-DAG: declare void @_Z15funcTmplFriend2I24ImplicitInst_NotImportedEvv() 354 // MSC-DAG: define linkonce_odr void @"\01??$funcTmplFriend3@UImplicitInst_NotImported@@@@YAXXZ"() 355 // GNU-DAG: define linkonce_odr void @_Z15funcTmplFriend3I24ImplicitInst_NotImportedEvv() 356 // MSC-DAG: declare dllimport void @"\01??$funcTmplFriend4@UImplicitInst_Imported@@@@YAXXZ"() 357 // GNU-DAG: declare dllimport void @_Z15funcTmplFriend4I21ImplicitInst_ImportedEvv() 358 struct FuncTmplFriend { 359 template<typename T> friend __declspec(dllimport) void funcTmplFriend1(); 360 template<typename T> friend __declspec(dllimport) void funcTmplFriend2(); 361 template<typename T> friend __declspec(dllimport) void funcTmplFriend3(); 362 template<typename T> friend __declspec(dllimport) inline void funcTmplFriend4(); 363 }; 364 template<typename T> __declspec(dllimport) void funcTmplFriend1(); 365 template<typename T> void funcTmplFriend2(); // dllimport ignored 366 template<typename T> void funcTmplFriend3() {} // dllimport ignored 367 template<typename T> inline void funcTmplFriend4() {} 368 USE(funcTmplFriend1<ImplicitInst_Imported>) 369 USE(funcTmplFriend2<ImplicitInst_NotImported>) 370 USE(funcTmplFriend3<ImplicitInst_NotImported>) 371 USE(funcTmplFriend4<ImplicitInst_Imported>) 372 373 // MSC-DAG: declare dllimport void @"\01??$externalFuncTmpl@UImplicitInst_Imported@@@ns@@YAXXZ"() 374 // GNU-DAG: declare dllimport void @_ZN2ns16externalFuncTmplI21ImplicitInst_ImportedEEvv() 375 namespace ns { template<typename T> __declspec(dllimport) void externalFuncTmpl(); } 376 USE(ns::externalFuncTmpl<ImplicitInst_Imported>) 377 378 379 template<typename T> void funcTmpl() {} 380 template<typename T> inline void inlineFuncTmpl() {} 381 template<typename T> __declspec(dllimport) void importedFuncTmplDecl(); 382 template<typename T> __declspec(dllimport) inline void importedFuncTmpl() {} 383 384 // Import implicit instantiation of an imported function template. 385 // MSC-DAG: declare dllimport void @"\01??$importedFuncTmplDecl@UImplicitInst_Imported@@@@YAXXZ"() 386 // GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI21ImplicitInst_ImportedEvv() 387 USE(importedFuncTmplDecl<ImplicitInst_Imported>) 388 389 // MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UImplicitInst_Imported@@@@YAXXZ"() 390 // GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ImplicitInst_ImportedEvv() 391 // MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UImplicitInst_Imported@@@@YAXXZ"() 392 // GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI21ImplicitInst_ImportedEvv() 393 USE(importedFuncTmpl<ImplicitInst_Imported>) 394 395 // Import explicit instantiation declaration of an imported function template. 396 // MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"() 397 // GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitDecl_ImportedEvv() 398 // MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"() 399 // GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI21ExplicitDecl_ImportedEvv() 400 extern template void importedFuncTmpl<ExplicitDecl_Imported>(); 401 USE(importedFuncTmpl<ExplicitDecl_Imported>) 402 403 // Import explicit instantiation definition of an imported function template. 404 // MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"() 405 // GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitInst_ImportedEvv() 406 // MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"() 407 // GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI21ExplicitInst_ImportedEvv() 408 template void importedFuncTmpl<ExplicitInst_Imported>(); 409 USE(importedFuncTmpl<ExplicitInst_Imported>) 410 411 412 // Import specialization of an imported function template. 413 // MSC-DAG: declare dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_Imported@@@@YAXXZ"() 414 // GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI21ExplicitSpec_ImportedEvv() 415 template<> __declspec(dllimport) void importedFuncTmplDecl<ExplicitSpec_Imported>(); 416 USE(importedFuncTmplDecl<ExplicitSpec_Imported>) 417 418 // MSC-DAG-FIXME: declare dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_Def_Imported@@@@YAXXZ"() 419 // MO1-DAG-FIXME: define available_externally dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_Def_Imported@@@@YAXXZ"() 420 #ifdef MSABI 421 //template<> __declspec(dllimport) void importedFuncTmplDecl<ExplicitSpec_Def_Imported>() {} 422 //USE(importedFuncTmplDecl<ExplicitSpec_Def_Imported>) 423 #endif 424 425 // MSC-DAG: declare dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"() 426 // GNU-DAG: declare dllimport void @_Z20importedFuncTmplDeclI31ExplicitSpec_InlineDef_ImportedEvv() 427 // MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmplDecl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"() 428 // GO1-DAG: define available_externally dllimport void @_Z20importedFuncTmplDeclI31ExplicitSpec_InlineDef_ImportedEvv() 429 template<> __declspec(dllimport) inline void importedFuncTmplDecl<ExplicitSpec_InlineDef_Imported>() {} 430 USE(importedFuncTmplDecl<ExplicitSpec_InlineDef_Imported>) 431 432 433 // MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_Imported@@@@YAXXZ"() 434 // GNU-DAG: declare dllimport void @_Z16importedFuncTmplI21ExplicitSpec_ImportedEvv() 435 template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Imported>(); 436 USE(importedFuncTmpl<ExplicitSpec_Imported>) 437 438 // MSC-DAG-FIXME: declare dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"() 439 // MO1-DAG-FIXME: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"() 440 #ifdef MSABI 441 //template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Def_Imported>() {} 442 //USE(importedFuncTmpl<ExplicitSpec_Def_Imported>) 443 #endif 444 445 // MSC-DAG: declare dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"() 446 // GNU-DAG: declare dllimport void @_Z16importedFuncTmplI31ExplicitSpec_InlineDef_ImportedEvv() 447 // MO1-DAG: define available_externally dllimport void @"\01??$importedFuncTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"() 448 // GO1-DAG: define available_externally dllimport void @_Z16importedFuncTmplI31ExplicitSpec_InlineDef_ImportedEvv() 449 template<> __declspec(dllimport) inline void importedFuncTmpl<ExplicitSpec_InlineDef_Imported>() {} 450 USE(importedFuncTmpl<ExplicitSpec_InlineDef_Imported>) 451 452 453 // Not importing specialization of an imported function template without 454 // explicit dllimport. 455 // MSC-DAG: define void @"\01??$importedFuncTmpl@UExplicitSpec_NotImported@@@@YAXXZ"() 456 // GNU-DAG: define void @_Z16importedFuncTmplI24ExplicitSpec_NotImportedEvv() 457 template<> void importedFuncTmpl<ExplicitSpec_NotImported>() {} 458 USE(importedFuncTmpl<ExplicitSpec_NotImported>) 459 460 461 // Import explicit instantiation declaration of a non-imported function template. 462 // MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitDecl_Imported@@@@YAXXZ"() 463 // MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"() 464 // GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitDecl_ImportedEvv() 465 // GNU-DAG: declare dllimport void @_Z14inlineFuncTmplI21ExplicitDecl_ImportedEvv() 466 // MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl@UExplicitDecl_Imported@@@@YAXXZ"() 467 // GO1-DAG: define available_externally dllimport void @_Z14inlineFuncTmplI21ExplicitDecl_ImportedEvv() 468 extern template __declspec(dllimport) void funcTmpl<ExplicitDecl_Imported>(); 469 extern template __declspec(dllimport) void inlineFuncTmpl<ExplicitDecl_Imported>(); 470 USE(funcTmpl<ExplicitDecl_Imported>) 471 USE(inlineFuncTmpl<ExplicitDecl_Imported>) 472 473 474 // Import explicit instantiation definition of a non-imported function template. 475 // MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"() 476 // MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"() 477 // GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv() 478 // GNU-DAG: declare dllimport void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv() 479 // MO1-DAG: define available_externally dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"() 480 // MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"() 481 // GO1-DAG: define available_externally dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv() 482 // GO1-DAG: define available_externally dllimport void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv() 483 template __declspec(dllimport) void funcTmpl<ExplicitInst_Imported>(); 484 template __declspec(dllimport) void inlineFuncTmpl<ExplicitInst_Imported>(); 485 USE(funcTmpl<ExplicitInst_Imported>) 486 USE(inlineFuncTmpl<ExplicitInst_Imported>) 487 488 489 // Import specialization of a non-imported function template. 490 // MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitSpec_Imported@@@@YAXXZ"() 491 // GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitSpec_ImportedEvv() 492 template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Imported>(); 493 USE(funcTmpl<ExplicitSpec_Imported>) 494 495 // MSC-DAG-FIXME: declare dllimport void @"\01??$funcTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"() 496 // MO1-DAG-FIXME: define available_externally dllimport void @"\01??$funcTmpl@UExplicitSpec_Def_Imported@@@@YAXXZ"() 497 #ifdef MSABI 498 //template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Def_Imported>() {} 499 //USE(funcTmpl<ExplicitSpec_Def_Imported>) 500 #endif 501 502 // MSC-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"() 503 // GNU-DAG: declare dllimport void @_Z8funcTmplI31ExplicitSpec_InlineDef_ImportedEvv() 504 // MO1-DAG: define available_externally dllimport void @"\01??$funcTmpl@UExplicitSpec_InlineDef_Imported@@@@YAXXZ"() 505 // GO1-DAG: define available_externally dllimport void @_Z8funcTmplI31ExplicitSpec_InlineDef_ImportedEvv() 506 template<> __declspec(dllimport) inline void funcTmpl<ExplicitSpec_InlineDef_Imported>() {} 507 USE(funcTmpl<ExplicitSpec_InlineDef_Imported>) 508 509 510 511 //===----------------------------------------------------------------------===// 512 // Classes 513 //===----------------------------------------------------------------------===// 514 515 struct __declspec(dllimport) T { 516 void a() {} 517 // MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01?a@T@@QAEXXZ" 518 519 static int b; 520 // MO1-DAG: @"\01?b@T@@2HA" = external dllimport global i32 521 }; 522 USEMEMFUNC(T, a) 523 USEVAR(T::b) 524 525 template <typename T> struct __declspec(dllimport) U { void foo() {} }; 526 // MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01?foo@?$U@H@@QAEXXZ" 527 struct __declspec(dllimport) V : public U<int> { }; 528 USEMEMFUNC(V, foo) 529 530 struct __declspec(dllimport) W { virtual void foo() {} }; 531 USECLASS(W) 532 // vftable: 533 // MO1-DAG: @"\01??_7W@@6B@" = available_externally dllimport unnamed_addr constant [1 x i8*] [i8* bitcast (void (%struct.W*)* @"\01?foo@W@@UAEXXZ" to i8*)] 534 // GO1-DAG: @_ZTV1W = available_externally dllimport unnamed_addr constant [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.W*)* @_ZN1W3fooEv to i8*)] 535 536 struct __declspec(dllimport) KeyFuncClass { 537 constexpr KeyFuncClass() {} 538 virtual void foo(); 539 }; 540 constexpr KeyFuncClass keyFuncClassVar; 541 // G32-DAG: @_ZTV12KeyFuncClass = external dllimport unnamed_addr constant [3 x i8*] 542 543 struct __declspec(dllimport) X : public virtual W {}; 544 USECLASS(X) 545 // vbtable: 546 // MO1-DAG: @"\01??_8X@@7B@" = available_externally dllimport unnamed_addr constant [2 x i32] [i32 0, i32 4] 547 548 struct __declspec(dllimport) Y { 549 int x; 550 }; 551 552 struct __declspec(dllimport) Z { virtual ~Z() {} }; 553 USECLASS(Z) 554 // User-defined dtor: 555 // MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01??1Z@@UAE@XZ" 556 557 namespace DontUseDtorAlias { 558 struct __declspec(dllimport) A { ~A(); }; 559 struct __declspec(dllimport) B : A { ~B(); }; 560 inline A::~A() { } 561 inline B::~B() { } 562 // Emit a real definition of B's constructor; don't alias it to A's. 563 // MO1-DAG: available_externally dllimport x86_thiscallcc void @"\01??1B@DontUseDtorAlias@@QAE@XZ" 564 USECLASS(B) 565 } 566 567 namespace Vtordisp { 568 // Don't dllimport the vtordisp. 569 // MO1-DAG: define linkonce_odr x86_thiscallcc void @"\01?f@?$C@D@Vtordisp@@$4PPPPPPPM@A@AEXXZ" 570 571 class Base { 572 virtual void f() {} 573 }; 574 template <typename T> 575 class __declspec(dllimport) C : virtual public Base { 576 public: 577 C() {} 578 virtual void f() {} 579 }; 580 template class C<char>; 581 } 582 583 namespace ClassTemplateStaticDef { 584 // Regular template static field: 585 template <typename T> struct __declspec(dllimport) S { 586 static int x; 587 }; 588 template <typename T> int S<T>::x; 589 // MSC-DAG: @"\01?x@?$S@H@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0 590 int f() { return S<int>::x; } 591 592 // Partial class template specialization static field: 593 template <typename A> struct T; 594 template <typename A> struct __declspec(dllimport) T<A*> { 595 static int x; 596 }; 597 template <typename A> int T<A*>::x; 598 // M32-DAG: @"\01?x@?$T@PAX@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0 599 int g() { return T<void*>::x; } 600 } 601 602 namespace PR19933 { 603 // Don't dynamically initialize dllimport vars. 604 // MSC2-NOT: @llvm.global_ctors 605 // GNU2-NOT: @llvm.global_ctors 606 607 struct NonPOD { NonPOD(); }; 608 template <typename T> struct A { static NonPOD x; }; 609 template <typename T> NonPOD A<T>::x; 610 template struct __declspec(dllimport) A<int>; 611 // MSC-DAG: @"\01?x@?$A@H@PR19933@@2UNonPOD@2@A" = available_externally dllimport global %"struct.PR19933::NonPOD" zeroinitializer 612 613 int f(); 614 template <typename T> struct B { static int x; }; 615 template <typename T> int B<T>::x = f(); 616 template struct __declspec(dllimport) B<int>; 617 // MSC-DAG: @"\01?x@?$B@H@PR19933@@2HA" = available_externally dllimport global i32 0 618 619 constexpr int g() { return 42; } 620 template <typename T> struct C { static int x; }; 621 template <typename T> int C<T>::x = g(); 622 template struct __declspec(dllimport) C<int>; 623 // MSC-DAG: @"\01?x@?$C@H@PR19933@@2HA" = available_externally dllimport global i32 42 624 } 625