brintos

brintos / llvm-project-archived public Read only

0
0
Text · 13.1 KiB · ec4250e Raw
378 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=i386-pc-win32 | FileCheck %s2// RUN: %clang_cc1 -std=c++11 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s3// RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=i386-pc-win32 | FileCheck %s4// RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s5// RUN: %clang_cc1 -std=c++20 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck -check-prefix CXX20-X64 %s6 7// Check that array-to-pointer decay is mangled as the underlying declaration.8extern const char arr[4] = "foo";9template<const char*> struct Decay1 {};10// CHECK: "?decay1@@3U?$Decay1@$1?arr@@3QBDB@@A"11Decay1<arr> decay1;12#if __cplusplus >= 201702L13// Note that this mangling approach can lead to collisions.14template<const void*> struct Decay2 {};15// CXX20-X64: "?decay2a@@3U?$Decay2@$1?arr@@3QBDB@@A"16Decay2<(const void*)arr> decay2a;17// CXX20-X64: "?decay2b@@3U?$Decay2@$1?arr@@3QBDB@@A"18Decay2<(const void*)&arr> decay2b;19#endif20 21template<typename T>22class Class {23 public:24  Class() {}25};26 27class Typename { };28 29template<typename T>30class Nested { };31 32template<bool flag>33class BoolTemplate {34 public:35  BoolTemplate() {}36};37 38template<int param>39class IntTemplate {40 public:41  IntTemplate() {}42};43 44template<unsigned param>45class UnsignedIntTemplate {46public:47  UnsignedIntTemplate() {}48};49 50template<long long param>51class LongLongTemplate {52 public:53  LongLongTemplate() {}54};55 56template<unsigned long long param>57class UnsignedLongLongTemplate {58 public:59  UnsignedLongLongTemplate() {}60};61 62template<>63class BoolTemplate<true> {64 public:65  BoolTemplate() {}66  template<class T> void Foo(T arg) {}67};68 69void template_mangling() {70  Class<Typename> c1;71// CHECK: call {{.*}} @"??0?$Class@VTypename@@@@QAE@XZ"72// X64: call {{.*}} @"??0?$Class@VTypename@@@@QEAA@XZ"73 74  Class<const Typename> c1_const;75// CHECK: call {{.*}} @"??0?$Class@$$CBVTypename@@@@QAE@XZ"76// X64: call {{.*}} @"??0?$Class@$$CBVTypename@@@@QEAA@XZ"77  Class<volatile Typename> c1_volatile;78// CHECK: call {{.*}} @"??0?$Class@$$CCVTypename@@@@QAE@XZ"79// X64: call {{.*}} @"??0?$Class@$$CCVTypename@@@@QEAA@XZ"80  Class<const volatile Typename> c1_cv;81// CHECK: call {{.*}} @"??0?$Class@$$CDVTypename@@@@QAE@XZ"82// X64: call {{.*}} @"??0?$Class@$$CDVTypename@@@@QEAA@XZ"83 84  Class<Nested<Typename> > c2;85// CHECK: call {{.*}} @"??0?$Class@V?$Nested@VTypename@@@@@@QAE@XZ"86// X64: call {{.*}} @"??0?$Class@V?$Nested@VTypename@@@@@@QEAA@XZ"87 88  Class<int * const> c_intpc;89// CHECK: call {{.*}} @"??0?$Class@QAH@@QAE@XZ"90// X64: call {{.*}} @"??0?$Class@QEAH@@QEAA@XZ"91  Class<int()> c_ft;92// CHECK: call {{.*}} @"??0?$Class@$$A6AHXZ@@QAE@XZ"93// X64: call {{.*}} @"??0?$Class@$$A6AHXZ@@QEAA@XZ"94  Class<int[]> c_inti;95// CHECK: call {{.*}} @"??0?$Class@$$BY0A@H@@QAE@XZ"96// X64: call {{.*}} @"??0?$Class@$$BY0A@H@@QEAA@XZ"97  Class<int[5]> c_int5;98// CHECK: call {{.*}} @"??0?$Class@$$BY04H@@QAE@XZ"99// X64: call {{.*}} @"??0?$Class@$$BY04H@@QEAA@XZ"100  Class<const int[5]> c_intc5;101// CHECK: call {{.*}} @"??0?$Class@$$BY04$$CBH@@QAE@XZ"102// X64: call {{.*}} @"??0?$Class@$$BY04$$CBH@@QEAA@XZ"103  Class<int * const[5]> c_intpc5;104// CHECK: call {{.*}} @"??0?$Class@$$BY04QAH@@QAE@XZ"105// X64: call {{.*}} @"??0?$Class@$$BY04QEAH@@QEAA@XZ"106 107  BoolTemplate<false> _false;108// CHECK: call {{.*}} @"??0?$BoolTemplate@$0A@@@QAE@XZ"109// X64: call {{.*}} @"??0?$BoolTemplate@$0A@@@QEAA@XZ"110 111  BoolTemplate<true> _true;112  // PR13158113  _true.Foo(1);114// CHECK: call {{.*}} @"??0?$BoolTemplate@$00@@QAE@XZ"115// X64: call {{.*}} @"??0?$BoolTemplate@$00@@QEAA@XZ"116// CHECK: call {{.*}} @"??$Foo@H@?$BoolTemplate@$00@@QAEXH@Z"117// X64: call {{.*}} @"??$Foo@H@?$BoolTemplate@$00@@QEAAXH@Z"118 119  IntTemplate<0> zero;120// CHECK: call {{.*}} @"??0?$IntTemplate@$0A@@@QAE@XZ"121// X64: call {{.*}} @"??0?$IntTemplate@$0A@@@QEAA@XZ"122 123  IntTemplate<5> five;124// CHECK: call {{.*}} @"??0?$IntTemplate@$04@@QAE@XZ"125// X64: call {{.*}} @"??0?$IntTemplate@$04@@QEAA@XZ"126 127  IntTemplate<11> eleven;128// CHECK: call {{.*}} @"??0?$IntTemplate@$0L@@@QAE@XZ"129// X64: call {{.*}} @"??0?$IntTemplate@$0L@@@QEAA@XZ"130 131  IntTemplate<256> _256;132// CHECK: call {{.*}} @"??0?$IntTemplate@$0BAA@@@QAE@XZ"133// X64: call {{.*}} @"??0?$IntTemplate@$0BAA@@@QEAA@XZ"134 135  IntTemplate<513> _513;136// CHECK: call {{.*}} @"??0?$IntTemplate@$0CAB@@@QAE@XZ"137// X64: call {{.*}} @"??0?$IntTemplate@$0CAB@@@QEAA@XZ"138 139  IntTemplate<1026> _1026;140// CHECK: call {{.*}} @"??0?$IntTemplate@$0EAC@@@QAE@XZ"141// X64: call {{.*}} @"??0?$IntTemplate@$0EAC@@@QEAA@XZ"142 143  IntTemplate<65535> ffff;144// CHECK: call {{.*}} @"??0?$IntTemplate@$0PPPP@@@QAE@XZ"145// X64: call {{.*}} @"??0?$IntTemplate@$0PPPP@@@QEAA@XZ"146 147  IntTemplate<-1>  neg_1;148// CHECK: call {{.*}} @"??0?$IntTemplate@$0?0@@QAE@XZ"149// X64: call {{.*}} @"??0?$IntTemplate@$0?0@@QEAA@XZ"150  IntTemplate<-9>  neg_9;151// CHECK: call {{.*}} @"??0?$IntTemplate@$0?8@@QAE@XZ"152// X64: call {{.*}} @"??0?$IntTemplate@$0?8@@QEAA@XZ"153  IntTemplate<-10> neg_10;154// CHECK: call {{.*}} @"??0?$IntTemplate@$0?9@@QAE@XZ"155// X64: call {{.*}} @"??0?$IntTemplate@$0?9@@QEAA@XZ"156  IntTemplate<-11> neg_11;157// CHECK: call {{.*}} @"??0?$IntTemplate@$0?L@@@QAE@XZ"158// X64: call {{.*}} @"??0?$IntTemplate@$0?L@@@QEAA@XZ"159  160  UnsignedIntTemplate<4294967295> ffffffff;161// CHECK: call {{.*}} @"??0?$UnsignedIntTemplate@$0PPPPPPPP@@@QAE@XZ"162// X64: call {{.*}} @"??0?$UnsignedIntTemplate@$0PPPPPPPP@@@QEAA@XZ"163 164  LongLongTemplate<-9223372036854775807LL-1LL> int64_min;165// CHECK: call {{.*}} @"??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QAE@XZ"166// X64: call {{.*}} @"??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QEAA@XZ"167  LongLongTemplate<9223372036854775807LL>      int64_max;168// CHECK: call {{.*}} @"??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QAE@XZ"169// X64: call {{.*}} @"??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QEAA@XZ"170  UnsignedLongLongTemplate<18446744073709551615ULL> uint64_max;171// CHECK: call {{.*}} @"??0?$UnsignedLongLongTemplate@$0?0@@QAE@XZ"172// X64: call {{.*}} @"??0?$UnsignedLongLongTemplate@$0?0@@QEAA@XZ"173  UnsignedLongLongTemplate<(unsigned long long)-1>  uint64_neg_1;174// CHECK: call {{.*}} @"??0?$UnsignedLongLongTemplate@$0?0@@QAE@XZ"175// X64: call {{.*}} @"??0?$UnsignedLongLongTemplate@$0?0@@QEAA@XZ"176}177 178namespace space {179  template<class T> const T& foo(const T& l) { return l; }180}181// CHECK: "??$foo@H@space@@YAABHABH@Z"182// X64: "??$foo@H@space@@YAAEBHAEBH@Z"183 184void use() {185  space::foo(42);186}187 188// PR13455189typedef void (*FunctionPointer)(void);190 191template <FunctionPointer function>192void FunctionPointerTemplate() {193  function();194}195 196void spam() {197  FunctionPointerTemplate<spam>();198// CHECK: "??$FunctionPointerTemplate@$1?spam@@YAXXZ@@YAXXZ"199// X64: "??$FunctionPointerTemplate@$1?spam@@YAXXZ@@YAXXZ"200}201 202// Unlike Itanium, there is no character code to indicate an argument pack.203// Tested with MSVC 2013, the first version which supports variadic templates.204 205template <typename ...Ts> void variadic_fn_template(const Ts &...args);206template <typename... Ts, typename... Us>207void multi_variadic_fn(Ts... ts, Us... us);208template <typename... Ts, typename C, typename... Us>209void multi_variadic_mixed(Ts... ts, C c, Us... us);210void variadic_fn_instantiate() {211  variadic_fn_template(0, 1, 3, 4);212  variadic_fn_template(0, 1, 'a', "b");213 214  // Directlly consecutive packs are separated by $$Z...215  multi_variadic_fn<int, int>(1, 2, 3, 4, 5);216  multi_variadic_fn<int, int, int>(1, 2, 3, 4, 5);217 218  // ...but not if another template parameter is between them.219  multi_variadic_mixed<int, int>(1, 2, 3);220  multi_variadic_mixed<int, int>(1, 2, 3, 4);221}222// CHECK: "??$variadic_fn_template@HHHH@@YAXABH000@Z"223// X64:   "??$variadic_fn_template@HHHH@@YAXAEBH000@Z"224// CHECK: "??$variadic_fn_template@HHD$$BY01D@@YAXABH0ABDAAY01$$CBD@Z"225// X64:   "??$variadic_fn_template@HHD$$BY01D@@YAXAEBH0AEBDAEAY01$$CBD@Z"226// CHECK: "??$multi_variadic_fn@HH$$ZHHH@@YAXHHHHH@Z"227// X64:   "??$multi_variadic_fn@HH$$ZHHH@@YAXHHHHH@Z"228// CHECK: "??$multi_variadic_fn@HHH$$ZHH@@YAXHHHHH@Z"229// X64:   "??$multi_variadic_fn@HHH$$ZHH@@YAXHHHHH@Z"230// CHECK: "??$multi_variadic_mixed@HHH$$V@@YAXHHH@Z"231// X64:   "??$multi_variadic_mixed@HHH$$V@@YAXHHH@Z"232// CHECK: "??$multi_variadic_mixed@HHHH@@YAXHHHH@Z"233// X64:   "??$multi_variadic_mixed@HHHH@@YAXHHHH@Z"234 235template <typename ...Ts>236struct VariadicClass {237  VariadicClass() { }238  int x;239};240void variadic_class_instantiate() {241  VariadicClass<int, char, bool> a;242  VariadicClass<bool, char, int> b;243}244// CHECK: call {{.*}} @"??0?$VariadicClass@HD_N@@QAE@XZ"245// CHECK: call {{.*}} @"??0?$VariadicClass@_NDH@@QAE@XZ"246 247template <typename T>248struct Second {};249 250template <typename T, template <class> class>251struct Type {};252 253template <template <class> class T>254struct Type2 {};255 256template <template <class> class T, bool B>257struct Thing;258 259template <template <class> class T>260struct Thing<T, false> { };261 262template <template <class> class T>263struct Thing<T, true> { };264 265void template_template_fun(Type<Thing<Second, true>, Second>) { }266// CHECK: "?template_template_fun@@YAXU?$Type@U?$Thing@USecond@@$00@@USecond@@@@@Z"267 268template <typename T>269void template_template_specialization();270 271template <>272void template_template_specialization<void (Type<Thing<Second, true>, Second>)>() {273}274// CHECK: "??$template_template_specialization@$$A6AXU?$Type@U?$Thing@USecond@@$00@@USecond@@@@@Z@@YAXXZ"275 276// PR16788277template <decltype(nullptr)> struct S1 {};278void f(S1<nullptr>) {}279// CHECK: "?f@@YAXU?$S1@$0A@@@@Z"280 281struct record {282  int first;283  int second;284};285template <const record &>286struct type1 {287};288extern const record inst;289void recref(type1<inst>) {}290// CHECK: "?recref@@YAXU?$type1@$1?inst@@3Urecord@@B@@@Z"291 292struct _GUID {};293struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;294 295template <typename T, const _GUID *G = &__uuidof(T)>296struct UUIDType1 {};297 298template <typename T, const _GUID &G = __uuidof(T)>299struct UUIDType2 {};300 301void fun(UUIDType1<uuid> a) {}302// CHECK: "?fun@@YAXU?$UUIDType1@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"303void fun(UUIDType2<uuid> b) {}304// CHECK: "?fun@@YAXU?$UUIDType2@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"305 306template <typename T> struct TypeWithFriendDefinition {307  friend void FunctionDefinedWithInjectedName(TypeWithFriendDefinition<T>) {}308};309// CHECK: call {{.*}} @"?FunctionDefinedWithInjectedName@@YAXU?$TypeWithFriendDefinition@H@@@Z"310void CallFunctionDefinedWithInjectedName() {311  FunctionDefinedWithInjectedName(TypeWithFriendDefinition<int>());312}313// CHECK: @"?FunctionDefinedWithInjectedName@@YAXU?$TypeWithFriendDefinition@H@@@Z"314 315// We need to be able to feed GUIDs through a couple rounds of template316// substitution.317template <const _GUID *G>318struct UUIDType3 {319  void foo() {}320};321template <const _GUID *G>322struct UUIDType4 : UUIDType3<G> {323  void bar() { UUIDType4::foo(); }324};325template struct UUIDType4<&__uuidof(uuid)>;326// CHECK: "?bar@?$UUIDType4@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@QAEXXZ"327// CHECK: "?foo@?$UUIDType3@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@QAEXXZ"328 329#ifdef _WIN64330template<__int128 N> struct Int128 {};331template<unsigned __int128 N> struct UInt128 {};332// X64: define {{.*}} @"?fun_int128@@YAXU?$Int128@$0A@@@@Z"(333void fun_int128(Int128<0>) {}334// X64: define {{.*}} @"?fun_int128@@YAXU?$Int128@$0?0@@@Z"(335void fun_int128(Int128<-1>) {}336// X64: define {{.*}} @"?fun_int128@@YAXU?$Int128@$0DPPPPPPPPPPPPPPPAAAAAAAAAAAAAAAB@@@@Z"(337void fun_int128(Int128<(__int128)9223372036854775807 * (__int128)9223372036854775807>) {}338// X64: define {{.*}} @"?fun_uint128@@YAXU?$UInt128@$0A@@@@Z"(339void fun_uint128(UInt128<0>) {}340// X64: define {{.*}} @"?fun_uint128@@YAXU?$UInt128@$0?0@@@Z"(341void fun_uint128(UInt128<(unsigned __int128)-1>) {}342// X64: define {{.*}} @"?fun_uint128@@YAXU?$UInt128@$0DPPPPPPPPPPPPPPPAAAAAAAAAAAAAAAB@@@@Z"(343void fun_uint128(UInt128<(unsigned __int128)9223372036854775807 * (unsigned __int128)9223372036854775807>) {}344#endif345 346#if __cplusplus >= 202002L347 348template<float> struct Float {};349// CXX20-X64: define {{.*}} @"?f@@YAXU?$Float@$ADPIAAAAA@@@@Z"(350void f(Float<1.0f>) {}351template<auto> struct Auto {};352// CXX20-X64: define {{.*}} @"?f@@YAXU?$Auto@$MMADPIAAAAA@@@@Z"(353void f(Auto<1.0f>) {}354 355struct S2 {356  int arr[2][3];357  int i;358  void fn();359} s2;360 361template<int&> struct TplSubobjectRef {};362// CXX20-X64: define {{.*}} @"?f@@YAXU?$TplSubobjectRef@$CC61?s2@@3US2@@Aarr@@00@01@@@@Z"(363void f(TplSubobjectRef<s2.arr[1][2]>) {}364template<int*> struct TplSubobjectPtr {};365// CXX20-X64: define {{.*}} @"?f@@YAXU?$TplSubobjectPtr@$CC61?s2@@3US2@@Aarr@@00@01@@@@Z"(366void f(TplSubobjectPtr<&s2.arr[1][2]>) {}367 368struct Derived : S2 {};369 370template <int Derived::*> struct TplMemberPtr {};371// CXX20-X64: define {{.*}} @"?f@@YAXU?$TplMemberPtr@$0BI@@@@Z"(372void f(TplMemberPtr<(int Derived::*)&S2::i>) {}373template <void (Derived::*)()> struct TplMemberFnPtr {};374// CXX20-X64: define {{.*}} @"?f@@YAXU?$TplMemberFnPtr@$1?fn@S2@@QEAAXXZ@@@Z"(375void f(TplMemberFnPtr<(void (Derived::*)())&S2::fn>) {}376 377#endif378