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