2011-10-14 06:29:44 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks -std=c++11 | FileCheck %s
|
2009-02-13 08:10:09 +08:00
|
|
|
struct X { };
|
|
|
|
struct Y { };
|
2009-03-08 07:57:03 +08:00
|
|
|
|
2009-09-17 11:46:43 +08:00
|
|
|
// CHECK: @unmangled_variable = global
|
|
|
|
// CHECK: @_ZN1N1iE = global
|
|
|
|
// CHECK: @_ZZN1N1fEiiE1b = internal global
|
|
|
|
// CHECK: @_ZZN1N1gEvE1a = internal global
|
|
|
|
// CHECK: @_ZGVZN1N1gEvE1a = internal global
|
|
|
|
|
2010-01-24 11:04:27 +08:00
|
|
|
//CHECK: @pr5966_i = external global
|
2013-09-20 09:15:31 +08:00
|
|
|
//CHECK: @_ZL8pr5966_j = internal global
|
2010-01-24 11:04:27 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define zeroext i1 @_ZplRK1YRA100_P1X
|
2009-02-13 08:10:09 +08:00
|
|
|
bool operator+(const Y&, X* (&xs)[100]) { return false; }
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f1s
|
2009-03-08 07:57:03 +08:00
|
|
|
typedef struct { int a; } s;
|
|
|
|
void f(s) { }
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f1e
|
2009-03-08 07:57:03 +08:00
|
|
|
typedef enum { foo } e;
|
|
|
|
void f(e) { }
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f1u
|
2009-03-08 07:57:03 +08:00
|
|
|
typedef union { int a; } u;
|
|
|
|
void f(u) { }
|
2009-03-11 01:07:44 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f1x
|
2009-03-11 01:07:44 +08:00
|
|
|
typedef struct { int a; } x,y;
|
|
|
|
void f(y) { }
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1fv
|
2009-04-01 08:15:23 +08:00
|
|
|
void f() { }
|
2009-04-01 08:58:25 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN1N1fEv
|
2009-04-01 08:58:25 +08:00
|
|
|
namespace N { void f() { } }
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN1N1N1fEv
|
2009-04-01 08:58:25 +08:00
|
|
|
namespace N { namespace N { void f() { } } }
|
2009-04-02 13:55:18 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @unmangled_function
|
2009-04-02 13:55:18 +08:00
|
|
|
extern "C" { namespace N { void unmangled_function() { } } }
|
|
|
|
|
2009-05-17 05:02:39 +08:00
|
|
|
extern "C" { namespace N { int unmangled_variable = 10; } }
|
2009-04-02 13:55:18 +08:00
|
|
|
|
2009-04-03 00:05:20 +08:00
|
|
|
namespace N { int i; }
|
2009-04-03 00:24:45 +08:00
|
|
|
|
|
|
|
namespace N { int f(int, int) { static int b; return b; } }
|
2009-04-14 02:03:33 +08:00
|
|
|
|
|
|
|
namespace N { int h(); void g() { static int a = h(); } }
|
2009-04-30 10:43:43 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1fno
|
2009-04-30 10:43:43 +08:00
|
|
|
void f(__int128_t, __uint128_t) { }
|
2009-05-16 00:09:15 +08:00
|
|
|
|
|
|
|
template <typename T> struct S1 {};
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f2S1IiE
|
2009-05-16 00:09:15 +08:00
|
|
|
void f(S1<int>) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f2S1IdE
|
2009-05-16 00:09:15 +08:00
|
|
|
void f(S1<double>) {}
|
|
|
|
|
|
|
|
template <int N> struct S2 {};
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f2S2ILi100EE
|
2009-05-16 00:09:15 +08:00
|
|
|
void f(S2<100>) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f2S2ILin100EE
|
2009-05-16 00:09:15 +08:00
|
|
|
void f(S2<-100>) {}
|
|
|
|
|
|
|
|
template <bool B> struct S3 {};
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f2S3ILb1EE
|
2009-05-16 00:09:15 +08:00
|
|
|
void f(S3<true>) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1f2S3ILb0EE
|
2009-05-16 00:09:15 +08:00
|
|
|
void f(S3<false>) {}
|
|
|
|
|
2009-05-18 01:41:20 +08:00
|
|
|
struct S;
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1fM1SKFvvE
|
2009-05-18 01:41:20 +08:00
|
|
|
void f(void (S::*)() const) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1fM1SFvvE
|
2009-05-18 01:41:20 +08:00
|
|
|
void f(void (S::*)()) {}
|
2009-09-17 07:53:19 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1fi
|
2009-09-17 07:53:19 +08:00
|
|
|
void f(const int) { }
|
|
|
|
|
2009-09-17 12:02:31 +08:00
|
|
|
template<typename T, typename U> void ft1(U u, T t) { }
|
|
|
|
|
|
|
|
template<typename T> void ft2(T t, void (*)(T), void (*)(T)) { }
|
2009-09-17 11:46:43 +08:00
|
|
|
|
2009-09-18 10:42:01 +08:00
|
|
|
template<typename T, typename U = S1<T> > struct S4 { };
|
|
|
|
template<typename T> void ft3(S4<T>*) { }
|
|
|
|
|
2009-09-18 12:29:09 +08:00
|
|
|
namespace NS {
|
|
|
|
template<typename T> void ft1(T) { }
|
2009-09-18 10:42:01 +08:00
|
|
|
}
|
|
|
|
|
2009-09-21 09:21:10 +08:00
|
|
|
void g1() {
|
2009-09-17 12:02:31 +08:00
|
|
|
// CHECK: @_Z3ft1IidEvT0_T_
|
|
|
|
ft1<int, double>(1, 0);
|
|
|
|
|
|
|
|
// CHECK: @_Z3ft2IcEvT_PFvS0_ES2_
|
|
|
|
ft2<char>(1, 0, 0);
|
2009-09-18 10:42:01 +08:00
|
|
|
|
|
|
|
// CHECK: @_Z3ft3IiEvP2S4IT_2S1IS1_EE
|
|
|
|
ft3<int>(0);
|
2009-09-18 12:29:09 +08:00
|
|
|
|
|
|
|
// CHECK: @_ZN2NS3ft1IiEEvT_
|
|
|
|
NS::ft1<int>(1);
|
|
|
|
}
|
|
|
|
|
2009-09-21 09:21:10 +08:00
|
|
|
// Expressions
|
|
|
|
template<int I> struct S5 { };
|
|
|
|
|
|
|
|
template<int I> void ft4(S5<I>) { }
|
|
|
|
void g2() {
|
|
|
|
// CHECK: @_Z3ft4ILi10EEv2S5IXT_EE
|
|
|
|
ft4(S5<10>());
|
|
|
|
|
|
|
|
// CHECK: @_Z3ft4ILi20EEv2S5IXT_EE
|
|
|
|
ft4(S5<20>());
|
|
|
|
}
|
|
|
|
|
2009-09-18 12:29:09 +08:00
|
|
|
extern "C++" {
|
|
|
|
// CHECK: @_Z1hv
|
|
|
|
void h() { }
|
2009-09-18 00:12:20 +08:00
|
|
|
}
|
2009-09-18 12:29:09 +08:00
|
|
|
|
2009-09-23 01:23:30 +08:00
|
|
|
// PR5019
|
|
|
|
extern "C" { struct a { int b; }; }
|
|
|
|
|
|
|
|
// CHECK: @_Z1fP1a
|
|
|
|
int f(struct a *x) {
|
|
|
|
return x->b;
|
|
|
|
}
|
2009-09-23 04:33:31 +08:00
|
|
|
|
|
|
|
// PR5017
|
|
|
|
extern "C" {
|
|
|
|
struct Debug {
|
2009-12-22 14:36:32 +08:00
|
|
|
const Debug& operator<< (unsigned a) const { return *this; }
|
2009-09-23 04:33:31 +08:00
|
|
|
};
|
|
|
|
Debug dbg;
|
|
|
|
// CHECK: @_ZNK5DebuglsEj
|
|
|
|
int main(void) { dbg << 32 ;}
|
|
|
|
}
|
2009-09-26 10:26:02 +08:00
|
|
|
|
|
|
|
template<typename T> struct S6 {
|
|
|
|
typedef int B;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T> void ft5(typename S6<T>::B) { }
|
|
|
|
// CHECK: @_Z3ft5IiEvN2S6IT_E1BE
|
|
|
|
template void ft5<int>(int);
|
2009-09-27 04:13:56 +08:00
|
|
|
|
|
|
|
template<typename T> class A {};
|
|
|
|
|
|
|
|
namespace NS {
|
|
|
|
template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; }
|
|
|
|
}
|
|
|
|
|
2009-09-27 06:18:22 +08:00
|
|
|
// CHECK: @_ZN2NSeqIcEEbRK1AIT_ES5_
|
2009-09-27 04:13:56 +08:00
|
|
|
template bool NS::operator==(const ::A<char>&, const ::A<char>&);
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; }
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: @_ZSteqIcEbRK1AIT_ES4_
|
|
|
|
template bool std::operator==(const ::A<char>&, const ::A<char>&);
|
|
|
|
|
2009-09-27 08:38:53 +08:00
|
|
|
struct S {
|
|
|
|
typedef int U;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T> typename T::U ft6(const T&) { return 0; }
|
|
|
|
|
|
|
|
// CHECK: @_Z3ft6I1SENT_1UERKS1_
|
|
|
|
template int ft6<S>(const S&);
|
2009-09-28 04:11:34 +08:00
|
|
|
|
2011-04-28 07:09:49 +08:00
|
|
|
template<typename> struct __is_scalar_type {
|
2012-09-14 06:00:12 +08:00
|
|
|
enum { __value = 1 };
|
2009-09-28 04:11:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<bool, typename> struct __enable_if { };
|
|
|
|
|
|
|
|
template<typename T> struct __enable_if<true, T> {
|
|
|
|
typedef T __type;
|
|
|
|
};
|
|
|
|
|
|
|
|
// PR5063
|
2011-04-28 07:09:49 +08:00
|
|
|
template<typename T> typename __enable_if<__is_scalar_type<T>::__value, void>::__type ft7() { }
|
2009-09-28 04:11:34 +08:00
|
|
|
|
2011-06-22 06:12:46 +08:00
|
|
|
// CHECK: @_Z3ft7IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv
|
2009-09-28 04:11:34 +08:00
|
|
|
template void ft7<int>();
|
2011-06-22 06:12:46 +08:00
|
|
|
// CHECK: @_Z3ft7IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv
|
2009-09-28 04:11:34 +08:00
|
|
|
template void ft7<void*>();
|
2009-10-07 05:58:01 +08:00
|
|
|
|
|
|
|
// PR5144
|
|
|
|
extern "C" {
|
|
|
|
void extern_f(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: @extern_f
|
|
|
|
void extern_f(void) { }
|
|
|
|
|
2009-10-07 09:45:02 +08:00
|
|
|
struct S7 {
|
2009-12-05 06:33:25 +08:00
|
|
|
S7();
|
2009-10-07 09:45:02 +08:00
|
|
|
|
2009-12-05 06:33:25 +08:00
|
|
|
struct S { S(); };
|
2009-10-07 09:45:02 +08:00
|
|
|
struct {
|
|
|
|
S s;
|
|
|
|
} a;
|
|
|
|
};
|
|
|
|
|
|
|
|
// PR5139
|
|
|
|
// CHECK: @_ZN2S7C2Ev
|
2012-11-14 09:52:05 +08:00
|
|
|
// CHECK: @_ZN2S7Ut_C1Ev
|
2013-12-09 22:51:17 +08:00
|
|
|
// CHECK: @_ZN2S7C1Ev
|
2009-10-07 09:45:02 +08:00
|
|
|
S7::S7() {}
|
|
|
|
|
2009-11-06 10:50:19 +08:00
|
|
|
// PR5063
|
2011-04-28 07:09:49 +08:00
|
|
|
template<typename T> typename __enable_if<(__is_scalar_type<T>::__value), void>::__type ft8() { }
|
2011-06-22 06:12:46 +08:00
|
|
|
// CHECK: @_Z3ft8IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv
|
2009-11-06 10:50:19 +08:00
|
|
|
template void ft8<int>();
|
2011-06-22 06:12:46 +08:00
|
|
|
// CHECK: @_Z3ft8IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv
|
2009-11-06 10:50:19 +08:00
|
|
|
template void ft8<void*>();
|
2009-12-14 09:45:37 +08:00
|
|
|
|
2009-12-16 13:48:46 +08:00
|
|
|
// PR5796
|
|
|
|
namespace PR5796 {
|
2011-04-28 07:09:49 +08:00
|
|
|
template<typename> struct __is_scalar_type {
|
2012-09-14 06:00:12 +08:00
|
|
|
enum { __value = 0 };
|
2009-12-16 13:48:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<bool, typename> struct __enable_if {};
|
|
|
|
template<typename T> struct __enable_if<true, T> { typedef T __type; };
|
|
|
|
template<typename T>
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN6PR57968__fill_aIiEENS_11__enable_ifIXntsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv
|
2011-04-28 07:09:49 +08:00
|
|
|
typename __enable_if<!__is_scalar_type<T>::__value, void>::__type __fill_a() { };
|
2009-12-16 13:48:46 +08:00
|
|
|
|
|
|
|
void f() { __fill_a<int>(); }
|
|
|
|
}
|
|
|
|
|
2009-12-14 09:45:37 +08:00
|
|
|
namespace Expressions {
|
|
|
|
// Unary operators.
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i
|
2009-12-14 09:45:37 +08:00
|
|
|
template <int i> void f1(int (*)[(-i) + 2]) { };
|
|
|
|
template void f1<1>(int (*)[1]);
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN11Expressions2f2ILi1EEEvPApsT__i
|
2009-12-14 09:45:37 +08:00
|
|
|
template <int i> void f2(int (*)[+i]) { };
|
|
|
|
template void f2<1>(int (*)[1]);
|
|
|
|
|
|
|
|
// Binary operators.
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i
|
2009-12-14 09:45:37 +08:00
|
|
|
template <int i> void f3(int (*)[i+i]) { };
|
|
|
|
template void f3<1>(int (*)[2]);
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i
|
2009-12-14 09:45:37 +08:00
|
|
|
template <int i> void f4(int (*)[2 + i+i]) { };
|
|
|
|
template void f4<1>(int (*)[4]);
|
|
|
|
|
|
|
|
// The ternary operator.
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i
|
2009-12-14 09:45:37 +08:00
|
|
|
template <bool b> void f4(int (*)[b ? 1 : 2]) { };
|
|
|
|
template void f4<true>(int (*)[1]);
|
|
|
|
}
|
2009-12-22 14:36:32 +08:00
|
|
|
|
|
|
|
struct Ops {
|
|
|
|
Ops& operator+(const Ops&);
|
|
|
|
Ops& operator-(const Ops&);
|
|
|
|
Ops& operator&(const Ops&);
|
|
|
|
Ops& operator*(const Ops&);
|
|
|
|
|
|
|
|
void *v;
|
|
|
|
};
|
|
|
|
|
2020-05-19 02:29:11 +08:00
|
|
|
// CHECK-LABEL: define nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %struct.Ops* @_ZN3OpsplERKS_
|
2009-12-22 14:36:32 +08:00
|
|
|
Ops& Ops::operator+(const Ops&) { return *this; }
|
2020-05-19 02:29:11 +08:00
|
|
|
// CHECK-LABEL: define nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %struct.Ops* @_ZN3OpsmiERKS_
|
2009-12-22 14:36:32 +08:00
|
|
|
Ops& Ops::operator-(const Ops&) { return *this; }
|
2020-05-19 02:29:11 +08:00
|
|
|
// CHECK-LABEL: define nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %struct.Ops* @_ZN3OpsanERKS_
|
2009-12-22 14:36:32 +08:00
|
|
|
Ops& Ops::operator&(const Ops&) { return *this; }
|
2020-05-19 02:29:11 +08:00
|
|
|
// CHECK-LABEL: define nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %struct.Ops* @_ZN3OpsmlERKS_
|
2009-12-22 14:36:32 +08:00
|
|
|
Ops& Ops::operator*(const Ops&) { return *this; }
|
|
|
|
|
2009-12-24 03:30:55 +08:00
|
|
|
// PR5861
|
|
|
|
namespace PR5861 {
|
|
|
|
template<bool> class P;
|
|
|
|
template<> class P<true> {};
|
|
|
|
|
|
|
|
template<template <bool> class, bool>
|
|
|
|
struct Policy { };
|
|
|
|
|
|
|
|
template<typename T, typename = Policy<P, true> > class Alloc
|
|
|
|
{
|
|
|
|
T *allocate(int, const void*) { return 0; }
|
|
|
|
};
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr i8* @_ZN6PR58615AllocIcNS_6PolicyINS_1PELb1EEEE8allocateEiPKv
|
2009-12-24 03:30:55 +08:00
|
|
|
template class Alloc<char>;
|
|
|
|
}
|
2009-12-24 06:31:44 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z1fU13block_pointerFiiiE
|
2010-01-07 17:36:51 +08:00
|
|
|
void f(int (^)(int, int)) { }
|
|
|
|
|
2010-01-24 11:04:27 +08:00
|
|
|
void pr5966_foo() {
|
|
|
|
extern int pr5966_i;
|
|
|
|
pr5966_i = 0;
|
|
|
|
}
|
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
static int pr5966_j;
|
2010-01-24 11:04:27 +08:00
|
|
|
|
|
|
|
void pr5966_bar() {
|
2013-09-20 09:15:31 +08:00
|
|
|
pr5966_j = 0;
|
2010-01-24 11:04:27 +08:00
|
|
|
}
|
2010-02-04 09:42:13 +08:00
|
|
|
|
|
|
|
namespace test0 {
|
|
|
|
int ovl(int x);
|
|
|
|
char ovl(double x);
|
|
|
|
|
|
|
|
template <class T> void f(T, char (&buffer)[sizeof(ovl(T()))]) {}
|
|
|
|
|
|
|
|
void test0() {
|
|
|
|
char buffer[1];
|
|
|
|
f(0.0, buffer);
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test05test0Ev()
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN5test01fIdEEvT_RAszcl3ovlcvS1__EE_c(
|
2010-02-04 09:42:13 +08:00
|
|
|
|
|
|
|
void test1() {
|
|
|
|
char buffer[sizeof(int)];
|
|
|
|
f(1, buffer);
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test05test1Ev()
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN5test01fIiEEvT_RAszcl3ovlcvS1__EE_c(
|
2010-02-04 09:42:13 +08:00
|
|
|
|
|
|
|
template <class T> void g(char (&buffer)[sizeof(T() + 5.0f)]) {}
|
|
|
|
void test2() {
|
|
|
|
char buffer[sizeof(float)];
|
|
|
|
g<float>(buffer);
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN5test01gIfEEvRAszplcvT__ELf40a00000E_c(
|
2010-02-04 09:42:13 +08:00
|
|
|
|
|
|
|
template <class T> void h(char (&buffer)[sizeof(T() + 5.0)]) {}
|
|
|
|
void test3() {
|
|
|
|
char buffer[sizeof(double)];
|
|
|
|
h<float>(buffer);
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN5test01hIfEEvRAszplcvT__ELd4014000000000000E_c(
|
2010-02-04 10:56:29 +08:00
|
|
|
|
|
|
|
template <class T> void j(char (&buffer)[sizeof(T().buffer)]) {}
|
|
|
|
struct A { double buffer[128]; };
|
|
|
|
void test4() {
|
|
|
|
char buffer[1024];
|
|
|
|
j<A>(buffer);
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN5test01jINS_1AEEEvRAszdtcvT__E6buffer_c(
|
2012-01-31 02:36:31 +08:00
|
|
|
|
|
|
|
template <class T> void k(char (&buffer)[sizeof(T() + 0.0f)]) {}
|
|
|
|
void test5() {
|
|
|
|
char buffer[sizeof(float)];
|
|
|
|
k<float>(buffer);
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN5test01kIfEEvRAszplcvT__ELf00000000E_c(
|
2012-01-31 02:36:31 +08:00
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
}
|
2010-02-06 04:45:00 +08:00
|
|
|
|
|
|
|
namespace test1 {
|
|
|
|
template<typename T> struct X { };
|
|
|
|
template<template<class> class Y, typename T> void f(Y<T>) { }
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN5test11fINS_1XEiEEvT_IT0_E
|
2010-02-06 04:45:00 +08:00
|
|
|
template void f(X<int>);
|
|
|
|
}
|
2010-02-06 12:52:27 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal void @_ZL27functionWithInternalLinkagev()
|
2010-02-06 12:52:27 +08:00
|
|
|
static void functionWithInternalLinkage() { }
|
|
|
|
void g() { functionWithInternalLinkage(); }
|
2010-03-02 07:49:17 +08:00
|
|
|
|
|
|
|
namespace test2 {
|
|
|
|
template <class T> decltype(((T*) 0)->member) read_member(T& obj) {
|
|
|
|
return obj.member;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A { int member; } obj;
|
|
|
|
int test() {
|
|
|
|
return read_member(obj);
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZN5test211read_memberINS_1AEEEDtptcvPT_Li0E6memberERS2_(
|
2010-03-02 07:49:17 +08:00
|
|
|
}
|
|
|
|
|
2011-04-24 16:23:24 +08:00
|
|
|
// rdar://problem/9280586
|
2010-03-02 07:49:17 +08:00
|
|
|
namespace test3 {
|
|
|
|
struct AmbiguousBase { int ab; };
|
|
|
|
struct Path1 : AmbiguousBase { float p; };
|
|
|
|
struct Path2 : AmbiguousBase { double p; };
|
|
|
|
struct Derived : Path1, Path2 { };
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZN5test38get_ab_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E2abERS2_(
|
2011-04-24 16:23:24 +08:00
|
|
|
template <class T> decltype(((T*) 0)->Path1::ab) get_ab_1(T &ref) { return ref.Path1::ab; }
|
2010-03-02 07:49:17 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZN5test38get_ab_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E2abERS2_(
|
2011-04-24 16:23:24 +08:00
|
|
|
template <class T> decltype(((T*) 0)->Path2::ab) get_ab_2(T &ref) { return ref.Path2::ab; }
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr float @_ZN5test37get_p_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E1pERS2_(
|
2010-03-02 07:49:17 +08:00
|
|
|
template <class T> decltype(((T*) 0)->Path1::p) get_p_1(T &ref) { return ref.Path1::p; }
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr double @_ZN5test37get_p_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E1pERS2_(
|
2010-03-02 07:49:17 +08:00
|
|
|
template <class T> decltype(((T*) 0)->Path2::p) get_p_2(T &ref) { return ref.Path2::p; }
|
|
|
|
|
|
|
|
Derived obj;
|
|
|
|
void test() {
|
2011-04-24 16:23:24 +08:00
|
|
|
get_ab_1(obj);
|
|
|
|
get_ab_2(obj);
|
2010-03-02 07:49:17 +08:00
|
|
|
get_p_1(obj);
|
|
|
|
get_p_2(obj);
|
|
|
|
}
|
|
|
|
}
|
2010-03-11 22:07:00 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test41gEPNS_3zedIXadL_ZNS_3foo3barEEEEE
|
2010-03-11 22:07:00 +08:00
|
|
|
namespace test4 {
|
|
|
|
struct foo { int bar; };
|
|
|
|
template <int (foo::*)>
|
|
|
|
struct zed {};
|
|
|
|
void g(zed<&foo::bar>*)
|
|
|
|
{}
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test51gEPNS_3zedIXadL_ZNS_3foo3barEEEEE
|
2010-03-11 22:07:00 +08:00
|
|
|
namespace test5 {
|
|
|
|
struct foo { static int bar; };
|
|
|
|
template <int *>
|
|
|
|
struct zed {};
|
|
|
|
void g(zed<&foo::bar>*)
|
|
|
|
{}
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test61gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE
|
2010-03-11 22:07:00 +08:00
|
|
|
namespace test6 {
|
|
|
|
struct foo { int bar(); };
|
|
|
|
template <int (foo::*)()>
|
|
|
|
struct zed {};
|
|
|
|
void g(zed<&foo::bar>*)
|
|
|
|
{}
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test71gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE
|
2010-03-11 22:07:00 +08:00
|
|
|
namespace test7 {
|
|
|
|
struct foo { static int bar(); };
|
|
|
|
template <int (*f)()>
|
|
|
|
struct zed {};
|
|
|
|
void g(zed<&foo::bar>*)
|
|
|
|
{}
|
|
|
|
}
|
2015-02-18 15:47:09 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN5test81AIL_ZNS_1B5valueEEE3incEv
|
2010-03-11 22:07:00 +08:00
|
|
|
namespace test8 {
|
|
|
|
template <int &counter> class A { void inc() { counter++; } };
|
2010-04-10 03:03:51 +08:00
|
|
|
class B { public: static int value; };
|
2010-03-11 22:07:00 +08:00
|
|
|
template class A<B::value>;
|
|
|
|
}
|
2010-03-17 12:28:11 +08:00
|
|
|
// CHECK: declare void @_ZN5test91fIiNS_3barEEEvRKNT0_3baz1XE
|
|
|
|
namespace test9 {
|
|
|
|
template<class T>
|
|
|
|
struct foo {
|
|
|
|
typedef T X;
|
|
|
|
};
|
|
|
|
struct bar {
|
|
|
|
typedef foo<int> baz;
|
|
|
|
};
|
|
|
|
template <class zaz, class zed>
|
|
|
|
void f(const typename zed::baz::X&);
|
|
|
|
void g() {
|
|
|
|
f<int, bar>( 0);
|
|
|
|
}
|
|
|
|
}
|
2010-04-10 05:48:08 +08:00
|
|
|
|
|
|
|
// <rdar://problem/7825453>
|
|
|
|
namespace test10 {
|
|
|
|
template <char P1> struct S {};
|
|
|
|
template <char P2> void f(struct S<false ? 'a' : P2> ) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test101fILc3EEEvNS_1SIXquLb0ELc97ET_EEE(
|
2010-04-10 05:48:08 +08:00
|
|
|
template void f<(char) 3>(struct S<3>);
|
|
|
|
}
|
2010-06-02 12:40:13 +08:00
|
|
|
|
|
|
|
namespace test11 {
|
|
|
|
// CHECK: @_ZN6test111fEz
|
|
|
|
void f(...) { }
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
void f(...);
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: @_ZN6test111A1fEz
|
|
|
|
void A::f(...) { }
|
|
|
|
}
|
2010-06-02 13:07:26 +08:00
|
|
|
|
|
|
|
namespace test12 {
|
|
|
|
|
|
|
|
// CHECK: _ZN6test121fENS_1AILt33000EEE
|
|
|
|
template <unsigned short> struct A { };
|
|
|
|
void f(A<33000>) { }
|
2010-07-14 14:43:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// PR7446
|
|
|
|
namespace test13 {
|
|
|
|
template <template <class> class T> class A {};
|
|
|
|
template <class U> class B {};
|
|
|
|
|
|
|
|
template <template<class> class T> void foo(const A<T> &a) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test133fooINS_1BEEEvRKNS_1AIT_EE(
|
2010-07-14 14:43:17 +08:00
|
|
|
template void foo(const A<B> &a);
|
|
|
|
}
|
2010-07-19 04:49:59 +08:00
|
|
|
|
|
|
|
namespace test14 {
|
|
|
|
extern "C" {
|
|
|
|
struct S {
|
|
|
|
static int a(), x;
|
|
|
|
};
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i32 @_ZN6test141S1aEv
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i32, i32* @_ZN6test141S1xE
|
2010-07-19 04:49:59 +08:00
|
|
|
int S::a() { return S::x; }
|
|
|
|
}
|
|
|
|
}
|
2010-07-24 09:17:35 +08:00
|
|
|
|
|
|
|
// rdar://problem/8204122
|
|
|
|
namespace test15 {
|
|
|
|
enum E { e = 3 };
|
|
|
|
template <int I> struct S {};
|
|
|
|
|
|
|
|
template <int I> void f(S<I + e>) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test151fILi7EEEvNS_1SIXplT_LNS_1EE3EEEE(
|
2010-07-24 09:17:35 +08:00
|
|
|
template void f<7>(S<7 + e>);
|
|
|
|
}
|
2010-08-06 06:02:13 +08:00
|
|
|
|
2010-08-18 05:51:21 +08:00
|
|
|
// rdar://problem/8302148
|
|
|
|
namespace test17 {
|
|
|
|
template <int N> struct A {};
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
static int foo(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T> A<sizeof(T::foo())> func(void);
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6test174testEv()
|
2010-08-18 05:51:21 +08:00
|
|
|
// CHECK: call {{.*}} @_ZN6test174funcINS_1BEEENS_1AIXszclsrT_3fooEEEEv()
|
2010-08-20 08:17:19 +08:00
|
|
|
void test() {
|
|
|
|
func<B>();
|
2010-08-18 05:51:21 +08:00
|
|
|
}
|
|
|
|
}
|
2010-08-19 03:18:59 +08:00
|
|
|
|
|
|
|
// PR7891
|
|
|
|
namespace test18 {
|
|
|
|
struct A {
|
|
|
|
int operator+();
|
|
|
|
int operator-();
|
|
|
|
int operator*();
|
|
|
|
int operator&();
|
|
|
|
};
|
|
|
|
template <int (A::*)()> struct S {};
|
|
|
|
|
|
|
|
template <typename T> void f(S<&T::operator+>) {}
|
|
|
|
template void f<A>(S<&A::operator+>);
|
|
|
|
|
|
|
|
template <typename T> void f(S<&T::operator- >) {}
|
|
|
|
template void f<A>(S<&A::operator- >);
|
|
|
|
|
|
|
|
template <typename T> void f(S<&T::operator*>) {}
|
|
|
|
template void f<A>(S<&A::operator*>);
|
|
|
|
|
|
|
|
template <typename T> void f(S<&T::operator&>) {}
|
|
|
|
template void f<A>(S<&A::operator&>);
|
|
|
|
|
2015-02-14 21:23:54 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onplEEE
|
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onmiEEE
|
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onmlEEE
|
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onanEEE
|
2010-08-19 03:18:59 +08:00
|
|
|
}
|
2010-08-20 08:17:19 +08:00
|
|
|
|
|
|
|
// rdar://problem/8332117
|
|
|
|
namespace test19 {
|
|
|
|
struct A {
|
|
|
|
template <typename T> int f();
|
|
|
|
int operator+();
|
|
|
|
operator int();
|
|
|
|
template <typename T> int operator-();
|
|
|
|
};
|
|
|
|
|
|
|
|
template <int (A::*)()> struct S {};
|
|
|
|
|
|
|
|
template <typename T> void g (S<&T::template f<int> >) {}
|
|
|
|
template <typename T> void g (S<&T::operator+ >) {}
|
|
|
|
template <typename T> void g (S<&T::operator int>) {}
|
|
|
|
template <typename T> void g (S<&T::template operator- <double> >) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_1fIiEEEE(
|
2010-08-20 08:17:19 +08:00
|
|
|
template void g<A>(S<&A::f<int> >);
|
2015-02-14 21:23:54 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_onplEEE(
|
2010-08-20 08:17:19 +08:00
|
|
|
template void g<A>(S<&A::operator+>);
|
2015-02-14 21:23:54 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_oncviEEE(
|
2010-08-20 08:17:19 +08:00
|
|
|
template void g<A>(S<&A::operator int>);
|
2015-02-14 21:23:54 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_onmiIdEEEE(
|
2010-08-20 08:17:19 +08:00
|
|
|
template void g<A>(S<&A::operator-<double> >);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test20 {
|
|
|
|
template <class T> T *f(const T&);
|
|
|
|
template <class T> T *f(T*);
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test205test0IiEEvDTcl1fIPT_ELi0EEE(
|
2010-08-20 08:17:19 +08:00
|
|
|
template <class T> void test0(decltype(f<T*>(0))) {}
|
|
|
|
template void test0<int>(decltype(f<int*>(0)));
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test205test1IiEEvDTcl1fIEcvT__EEE(
|
2010-08-20 08:17:19 +08:00
|
|
|
template <class T> void test1(decltype(f<>(T()))) {}
|
|
|
|
template void test1<int>(decltype(f<>(int())));
|
|
|
|
}
|
2010-11-03 00:54:00 +08:00
|
|
|
|
|
|
|
// rdar:// 8620510
|
|
|
|
namespace test21 {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6test2112vla_arg_funcEiPA_i(
|
2010-11-03 00:54:00 +08:00
|
|
|
void vla_arg_func(int X, int a[X][X]) {}
|
|
|
|
}
|
2010-11-04 12:31:32 +08:00
|
|
|
|
|
|
|
namespace test22 {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6test221fEDn(
|
2010-11-04 12:31:32 +08:00
|
|
|
void f(decltype(nullptr)) { }
|
|
|
|
}
|
2011-01-27 04:05:40 +08:00
|
|
|
|
|
|
|
// rdar://problem/8913416
|
|
|
|
namespace test23 {
|
|
|
|
typedef void * const vpc;
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6test231fERA10_KPv(
|
2011-01-27 04:05:40 +08:00
|
|
|
void f(vpc (&)[10]) {}
|
|
|
|
|
|
|
|
typedef vpc vpca5[5];
|
|
|
|
void f(vpca5 volatile (&)[10]) {}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6test231fERA10_A5_VKPv(
|
2011-01-27 04:05:40 +08:00
|
|
|
}
|
2011-03-22 14:34:45 +08:00
|
|
|
|
|
|
|
namespace test24 {
|
|
|
|
void test0() {
|
|
|
|
extern int foo();
|
|
|
|
// CHECK: call i32 @_ZN6test243fooEv()
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
static char bar() {}
|
2011-03-22 14:34:45 +08:00
|
|
|
void test1() {
|
2013-09-20 09:15:31 +08:00
|
|
|
// CHECK: call signext i8 @_ZN6test24L3barEv()
|
|
|
|
bar();
|
2011-03-22 14:34:45 +08:00
|
|
|
}
|
|
|
|
}
|
2011-04-24 16:43:07 +08:00
|
|
|
|
|
|
|
// rdar://problem/8806641
|
|
|
|
namespace test25 {
|
|
|
|
template <void (*fn)()> struct A {
|
|
|
|
static void call() { fn(); }
|
|
|
|
};
|
|
|
|
void foo();
|
|
|
|
void test() {
|
|
|
|
// CHECK: call void @_ZN6test251AIXadL_ZNS_3fooEvEEE4callEv()
|
|
|
|
A<foo>::call();
|
|
|
|
}
|
|
|
|
}
|
2011-05-04 09:45:19 +08:00
|
|
|
|
|
|
|
namespace test26 {
|
|
|
|
template <template <class> class T> void foo(decltype(T<float>::object) &object) {}
|
|
|
|
|
|
|
|
template <class T> struct holder { static T object; };
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
float f;
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN6test263fooINS_6holderEEEvRDtsrT_IfE6objectE(
|
|
|
|
foo<holder>(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test27 {
|
|
|
|
struct A {
|
|
|
|
struct inner {
|
|
|
|
float object;
|
|
|
|
};
|
|
|
|
|
|
|
|
float meth();
|
|
|
|
};
|
|
|
|
typedef A Alias;
|
|
|
|
|
|
|
|
template <class T> void a(decltype(T::inner::object) &object) {}
|
|
|
|
template <class T> void b(decltype(T().Alias::meth()) &object) {}
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
float f;
|
|
|
|
// CHECK: call void @_ZN6test271aINS_1AEEEvRDtsrNT_5innerE6objectE(
|
|
|
|
a<A>(f);
|
|
|
|
// CHECK: call void @_ZN6test271bINS_1AEEEvRDTcldtcvT__Esr5AliasE4methEE(
|
|
|
|
b<A>(f);
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 00:49:23 +08:00
|
|
|
|
|
|
|
// An injected class name type in a unresolved-name.
|
|
|
|
namespace test28 {
|
|
|
|
template <class T> struct A {
|
|
|
|
enum { bit };
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T> void foo(decltype(A<T>::A::bit) x);
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
foo<char>(A<char>::bit);
|
|
|
|
// CHECK: call void @_ZN6test283fooIcEEvDtsr1AIT_E1AE3bitE(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// An enclosing template type parameter in an unresolved-name.
|
|
|
|
namespace test29 {
|
|
|
|
template <class T> struct A {
|
|
|
|
template <class U> static void foo(decltype(T::fn(U())) x);
|
|
|
|
};
|
|
|
|
struct B { static int fn(int); static long fn(long); };
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
A<B>::foo<int>(0);
|
|
|
|
// CHECK: call void @_ZN6test291AINS_1BEE3fooIiEEvDTclsrS1_2fncvT__EEE(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// An enclosing template template parameter in an unresolved-name.
|
|
|
|
namespace test30 {
|
|
|
|
template <template <class> class T> struct A {
|
|
|
|
template <class U> static void foo(decltype(T<U>::fn()) x);
|
|
|
|
};
|
|
|
|
template <class T> struct B { static T fn(); };
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
A<B>::foo<int>(0);
|
2011-07-01 08:04:39 +08:00
|
|
|
// CHECK: call void @_ZN6test301AINS_1BEE3fooIiEEvDTclsrS1_IT_EE2fnEE(
|
2011-06-29 00:49:23 +08:00
|
|
|
}
|
|
|
|
}
|
2011-07-01 09:22:09 +08:00
|
|
|
|
|
|
|
namespace test31 { // instantiation-dependent mangling of decltype
|
|
|
|
int x;
|
|
|
|
template<class T> auto f1(T p)->decltype(x) { return 0; }
|
|
|
|
// The return type in the mangling of the template signature
|
|
|
|
// is encoded as "i".
|
|
|
|
template<class T> auto f2(T p)->decltype(p) { return 0; }
|
|
|
|
// The return type in the mangling of the template signature
|
|
|
|
// is encoded as "Dtfp_E".
|
|
|
|
void g(int);
|
|
|
|
template<class T> auto f3(T p)->decltype(g(p)) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr i32 @_ZN6test312f1IiEEiT_(
|
2011-07-01 09:22:09 +08:00
|
|
|
template int f1(int);
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr i32 @_ZN6test312f2IiEEDtfp_ET_
|
2011-07-01 09:22:09 +08:00
|
|
|
template int f2(int);
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test312f3IiEEDTcl1gfp_EET_
|
2011-07-01 09:22:09 +08:00
|
|
|
template void f3(int);
|
|
|
|
}
|
2011-07-01 10:19:08 +08:00
|
|
|
|
|
|
|
// PR10205
|
|
|
|
namespace test32 {
|
|
|
|
template<typename T, int=T::value> struct A {
|
|
|
|
typedef int type;
|
|
|
|
};
|
|
|
|
struct B { enum { value = 4 }; };
|
|
|
|
|
|
|
|
template <class T> typename A<T>::type foo() { return 0; }
|
|
|
|
void test() {
|
|
|
|
foo<B>();
|
|
|
|
// CHECK: call i32 @_ZN6test323fooINS_1BEEENS_1AIT_XsrS3_5valueEE4typeEv()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test33 {
|
|
|
|
template <class T> struct X {
|
|
|
|
enum { value = T::value };
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, int=X<T>::value> struct A {
|
|
|
|
typedef int type;
|
|
|
|
};
|
|
|
|
struct B { enum { value = 4 }; };
|
|
|
|
|
|
|
|
template <class T> typename A<T>::type foo() { return 0; }
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
foo<B>();
|
|
|
|
// CHECK: call i32 @_ZN6test333fooINS_1BEEENS_1AIT_Xsr1XIS3_EE5valueEE4typeEv()
|
|
|
|
}
|
|
|
|
}
|
2011-07-12 06:38:07 +08:00
|
|
|
|
|
|
|
namespace test34 {
|
2011-07-12 12:47:20 +08:00
|
|
|
// Mangling for instantiation-dependent decltype expressions.
|
2011-07-12 06:38:07 +08:00
|
|
|
template<typename T>
|
|
|
|
void f(decltype(sizeof(decltype(T() + T())))) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE
|
2011-07-12 06:38:07 +08:00
|
|
|
template void f<int>(decltype(sizeof(1)));
|
2011-07-12 12:47:20 +08:00
|
|
|
|
|
|
|
// Mangling for non-instantiation-dependent sizeof expressions.
|
|
|
|
template<unsigned N>
|
|
|
|
void f2(int (&)[N + sizeof(int*)]) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test342f2ILj4EEEvRAplT_Lm8E_i
|
2011-07-12 12:47:20 +08:00
|
|
|
template void f2<4>(int (&)[4 + sizeof(int*)]);
|
|
|
|
|
|
|
|
// Mangling for non-instantiation-dependent sizeof expressions
|
|
|
|
// involving an implicit conversion of the result of the sizeof.
|
|
|
|
template<unsigned long long N>
|
|
|
|
void f3(int (&)[N + sizeof(int*)]) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test342f3ILy4EEEvRAplT_Ly8E_i
|
2011-07-12 12:47:20 +08:00
|
|
|
template void f3<4>(int (&)[4 + sizeof(int*)]);
|
2011-07-12 23:18:55 +08:00
|
|
|
|
|
|
|
// Mangling for instantiation-dependent sizeof() expressions as
|
|
|
|
// template arguments.
|
|
|
|
template<unsigned> struct A { };
|
|
|
|
|
|
|
|
template<typename T> void f4(::test34::A<sizeof(sizeof(decltype(T() + T())))>) { }
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test342f4IiEEvNS_1AIXszstDTplcvT__EcvS2__EEEEE
|
2011-07-12 23:18:55 +08:00
|
|
|
template void f4<int>(A<sizeof(sizeof(int))>);
|
2011-07-12 06:38:07 +08:00
|
|
|
}
|
2011-07-12 13:06:05 +08:00
|
|
|
|
|
|
|
namespace test35 {
|
|
|
|
// Dependent operator names of unknown arity.
|
|
|
|
struct A {
|
|
|
|
template<typename U> A operator+(U) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void f1(decltype(sizeof(&T::template operator+<int>))) {}
|
|
|
|
|
2015-02-14 21:23:54 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test352f1INS_1AEEEvDTszadsrT_onplIiEE
|
2011-07-12 13:06:05 +08:00
|
|
|
template void f1<A>(__SIZE_TYPE__);
|
|
|
|
}
|
2011-07-12 15:03:48 +08:00
|
|
|
|
|
|
|
namespace test36 {
|
|
|
|
template<unsigned> struct A { };
|
|
|
|
|
|
|
|
template<typename ...Types>
|
|
|
|
auto f1(Types... values) -> A<sizeof...(values)> { }
|
|
|
|
|
|
|
|
// CHECK: define weak_odr {{.*}} @_ZN6test362f1IJifEEENS_1AIXsZfp_EEEDpT_
|
|
|
|
template A<2> f1(int, float);
|
|
|
|
}
|
2012-11-14 09:52:05 +08:00
|
|
|
|
|
|
|
namespace test37 {
|
|
|
|
struct foo {
|
|
|
|
struct {
|
|
|
|
} a;
|
|
|
|
typedef struct { } b;
|
|
|
|
typedef struct { } *c;
|
|
|
|
struct {
|
|
|
|
} d;
|
|
|
|
};
|
|
|
|
template<typename T> void func(T) { }
|
|
|
|
void test() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN6test374funcINS_3fooUt_EEEvT_
|
2012-11-14 09:52:05 +08:00
|
|
|
func(foo().a);
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN6test374funcINS_3fooUt0_EEEvT_
|
2012-11-14 09:52:05 +08:00
|
|
|
func(*foo::c());
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN6test374funcINS_3fooUt1_EEEvT_
|
2012-11-14 09:52:05 +08:00
|
|
|
func(foo().d);
|
|
|
|
}
|
|
|
|
}
|
2013-02-08 09:07:32 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z6ASfuncPU3AS3i
|
2013-02-08 09:07:32 +08:00
|
|
|
void ASfunc(__attribute__((address_space(3))) int* x) {}
|
2013-05-28 22:09:46 +08:00
|
|
|
|
|
|
|
namespace test38 {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN6test384funcINS_3fooUt_EEEvT_
|
2013-05-28 22:09:46 +08:00
|
|
|
typedef struct {
|
|
|
|
struct {
|
|
|
|
} a;
|
|
|
|
} foo;
|
|
|
|
|
|
|
|
template <typename T> void func(T) {}
|
|
|
|
void test() { func(foo().a); }
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test39 {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal void @"_ZN6test394funcINS_3$_03$_1EEEvT_"
|
2013-05-28 22:09:46 +08:00
|
|
|
typedef struct {
|
|
|
|
struct {} a;
|
|
|
|
} *foo;
|
|
|
|
template<typename T> void func(T) {}
|
2017-09-20 15:22:00 +08:00
|
|
|
void test() {
|
|
|
|
foo x;
|
2013-05-28 22:09:46 +08:00
|
|
|
func(x->a);
|
|
|
|
}
|
|
|
|
}
|
2013-07-10 08:30:46 +08:00
|
|
|
|
|
|
|
namespace test40 {
|
2014-05-28 17:56:42 +08:00
|
|
|
// CHECK: i32* {{.*}} @_ZZN6test401fEvE1a_0
|
2013-07-10 08:30:46 +08:00
|
|
|
void h(int&);
|
|
|
|
inline void f() {
|
|
|
|
if (0) {
|
|
|
|
static int a;
|
|
|
|
}
|
|
|
|
static int a;
|
|
|
|
h(a);
|
|
|
|
};
|
|
|
|
void g() { f(); }
|
|
|
|
}
|
2013-08-29 07:48:32 +08:00
|
|
|
|
|
|
|
namespace test41 {
|
|
|
|
// CHECK: define linkonce_odr void @_ZN6test414funcINS_1XEEEvNS_3fooILi20ES1_EE
|
|
|
|
template <int i, class T> struct foo {
|
|
|
|
template <class T2 = T> friend void func(foo x) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct X {};
|
|
|
|
|
|
|
|
void g() { func(foo<20, X>()); }
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test42 {
|
|
|
|
// CHECK: define linkonce_odr void @_ZN6test424funcINS_1XEEEvNS_3fooILi20ES1_EE
|
|
|
|
template <int i, template <class> class T> struct foo {
|
|
|
|
template <template <class> class T2 = T> friend void func(foo x) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class V> struct X {
|
|
|
|
};
|
|
|
|
|
|
|
|
void g() { func(foo<20, X>()); }
|
|
|
|
}
|
2013-10-24 04:52:43 +08:00
|
|
|
|
|
|
|
namespace test43 {
|
|
|
|
// CHECK-LABEL: define void @_ZN6test431gEPNS_3zedIXadL_ZNS_3fooUt_3barEEEEE
|
|
|
|
struct foo { union { int bar; }; };
|
|
|
|
template <int (foo::*)>
|
|
|
|
struct zed {};
|
|
|
|
void g(zed<&foo::bar>*)
|
|
|
|
{}
|
|
|
|
}
|
2013-11-04 07:51:28 +08:00
|
|
|
|
|
|
|
namespace test44 {
|
|
|
|
struct foo { void bar() __restrict { }; } obj;
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
obj.bar();
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN6test443foo3barEv(%"struct.test44::foo"* %this)
|
|
|
|
}
|
2014-04-10 08:49:24 +08:00
|
|
|
|
|
|
|
namespace test45 {
|
|
|
|
struct S {
|
|
|
|
enum e {};
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
void f(enum T::e *) {}
|
|
|
|
template void f<S>(S::e *);
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test451fINS_1SEEEvPTeNT_1eE(i32* %0)
|
2014-04-10 08:49:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace test46 {
|
|
|
|
struct S {
|
|
|
|
struct s {};
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
void f(struct T::s *) {}
|
|
|
|
template void f<S>(S::s *);
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test461fINS_1SEEEvPTsNT_1sE(%"struct.test46::S::s"* %0)
|
2014-04-10 08:49:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace test47 {
|
|
|
|
struct S {
|
|
|
|
class c {};
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
void f(class T::c *) {}
|
|
|
|
template void f<S>(S::c *);
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test471fINS_1SEEEvPTsNT_1cE(%"class.test47::S::c"* %0)
|
2014-04-10 08:49:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace test48 {
|
|
|
|
struct S {
|
|
|
|
union u {};
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
void f(union T::u *) {}
|
|
|
|
template void f<S>(S::u *);
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN6test481fINS_1SEEEvPTuNT_1uE(%"union.test48::S::u"* %0)
|
2014-04-10 08:49:24 +08:00
|
|
|
}
|
2014-10-25 04:22:57 +08:00
|
|
|
|
|
|
|
namespace test49 {
|
|
|
|
template <int>
|
|
|
|
struct S {};
|
|
|
|
|
|
|
|
template <template <int> class T>
|
|
|
|
T<3> fin(T<3>);
|
|
|
|
|
|
|
|
auto v = fin<S>;
|
|
|
|
// CHECK-LABEL: declare void @_ZN6test493finINS_1SEEET_ILi3EES3_()
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test50 {
|
|
|
|
template <int>
|
|
|
|
struct S {};
|
|
|
|
|
|
|
|
template <template <int> class T>
|
|
|
|
T<3> fin(T<4>);
|
|
|
|
|
|
|
|
auto v = fin<S>;
|
|
|
|
// CHECK-LABEL: declare void @_ZN6test503finINS_1SEEET_ILi3EES2_ILi4EE()
|
|
|
|
}
|
2015-02-14 21:23:54 +08:00
|
|
|
|
|
|
|
namespace test51 {
|
|
|
|
template <typename T>
|
|
|
|
decltype(T().~T()) fun() {}
|
|
|
|
template void fun<int>();
|
|
|
|
// CHECK-LABEL: @_ZN6test513funIiEEDTcldtcvT__EdnS1_EEv
|
|
|
|
template void fun<X>();
|
|
|
|
// CHECK-LABEL: @_ZN6test513funI1XEEDTcldtcvT__EdnS2_EEv
|
|
|
|
template void fun<S1<int> >();
|
|
|
|
// CHECK-LABEL: @_ZN6test513funI2S1IiEEEDTcldtcvT__EdnS3_EEv
|
|
|
|
|
2015-02-19 10:16:16 +08:00
|
|
|
enum E {};
|
|
|
|
template <typename T>
|
|
|
|
struct X {
|
|
|
|
struct Y {};
|
|
|
|
};
|
|
|
|
|
2015-02-14 21:23:54 +08:00
|
|
|
template <typename T>
|
|
|
|
decltype(S1<T>().~S1<T>()) fun1() {};
|
|
|
|
template <typename U, typename T>
|
|
|
|
decltype(U().~S1<T>()) fun2() {}
|
|
|
|
template <typename U, typename T>
|
|
|
|
decltype(S1<T>().~U()) fun3() {}
|
2015-02-18 10:28:01 +08:00
|
|
|
template <typename T>
|
|
|
|
decltype(S1<T>().~S1<T>(), S1<T>().~S1<T>()) fun4() {};
|
|
|
|
template <typename T>
|
|
|
|
decltype(S1<int>().~S1<T>()) fun5(){};
|
|
|
|
template <template <typename T> class U>
|
|
|
|
decltype(S1<int>().~U<int>()) fun6(){};
|
2015-02-19 10:16:16 +08:00
|
|
|
template <typename T>
|
|
|
|
decltype(E().E::~T()) fun7() {}
|
|
|
|
template <template <typename> class U>
|
|
|
|
decltype(X<int>::Y().U<int>::Y::~Y()) fun8() {}
|
2015-02-14 21:23:54 +08:00
|
|
|
template void fun1<int>();
|
|
|
|
// CHECK-LABEL: @_ZN6test514fun1IiEEDTcldtcv2S1IT_E_Edn2S1IS2_EEEv
|
|
|
|
template void fun2<S1<int>, int>();
|
|
|
|
// CHECK-LABEL: @_ZN6test514fun2I2S1IiEiEEDTcldtcvT__Edn2S1IT0_EEEv
|
|
|
|
template void fun3<S1<int>, int>();
|
|
|
|
// CHECK-LABEL: @_ZN6test514fun3I2S1IiEiEEDTcldtcvS1_IT0_E_EdnT_EEv
|
2015-02-18 10:28:01 +08:00
|
|
|
template void fun4<int>();
|
|
|
|
// CHECK-LABEL: @_ZN6test514fun4IiEEDTcmcldtcv2S1IT_E_Edn2S1IS2_EEcldtcvS3__Edn2S1IS2_EEEv
|
|
|
|
template void fun5<int>();
|
2015-02-19 10:16:16 +08:00
|
|
|
// CHECK-LABEL: @_ZN6test514fun5IiEEDTcldtcv2S1IiE_Edn2S1IT_EEEv
|
2015-02-18 10:28:01 +08:00
|
|
|
template void fun6<S1>();
|
2015-02-19 10:16:16 +08:00
|
|
|
// CHECK-LABEL: @_ZN6test514fun6I2S1EEDTcldtcvS1_IiE_EdnT_IiEEEv
|
|
|
|
template void fun7<E>();
|
|
|
|
// CHECK-LABEL: @_ZN6test514fun7INS_1EEEEDTcldtcvS1__Esr1EEdnT_EEv
|
|
|
|
template void fun8<X>();
|
2015-02-14 21:23:54 +08:00
|
|
|
}
|
2015-02-20 05:41:48 +08:00
|
|
|
|
|
|
|
namespace test52 {
|
|
|
|
struct X {};
|
|
|
|
void operator+(X);
|
|
|
|
template <typename... T>
|
|
|
|
auto f4(T... x) -> decltype(operator+(x...));
|
|
|
|
// CHECK-LABEL: @_ZN6test522f4IJNS_1XEEEEDTclonplspfp_EEDpT_
|
|
|
|
void use() { f4(X{}); }
|
|
|
|
}
|
2015-03-11 14:45:39 +08:00
|
|
|
|
|
|
|
namespace test53 {
|
|
|
|
struct c {
|
|
|
|
using t1 = struct { int z; };
|
|
|
|
using t2 = struct { double z; };
|
|
|
|
using t3 = struct { float z; };
|
|
|
|
using t4 = struct { float z; };
|
|
|
|
|
|
|
|
__attribute__((used)) c(t1) {}
|
|
|
|
__attribute__((used)) c(t2) {}
|
|
|
|
__attribute__((used)) c(t3) {}
|
|
|
|
__attribute__((used)) c(t4) {}
|
|
|
|
// CHECK-LABEL: @_ZN6test531cC2ENS0_2t1E
|
|
|
|
// CHECK-LABEL: @_ZN6test531cC2ENS0_2t2E
|
|
|
|
// CHECK-LABEL: @_ZN6test531cC2ENS0_2t3E
|
|
|
|
// CHECK-LABEL: @_ZN6test531cC2ENS0_2t4E
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test54 {
|
|
|
|
struct c {
|
|
|
|
using t1 = struct { int z; } *;
|
|
|
|
using t2 = struct { double z; } *;
|
|
|
|
|
|
|
|
__attribute__((used)) c(t1) {}
|
|
|
|
__attribute__((used)) c(t2) {}
|
|
|
|
// CHECK-LABEL: @_ZN6test541cC2EPNS0_Ut_E
|
|
|
|
// CHECK-LABEL: @_ZN6test541cC2EPNS0_Ut0_E
|
|
|
|
};
|
|
|
|
}
|
2016-06-08 08:34:15 +08:00
|
|
|
|
|
|
|
namespace test55 {
|
|
|
|
enum E { R };
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void fn(T, __underlying_type(T)) {}
|
|
|
|
|
|
|
|
template void fn<E>(E, __underlying_type(E));
|
|
|
|
// CHECK-LABEL: @_ZN6test552fnINS_1EEEEvT_U3eutS2_
|
|
|
|
}
|
2016-10-25 04:29:40 +08:00
|
|
|
|
|
|
|
namespace test56 {
|
|
|
|
struct A { A *operator->(); int n; } a;
|
|
|
|
template<int N> void f(decltype(a->n + N)) {}
|
|
|
|
// CHECK-LABEL: @_ZN6test561fILi0EEEvDTplptL_ZNS_1aEE1nT_E
|
|
|
|
template void f<0>(int);
|
|
|
|
}
|
2016-10-25 04:47:04 +08:00
|
|
|
|
|
|
|
namespace test57 {
|
|
|
|
struct X { template <int N> int f(); } x;
|
|
|
|
template<int N> void f(decltype(x.f<0>() + N)) {}
|
|
|
|
// CHECK-LABEL: @_ZN6test571fILi0EEEvDTplcldtL_ZNS_1xEE1fIXLi0EEEET_E
|
|
|
|
template void f<0>(int);
|
|
|
|
}
|
2017-01-21 02:50:12 +08:00
|
|
|
|
|
|
|
namespace test58 {
|
|
|
|
struct State {
|
|
|
|
bool m_fn1();
|
|
|
|
} a;
|
2017-01-25 05:03:48 +08:00
|
|
|
template <class T> struct identity { typedef T type; };
|
2017-01-21 02:50:12 +08:00
|
|
|
struct A {
|
2017-01-25 05:03:48 +08:00
|
|
|
template <typename T> A(T, bool (identity<T>::type::*)());
|
2017-01-21 02:50:12 +08:00
|
|
|
};
|
2017-01-25 05:03:48 +08:00
|
|
|
// CHECK-LABEL: @_ZN6test581AC1INS_5StateEEET_MNS_8identityIS3_E4typeEFbvE
|
2017-01-21 02:50:12 +08:00
|
|
|
void fn1() { A(a, &State::m_fn1); }
|
|
|
|
}
|