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