brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.4 KiB · 2fca98f Raw
436 lines · cpp
1// RUN: %clang_cc1 -verify -Wno-return-type -Wno-main -std=c++11 -fclang-abi-compat=latest -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s2// RUN: %clang_cc1 -verify -Wno-return-type -Wno-main -std=c++20 -fclang-abi-compat=latest -emit-llvm -triple x86_64-linux-gnu -o - %s | FileCheck %s --check-prefixes=CHECK,CXX203// expected-no-diagnostics4 5namespace test1 {6int x;7template <int& D> class T { };8// CHECK: void @_ZN5test12f0ENS_1TIL_ZNS_1xEEEE(9void f0(T<x> a0) {}10}11 12namespace test1 {13// CHECK: void @_ZN5test12f0Ef14void f0(float) {}15template<void (&)(float)> struct t1 {};16// CHECK: void @_ZN5test12f1ENS_2t1IL_ZNS_2f0EfEEE(17void f1(t1<f0> a0) {}18}19 20namespace test2 {21// CHECK: void @_ZN5test22f0Ef22void f0(float) {}23template<void (*)(float)> struct t1 {};24// CHECK: void @_ZN5test22f1ENS_2t1IXadL_ZNS_2f0EfEEEE(25void f1(t1<f0> a0) {}26}27 28namespace test3 {29// CHECK: void @test3_f030extern "C" void test3_f0(float) {}31template<void (&)(float)> struct t1 {};32// CHECK: void @_ZN5test32f1ENS_2t1IL_Z8test3_f0EEE(33void f1(t1<test3_f0> a0) {}34}35 36namespace test4 {37// CHECK: void @test4_f038extern "C" void test4_f0(float) {}39template<void (*)(float)> struct t1 {};40// CHECK: void @_ZN5test42f1ENS_2t1IXadL_Z8test4_f0EEEE(41void f1(t1<test4_f0> a0) {}42}43 44// CHECK: void @test5_f045extern "C" void test5_f0(float) {}46int main(int) {}47 48namespace test5 {49template<void (&)(float)> struct t1 {};50// CHECK: void @_ZN5test52f1ENS_2t1IL_Z8test5_f0EEE(51void f1(t1<test5_f0> a0) {}52 53template<int (&)(int)> struct t2 {};54// CHECK: void @_ZN5test52f2ENS_2t2IL_Z4mainEEE55void f2(t2<main> a0) {}56}57 58namespace test6 {59struct A { void im0(float); };60// CHECK: void @_ZN5test61A3im0Ef61void A::im0(float) {}62template <void(A::*)(float)> class T { };63// CHECK: void @_ZN5test62f0ENS_1TIXadL_ZNS_1A3im0EfEEEE(64void f0(T<&A::im0> a0) {}65}66 67namespace test7 {68  template<typename T>69  struct meta {70    static const unsigned value = sizeof(T);71  };72 73  template<unsigned> struct int_c {74    typedef float type;75  };76 77  template<typename T>78  struct X {79    template<typename U>80    X(U*, typename int_c<(meta<T>::value + meta<U>::value)>::type *) { }81  };82 83  // CHECK: define weak_odr {{.*}} @_ZN5test71XIiEC1IdEEPT_PNS_5int_cIXplL_ZNS_4metaIiE5valueEEsr4metaIS3_EE5valueEE4typeE(84  template X<int>::X(double*, float*);85}86 87namespace test8 {88  template<typename T>89  struct meta {90    struct type {91      static const unsigned value = sizeof(T);92    };93  };94 95  template<unsigned> struct int_c {96    typedef float type;97  };98 99  template<typename T>100  void f(int_c<meta<T>::type::value>) { }101 102  // CHECK-LABEL: define weak_odr {{.*}}void @_ZN5test81fIiEEvNS_5int_cIXsr4metaIT_E4typeE5valueEEE(103  template void f<int>(int_c<sizeof(int)>);104}105 106namespace test9 {107  template<typename T>108  struct supermeta {109    template<typename U>110    struct apply {111      typedef T U::*type;112    };113  };114 115  struct X { };116 117  template<typename T, typename U>118  typename supermeta<T>::template apply<U>::type f();119 120  void test_f() {121    // CHECK: @_ZN5test91fIiNS_1XEEENS_9supermetaIT_E5applyIT0_E4typeEv()122    // Note: GCC incorrectly mangles this as123    // _ZN5test91fIiNS_1XEEENS_9supermetaIT_E5apply4typeEv, while EDG124    // gets it right.125    f<int, X>();126  }127}128 129namespace test10 {130  template<typename T>131  struct X {132    template<typename U>133    struct definition {134    };135  };136 137  // CHECK: _ZN6test101fIidEENS_1XIT_E10definitionIT0_EES2_S5_138  template<typename T, typename U>139  typename X<T>::template definition<U> f(T, U) { }140 141  void g(int i, double d) {142    f(i, d);143  }144}145 146// Report from cxx-abi-dev, 2012.01.04.147namespace test11 {148  int cmp(char a, char b);149  template <typename T, int (*cmp)(T, T)> struct A {};150  template <typename T> void f(A<T,cmp> &) {}151  template void f<char>(A<char,cmp> &);152  // CHECK: @_ZN6test111fIcEEvRNS_1AIT_L_ZNS_3cmpEccEEE(153}154 155namespace test12 {156  // Make sure we can mangle non-type template args with internal linkage.157  static int f() {}158  const int n = 10;159  template<typename T, T v> void test() {}160  void use() {161    // CHECK-LABEL: define internal {{.*}}void @_ZN6test124testIFivETnT_XadL_ZNS_L1fEvEEEEvv(162    test<int(), &f>();163    // CHECK-LABEL: define internal {{.*}}void @_ZN6test124testIRFivETnT_L_ZNS_L1fEvEEEvv(164    test<int(&)(), f>();165    // CHECK-LABEL: define internal {{.*}}void @_ZN6test124testIPKiTnT_XadL_ZNS_L1nEEEEEvv(166    test<const int*, &n>();167    // CHECK-LABEL: define internal {{.*}}void @_ZN6test124testIRKiTnT_L_ZNS_L1nEEEEvv(168    test<const int&, n>();169  }170}171 172// Test the boundary condition of minimal signed integers.173namespace test13 {174  template <char c> char returnChar() { return c; }175  template char returnChar<-128>();176  // CHECK: @_ZN6test1310returnCharILcn128EEEcv()177 178  template <short s> short returnShort() { return s; }179  template short returnShort<-32768>();180  // CHECK: @_ZN6test1311returnShortILsn32768EEEsv()181}182 183namespace test14 {184  template <typename> inline int inl(bool b) {185    if (b) {186      static struct {187        int field;188      } a;189      // CHECK: @_ZZN6test143inlIvEEibE1a190 191      return a.field;192    } else {193      static struct {194        int field;195      } a;196      // CHECK: @_ZZN6test143inlIvEEibE1a_0197 198      return a.field;199    }200  }201 202  int call(bool b) { return inl<void>(b); }203}204 205namespace std {206template <class _Tp, _Tp...> struct integer_sequence {};207}208 209namespace test15 {210template <int N>211__make_integer_seq<std::integer_sequence, int, N> make() {}212template __make_integer_seq<std::integer_sequence, int, 5> make<5>();213// CHECK: define weak_odr {{.*}} @_ZN6test154makeILi5EEE18__make_integer_seqISt16integer_sequenceiXT_EEv(214}215 216namespace test16 {217  // Ensure we properly form substitutions for template names in prefixes.218  // CHECK: @_ZN6test161fINS_1TEEEvNT_1UIiE1VIiEENS5_IfEE219  template<typename T> void f(typename T::template U<int>::template V<int>, typename T::template U<int>::template V<float>);220  struct T { template<typename I> struct U { template<typename J> using V = int; }; };221  void g() { f<T>(1, 2); }222}223 224#if __cplusplus >= 202002L225namespace cxx20 {226  template<auto> struct A {};227  template<typename T, T V> struct B {};228  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AILf3f800000EEE(229  void f(A<1.0f>) {}230  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AILd3ff0000000000000EEE(231  void f(A<1.0>) {}232  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AILe3fff8000000000000000EEE(233  void f(A<1.0l>) {}234  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXtlCiLi0ELi1EEEEE(235  void f(A<1i>) {}236  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXtlCdLd0000000000000000ELd3ff0000000000000EEEEE(237  void f(A<1.0i>) {}238 239  int x;240  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXadL_ZNS_1xEEEEE(241  void f(A<&x>) {}242  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIPiXadL_ZNS_1xEEEEE(243  void f(B<int*, &x>) {}244  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXcvPKiadL_ZNS_1xEEEEE(245  void f(A<(const int*)&x>) {}246  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIPKiXadL_ZNS_1xEEEEE(247  void f(B<const int*, &x>) {}248  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXcvPvadL_ZNS_1xEEEEE(249  void f(A<(void*)&x>) {}250  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIPvXadL_ZNS_1xEEEEE(251  void f(B<void*, (void*)&x>) {}252  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXcvPKvadL_ZNS_1xEEEEE(253  void f(A<(const void*)&x>) {}254  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIPKvXadL_ZNS_1xEEEEE(255  void f(B<const void*, (const void*)&x>) {}256 257  struct Q { int x; } q;258 259  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXadsoiL_ZNS_1qEEEEEE(260  void f(A<&q.x>) {}261  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIPiXadsoiL_ZNS_1qEEEEEE(262  void f(B<int*, &q.x>) {}263  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXadsoKiL_ZNS_1qEEEEEE(264  void f(A<(const int*)&q.x>) {}265  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIPKiXadsoS1_L_ZNS_1qEEEEEE266  void f(B<const int*, (const int*)&q.x>) {}267  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXcvPvadsoiL_ZNS_1qEEEEEE(268  void f(A<(void*)&q.x>) {}269  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIPvXadsoiL_ZNS_1qEEEEEE(270  void f(B<void*, (void*)&q.x>) {}271  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXcvPKvadsoiL_ZNS_1qEEEEEE(272  void f(A<(const void*)&q.x>) {}273  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIPKvXadsoiL_ZNS_1qEEEEEE(274  void f(B<const void*, (const void*)&q.x>) {}275 276  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXadL_ZNS_1Q1xEEEEE(277  void f(A<&Q::x>) {}278  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIMNS_1QEiXadL_ZNS1_1xEEEEE279  void f(B<int Q::*, &Q::x>) {}280  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXcvMNS_1QEKiadL_ZNS1_1xEEEEE(281  void f(A<(const int Q::*)&Q::x>) {}282  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIMNS_1QEKiXadL_ZNS1_1xEEEEE(283  void f(B<const int Q::*, (const int Q::*)&Q::x>) {}284 285  struct R : Q {};286 287  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXmcMNS_1REiadL_ZNS_1Q1xEEEEEE(288  void f(A<(int R::*)&Q::x>) {}289  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIMNS_1REiXmcS2_adL_ZNS_1Q1xEEEEEE(290  void f(B<int R::*, (int R::*)&Q::x>) {}291  // CXX20: define {{.*}} @_ZN5cxx201fENS_1AIXmcMNS_1REKiadL_ZNS_1Q1xEEEEEE(292  void f(A<(const int R::*)&Q::x>) {}293  // CXX20: define {{.*}} @_ZN5cxx201fENS_1BIMNS_1REKiXmcS3_adL_ZNS_1Q1xEEEEEE(294  void f(B<const int R::*, (const int R::*)&Q::x>) {}295}296#endif297 298namespace test17 {299  // Ensure we mangle the types for non-type template arguments if we've lost300  // track of argument / parameter correspondence.301  template<int A, int ...B> struct X {};302 303  // CHECK: define {{.*}} @_ZN6test171fILi1EJLi2ELi3ELi4EEEEvNS_1XIXT_EJLi5EXspT0_ELi6EEEE304  template<int D, int ...C> void f(X<D, 5u, C..., 6u>) {}305  void g() { f<1, 2, 3, 4>({}); }306 307  // Note: there is no J...E here, because we can't form a pack argument, and308  // the 5u and 6u are mangled with the original type 'j' (unsigned int) not309  // with the resolved type 'i' (signed int).310  // CHECK: define {{.*}} @_ZN6test171hILi4EJLi1ELi2ELi3EEEEvNS_1XIXspT0_ELj5EXT_ELj6EEE311  template<int D, int ...C> void h(X<C..., 5u, D, 6u>) {}312  void i() { h<4, 1, 2, 3>({}); }313 314#if __cplusplus >= 201402L315  template<int A, const volatile int*> struct Y {};316  int n;317  // Case 1: &n is a resolved template argument, with a known parameter:318  // mangled with no conversion.319  // CXX20: define {{.*}} @_ZN6test172j1ILi1EEEvNS_1YIXT_EXadL_ZNS_1nEEEEE320  template<int N> void j1(Y<N, (const int*)&n>) {}321  // Case 2: &n is an unresolved template argument, with an unknown322  // corresopnding parameter: mangled as the source expression.323  // CXX20: define {{.*}} @_ZN6test172j2IJLi1EEEEvNS_1YIXspT_EXcvPKiadL_ZNS_1nEEEEE324  template<int ...Ns> void j2(Y<Ns..., (const int*)&n>) {}325  // Case 3: &n is a resolved template argument, with a known parameter, but326  // for a template that can be overloaded on type: mangled with the parameter type.327  // CXX20: define {{.*}} @_ZN6test172j3ILi1EEEvDTplT_clL_ZNS_1yIXcvPVKiadL_ZNS_1nEEEEEivEEE328  template<const volatile int*> int y();329  template<int N> void j3(decltype(N + y<(const int*)&n>())) {}330  void k() {331    j1<1>(Y<1, &n>());332    j2<1>(Y<1, &n>());333    j3<1>(0);334  }335#endif336}337 338namespace partially_dependent_template_args {339  namespace test1 {340    template<bool B> struct enable { using type = int; };341    template<typename ...> struct and_ { static constexpr bool value = true; };342    template<typename T> inline typename enable<and_<T, T, T>::value>::type f(T) {}343    // FIXME: GCC and ICC form a J...E mangling for the pack here. Clang344    // doesn't do so when mangling an <unresolved-prefix>. It's not clear who's345    // right. See https://github.com/itanium-cxx-abi/cxx-abi/issues/113.346    // CHECK: @_ZN33partially_dependent_template_args5test11fIiEENS0_6enableIXsr4and_IT_S3_S3_EE5valueEE4typeES3_347    void g() { f(0); }348  }349 350  namespace test2 {351    struct X { int n; };352    template<unsigned> int f(X);353 354    template<typename T> void g1(decltype(f<0>(T()))) {}355    template<typename T> void g2(decltype(f<0>({}) + T())) {}356    template<typename T> void g3(decltype(f<0>(X{}) + T())) {}357    template<int N> void g4(decltype(f<0>(X{N})));358 359    // The first of these mangles the unconverted argument Li0E because the360    // callee is unresolved, the rest mangle the converted argument Lj0E361    // because the callee is resolved.362    void h() {363      // CHECK: @_ZN33partially_dependent_template_args5test22g1INS0_1XEEEvDTcl1fILi0EEcvT__EEE364      g1<X>({});365      // CHECK: @_ZN33partially_dependent_template_args5test22g2IiEEvDTplclL_ZNS0_1fILj0EEEiNS0_1XEEilEEcvT__EE366      g2<int>({});367      // CHECK: @_ZN33partially_dependent_template_args5test22g3IiEEvDTplclL_ZNS0_1fILj0EEEiNS0_1XEEtlS3_EEcvT__EE368      g3<int>({});369      // CHECK: @_ZN33partially_dependent_template_args5test22g4ILi0EEEvDTclL_ZNS0_1fILj0EEEiNS0_1XEEtlS3_T_EEE370      g4<0>({});371    }372  }373}374 375namespace fixed_size_parameter_pack {376  template<typename ...T> struct A {377    template<T ...> struct B {};378  };379  template<int ...Ns> void f(A<unsigned, char, long long>::B<0, Ns...>);380  void g() { f<1, 2>({}); }381}382 383namespace type_qualifier {384  template<typename T> using int_t = int;385  template<typename T> void f(decltype(int_t<T*>() + 1)) {}386  // FIXME: This mangling doesn't work: we need to mangle the387  // instantiation-dependent 'int_t' operand.388  // CHECK: @_ZN14type_qualifier1fIPiEEvDTplcvi_ELi1EE389  template void f<int*>(int);390 391  // Note that this template has different constraints but would mangle the392  // same:393  //template<typename T> void f(decltype(int_t<typename T::type>() + 1)) {}394 395  struct impl { using type = void; };396  template<typename T> using alias = impl;397  template<typename T> void g(decltype(alias<T*>::type(), 1)) {}398  // FIXME: Similarly we need to mangle the `T*` in here.399  // CHECK: @_ZN14type_qualifier1gIPiEEvDTcmcvv_ELi1EE400  template void g<int*>(int);401}402 403namespace unresolved_template_specialization_type {404  template <int> struct enable_if {};405  struct Foo {406    static const int value = true;407  };408  struct HashStateBase {409    template <typename> using is_hashable = Foo;410  };411  template <class> struct raw_hash_set {412    template <typename H>413    static enable_if<H::template is_hashable<int>::value>414        AbslHashValue() {}415  };416  template enable_if<true> raw_hash_set<int>::AbslHashValue<HashStateBase>();417  // CHECK: @_ZN39unresolved_template_specialization_type12raw_hash_setIiE13AbslHashValueINS_13HashStateBaseEEENS_9enable_ifIXsrNT_11is_hashableIiEE5valueEEEv418} // namespace unresolved_template_specialization_type419 420namespace GH133610 {421  template <class T> struct A {422    template <class V> struct B { int MEM; };423  };424 425  struct D {};426  struct C: public A<int>::B<D> {};427 428  template <class T, class U, class V>429  auto k(T t, U u, V v) -> decltype (t.U::template B<V>::MEM) { return {}; }430 431  void t() {432    k( C(), A<int>(), D() );433  }434  // CHECK: @_ZN8GH1336101kINS_1CENS_1AIiEENS_1DEEEDtdtfp_sr1U1BIT1_EE3MEMET_T0_S5_435} // namespace GH133610436