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