Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks -std=c++11 | FileCheck %s |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 2 | struct X { }; |
| 3 | struct Y { }; |
Anders Carlsson | b1d947b | 2009-03-07 23:57:03 +0000 | [diff] [blame] | 4 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 5 | // CHECK: @unmangled_variable = global |
| 6 | // CHECK: @_ZN1N1iE = global |
| 7 | // CHECK: @_ZZN1N1fEiiE1b = internal global |
| 8 | // CHECK: @_ZZN1N1gEvE1a = internal global |
| 9 | // CHECK: @_ZGVZN1N1gEvE1a = internal global |
| 10 | |
Sean Hunt | 3145525 | 2010-01-24 03:04:27 +0000 | [diff] [blame] | 11 | //CHECK: @pr5966_i = external global |
| 12 | //CHECK: @_ZL8pr5966_i = internal global |
| 13 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 14 | // CHECK: define zeroext i1 @_ZplRK1YRA100_P1X |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 15 | bool operator+(const Y&, X* (&xs)[100]) { return false; } |
| 16 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 17 | // CHECK: define void @_Z1f1s |
Anders Carlsson | b1d947b | 2009-03-07 23:57:03 +0000 | [diff] [blame] | 18 | typedef struct { int a; } s; |
| 19 | void f(s) { } |
| 20 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 21 | // CHECK: define void @_Z1f1e |
Anders Carlsson | b1d947b | 2009-03-07 23:57:03 +0000 | [diff] [blame] | 22 | typedef enum { foo } e; |
| 23 | void f(e) { } |
| 24 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 25 | // CHECK: define void @_Z1f1u |
Anders Carlsson | b1d947b | 2009-03-07 23:57:03 +0000 | [diff] [blame] | 26 | typedef union { int a; } u; |
| 27 | void f(u) { } |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 28 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 29 | // CHECK: define void @_Z1f1x |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 30 | typedef struct { int a; } x,y; |
| 31 | void f(y) { } |
| 32 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 33 | // CHECK: define void @_Z1fv |
Anders Carlsson | c6c91bc | 2009-04-01 00:15:23 +0000 | [diff] [blame] | 34 | void f() { } |
Anders Carlsson | 984e068 | 2009-04-01 00:58:25 +0000 | [diff] [blame] | 35 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 36 | // CHECK: define void @_ZN1N1fEv |
Anders Carlsson | 984e068 | 2009-04-01 00:58:25 +0000 | [diff] [blame] | 37 | namespace N { void f() { } } |
| 38 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 39 | // CHECK: define void @_ZN1N1N1fEv |
Anders Carlsson | 984e068 | 2009-04-01 00:58:25 +0000 | [diff] [blame] | 40 | namespace N { namespace N { void f() { } } } |
Anders Carlsson | 91e20dd | 2009-04-02 05:55:18 +0000 | [diff] [blame] | 41 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 42 | // CHECK: define void @unmangled_function |
Anders Carlsson | 91e20dd | 2009-04-02 05:55:18 +0000 | [diff] [blame] | 43 | extern "C" { namespace N { void unmangled_function() { } } } |
| 44 | |
Anders Carlsson | 2928c21 | 2009-05-16 21:02:39 +0000 | [diff] [blame] | 45 | extern "C" { namespace N { int unmangled_variable = 10; } } |
Anders Carlsson | 91e20dd | 2009-04-02 05:55:18 +0000 | [diff] [blame] | 46 | |
Anders Carlsson | 329749c | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 47 | namespace N { int i; } |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 48 | |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 49 | namespace N { int f(int, int) { static int b; return b; } } |
Anders Carlsson | 283a062 | 2009-04-13 18:03:33 +0000 | [diff] [blame] | 50 | |
Anders Carlsson | 283a062 | 2009-04-13 18:03:33 +0000 | [diff] [blame] | 51 | namespace N { int h(); void g() { static int a = h(); } } |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 52 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 53 | // CHECK: define void @_Z1fno |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 54 | void f(__int128_t, __uint128_t) { } |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 55 | |
| 56 | template <typename T> struct S1 {}; |
| 57 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 58 | // CHECK: define void @_Z1f2S1IiE |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 59 | void f(S1<int>) {} |
| 60 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 61 | // CHECK: define void @_Z1f2S1IdE |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 62 | void f(S1<double>) {} |
| 63 | |
| 64 | template <int N> struct S2 {}; |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 65 | // CHECK: define void @_Z1f2S2ILi100EE |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 66 | void f(S2<100>) {} |
| 67 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 68 | // CHECK: define void @_Z1f2S2ILin100EE |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 69 | void f(S2<-100>) {} |
| 70 | |
| 71 | template <bool B> struct S3 {}; |
| 72 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 73 | // CHECK: define void @_Z1f2S3ILb1EE |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 74 | void f(S3<true>) {} |
| 75 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 76 | // CHECK: define void @_Z1f2S3ILb0EE |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 77 | void f(S3<false>) {} |
| 78 | |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 79 | struct S; |
| 80 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 81 | // CHECK: define void @_Z1fM1SKFvvE |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 82 | void f(void (S::*)() const) {} |
| 83 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 84 | // CHECK: define void @_Z1fM1SFvvE |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 85 | void f(void (S::*)()) {} |
Anders Carlsson | cf85b93 | 2009-09-16 23:53:19 +0000 | [diff] [blame] | 86 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 87 | // CHECK: define void @_Z1fi |
Anders Carlsson | cf85b93 | 2009-09-16 23:53:19 +0000 | [diff] [blame] | 88 | void f(const int) { } |
| 89 | |
Anders Carlsson | 03c9d53 | 2009-09-17 04:02:31 +0000 | [diff] [blame] | 90 | template<typename T, typename U> void ft1(U u, T t) { } |
| 91 | |
| 92 | template<typename T> void ft2(T t, void (*)(T), void (*)(T)) { } |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 93 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 94 | template<typename T, typename U = S1<T> > struct S4 { }; |
| 95 | template<typename T> void ft3(S4<T>*) { } |
| 96 | |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 97 | namespace NS { |
| 98 | template<typename T> void ft1(T) { } |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 101 | void g1() { |
Anders Carlsson | 03c9d53 | 2009-09-17 04:02:31 +0000 | [diff] [blame] | 102 | // CHECK: @_Z3ft1IidEvT0_T_ |
| 103 | ft1<int, double>(1, 0); |
| 104 | |
| 105 | // CHECK: @_Z3ft2IcEvT_PFvS0_ES2_ |
| 106 | ft2<char>(1, 0, 0); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 107 | |
| 108 | // CHECK: @_Z3ft3IiEvP2S4IT_2S1IS1_EE |
| 109 | ft3<int>(0); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 110 | |
| 111 | // CHECK: @_ZN2NS3ft1IiEEvT_ |
| 112 | NS::ft1<int>(1); |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 113 | } |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 114 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 115 | // Expressions |
| 116 | template<int I> struct S5 { }; |
| 117 | |
| 118 | template<int I> void ft4(S5<I>) { } |
| 119 | void g2() { |
| 120 | // CHECK: @_Z3ft4ILi10EEv2S5IXT_EE |
| 121 | ft4(S5<10>()); |
| 122 | |
| 123 | // CHECK: @_Z3ft4ILi20EEv2S5IXT_EE |
| 124 | ft4(S5<20>()); |
| 125 | } |
| 126 | |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 127 | extern "C++" { |
| 128 | // CHECK: @_Z1hv |
| 129 | void h() { } |
| 130 | } |
| 131 | |
Anders Carlsson | 5cc58c6 | 2009-09-22 17:23:30 +0000 | [diff] [blame] | 132 | // PR5019 |
| 133 | extern "C" { struct a { int b; }; } |
| 134 | |
| 135 | // CHECK: @_Z1fP1a |
| 136 | int f(struct a *x) { |
| 137 | return x->b; |
| 138 | } |
Anders Carlsson | add2882 | 2009-09-22 20:33:31 +0000 | [diff] [blame] | 139 | |
| 140 | // PR5017 |
| 141 | extern "C" { |
| 142 | struct Debug { |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 143 | const Debug& operator<< (unsigned a) const { return *this; } |
Anders Carlsson | add2882 | 2009-09-22 20:33:31 +0000 | [diff] [blame] | 144 | }; |
| 145 | Debug dbg; |
| 146 | // CHECK: @_ZNK5DebuglsEj |
| 147 | int main(void) { dbg << 32 ;} |
| 148 | } |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 149 | |
| 150 | template<typename T> struct S6 { |
| 151 | typedef int B; |
| 152 | }; |
| 153 | |
| 154 | template<typename T> void ft5(typename S6<T>::B) { } |
| 155 | // CHECK: @_Z3ft5IiEvN2S6IT_E1BE |
| 156 | template void ft5<int>(int); |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 157 | |
| 158 | template<typename T> class A {}; |
| 159 | |
| 160 | namespace NS { |
| 161 | template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; } |
| 162 | } |
| 163 | |
Anders Carlsson | aeb8537 | 2009-09-26 22:18:22 +0000 | [diff] [blame] | 164 | // CHECK: @_ZN2NSeqIcEEbRK1AIT_ES5_ |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 165 | template bool NS::operator==(const ::A<char>&, const ::A<char>&); |
| 166 | |
| 167 | namespace std { |
| 168 | template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; } |
| 169 | } |
| 170 | |
| 171 | // CHECK: @_ZSteqIcEbRK1AIT_ES4_ |
| 172 | template bool std::operator==(const ::A<char>&, const ::A<char>&); |
| 173 | |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 174 | struct S { |
| 175 | typedef int U; |
| 176 | }; |
| 177 | |
| 178 | template <typename T> typename T::U ft6(const T&) { return 0; } |
| 179 | |
| 180 | // CHECK: @_Z3ft6I1SENT_1UERKS1_ |
| 181 | template int ft6<S>(const S&); |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 182 | |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 183 | template<typename> struct __is_scalar_type { |
Richard Smith | 2bcb984 | 2012-09-13 22:00:12 +0000 | [diff] [blame] | 184 | enum { __value = 1 }; |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | template<bool, typename> struct __enable_if { }; |
| 188 | |
| 189 | template<typename T> struct __enable_if<true, T> { |
| 190 | typedef T __type; |
| 191 | }; |
| 192 | |
| 193 | // PR5063 |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 194 | template<typename T> typename __enable_if<__is_scalar_type<T>::__value, void>::__type ft7() { } |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 195 | |
John McCall | 26a6ec7 | 2011-06-21 22:12:46 +0000 | [diff] [blame] | 196 | // CHECK: @_Z3ft7IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 197 | template void ft7<int>(); |
John McCall | 26a6ec7 | 2011-06-21 22:12:46 +0000 | [diff] [blame] | 198 | // CHECK: @_Z3ft7IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 199 | template void ft7<void*>(); |
Anders Carlsson | b217c1b | 2009-10-06 21:58:01 +0000 | [diff] [blame] | 200 | |
| 201 | // PR5144 |
| 202 | extern "C" { |
| 203 | void extern_f(void); |
| 204 | }; |
| 205 | |
| 206 | // CHECK: @extern_f |
| 207 | void extern_f(void) { } |
| 208 | |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 209 | struct S7 { |
Anders Carlsson | 5c478cf | 2009-12-04 22:33:25 +0000 | [diff] [blame] | 210 | S7(); |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 211 | |
Anders Carlsson | 5c478cf | 2009-12-04 22:33:25 +0000 | [diff] [blame] | 212 | struct S { S(); }; |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 213 | struct { |
| 214 | S s; |
| 215 | } a; |
| 216 | }; |
| 217 | |
| 218 | // PR5139 |
John McCall | 8e51a1f | 2010-02-18 21:31:48 +0000 | [diff] [blame] | 219 | // CHECK: @_ZN2S7C1Ev |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 220 | // CHECK: @_ZN2S7C2Ev |
David Blaikie | 66cff72 | 2012-11-14 01:52:05 +0000 | [diff] [blame] | 221 | // CHECK: @_ZN2S7Ut_C1Ev |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 222 | S7::S7() {} |
| 223 | |
Anders Carlsson | a769408 | 2009-11-06 02:50:19 +0000 | [diff] [blame] | 224 | // PR5063 |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 225 | template<typename T> typename __enable_if<(__is_scalar_type<T>::__value), void>::__type ft8() { } |
John McCall | 26a6ec7 | 2011-06-21 22:12:46 +0000 | [diff] [blame] | 226 | // CHECK: @_Z3ft8IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv |
Anders Carlsson | a769408 | 2009-11-06 02:50:19 +0000 | [diff] [blame] | 227 | template void ft8<int>(); |
John McCall | 26a6ec7 | 2011-06-21 22:12:46 +0000 | [diff] [blame] | 228 | // CHECK: @_Z3ft8IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv |
Anders Carlsson | a769408 | 2009-11-06 02:50:19 +0000 | [diff] [blame] | 229 | template void ft8<void*>(); |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 230 | |
Anders Carlsson | 58040a5 | 2009-12-16 05:48:46 +0000 | [diff] [blame] | 231 | // PR5796 |
| 232 | namespace PR5796 { |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 233 | template<typename> struct __is_scalar_type { |
Richard Smith | 2bcb984 | 2012-09-13 22:00:12 +0000 | [diff] [blame] | 234 | enum { __value = 0 }; |
Anders Carlsson | 58040a5 | 2009-12-16 05:48:46 +0000 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | template<bool, typename> struct __enable_if {}; |
| 238 | template<typename T> struct __enable_if<true, T> { typedef T __type; }; |
| 239 | template<typename T> |
| 240 | |
John McCall | 26a6ec7 | 2011-06-21 22:12:46 +0000 | [diff] [blame] | 241 | // CHECK: define linkonce_odr void @_ZN6PR57968__fill_aIiEENS_11__enable_ifIXntsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 242 | typename __enable_if<!__is_scalar_type<T>::__value, void>::__type __fill_a() { }; |
Anders Carlsson | 58040a5 | 2009-12-16 05:48:46 +0000 | [diff] [blame] | 243 | |
| 244 | void f() { __fill_a<int>(); } |
| 245 | } |
| 246 | |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 247 | namespace Expressions { |
| 248 | // Unary operators. |
| 249 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 250 | // CHECK: define weak_odr void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 251 | template <int i> void f1(int (*)[(-i) + 2]) { }; |
| 252 | template void f1<1>(int (*)[1]); |
| 253 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 254 | // CHECK: define weak_odr void @_ZN11Expressions2f2ILi1EEEvPApsT__i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 255 | template <int i> void f2(int (*)[+i]) { }; |
| 256 | template void f2<1>(int (*)[1]); |
| 257 | |
| 258 | // Binary operators. |
| 259 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 260 | // CHECK: define weak_odr void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 261 | template <int i> void f3(int (*)[i+i]) { }; |
| 262 | template void f3<1>(int (*)[2]); |
| 263 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 264 | // CHECK: define weak_odr void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 265 | template <int i> void f4(int (*)[2 + i+i]) { }; |
| 266 | template void f4<1>(int (*)[4]); |
| 267 | |
| 268 | // The ternary operator. |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 269 | // CHECK: define weak_odr void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 270 | template <bool b> void f4(int (*)[b ? 1 : 2]) { }; |
| 271 | template void f4<true>(int (*)[1]); |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 272 | } |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 273 | |
| 274 | struct Ops { |
| 275 | Ops& operator+(const Ops&); |
| 276 | Ops& operator-(const Ops&); |
| 277 | Ops& operator&(const Ops&); |
| 278 | Ops& operator*(const Ops&); |
| 279 | |
| 280 | void *v; |
| 281 | }; |
| 282 | |
| 283 | // CHECK: define %struct.Ops* @_ZN3OpsplERKS_ |
| 284 | Ops& Ops::operator+(const Ops&) { return *this; } |
| 285 | // CHECK: define %struct.Ops* @_ZN3OpsmiERKS_ |
| 286 | Ops& Ops::operator-(const Ops&) { return *this; } |
| 287 | // CHECK: define %struct.Ops* @_ZN3OpsanERKS_ |
| 288 | Ops& Ops::operator&(const Ops&) { return *this; } |
| 289 | // CHECK: define %struct.Ops* @_ZN3OpsmlERKS_ |
| 290 | Ops& Ops::operator*(const Ops&) { return *this; } |
| 291 | |
Anders Carlsson | 9e85c74 | 2009-12-23 19:30:55 +0000 | [diff] [blame] | 292 | // PR5861 |
| 293 | namespace PR5861 { |
| 294 | template<bool> class P; |
| 295 | template<> class P<true> {}; |
| 296 | |
| 297 | template<template <bool> class, bool> |
| 298 | struct Policy { }; |
| 299 | |
| 300 | template<typename T, typename = Policy<P, true> > class Alloc |
| 301 | { |
| 302 | T *allocate(int, const void*) { return 0; } |
| 303 | }; |
| 304 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 305 | // CHECK: define weak_odr i8* @_ZN6PR58615AllocIcNS_6PolicyINS_1PELb1EEEE8allocateEiPKv |
Anders Carlsson | 9e85c74 | 2009-12-23 19:30:55 +0000 | [diff] [blame] | 306 | template class Alloc<char>; |
| 307 | } |
Anders Carlsson | f28c687 | 2009-12-23 22:31:44 +0000 | [diff] [blame] | 308 | |
| 309 | // CHECK: define void @_Z1fU13block_pointerFiiiE |
Nuno Lopes | a9efbf0 | 2010-01-07 09:36:51 +0000 | [diff] [blame] | 310 | void f(int (^)(int, int)) { } |
| 311 | |
Sean Hunt | 3145525 | 2010-01-24 03:04:27 +0000 | [diff] [blame] | 312 | void pr5966_foo() { |
| 313 | extern int pr5966_i; |
| 314 | pr5966_i = 0; |
| 315 | } |
| 316 | |
| 317 | static int pr5966_i; |
| 318 | |
| 319 | void pr5966_bar() { |
| 320 | pr5966_i = 0; |
| 321 | } |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 322 | |
| 323 | namespace test0 { |
| 324 | int ovl(int x); |
| 325 | char ovl(double x); |
| 326 | |
| 327 | template <class T> void f(T, char (&buffer)[sizeof(ovl(T()))]) {} |
| 328 | |
| 329 | void test0() { |
| 330 | char buffer[1]; |
| 331 | f(0.0, buffer); |
| 332 | } |
| 333 | // CHECK: define void @_ZN5test05test0Ev() |
| 334 | // CHECK: define linkonce_odr void @_ZN5test01fIdEEvT_RAszcl3ovlcvS1__EE_c( |
| 335 | |
| 336 | void test1() { |
| 337 | char buffer[sizeof(int)]; |
| 338 | f(1, buffer); |
| 339 | } |
| 340 | // CHECK: define void @_ZN5test05test1Ev() |
| 341 | // CHECK: define linkonce_odr void @_ZN5test01fIiEEvT_RAszcl3ovlcvS1__EE_c( |
| 342 | |
| 343 | template <class T> void g(char (&buffer)[sizeof(T() + 5.0f)]) {} |
| 344 | void test2() { |
| 345 | char buffer[sizeof(float)]; |
| 346 | g<float>(buffer); |
| 347 | } |
John McCall | 1b60052 | 2011-04-24 03:07:16 +0000 | [diff] [blame] | 348 | // CHECK: define linkonce_odr void @_ZN5test01gIfEEvRAszplcvT__ELf40a00000E_c( |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 349 | |
| 350 | template <class T> void h(char (&buffer)[sizeof(T() + 5.0)]) {} |
| 351 | void test3() { |
| 352 | char buffer[sizeof(double)]; |
| 353 | h<float>(buffer); |
| 354 | } |
| 355 | // CHECK: define linkonce_odr void @_ZN5test01hIfEEvRAszplcvT__ELd4014000000000000E_c( |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 356 | |
| 357 | template <class T> void j(char (&buffer)[sizeof(T().buffer)]) {} |
| 358 | struct A { double buffer[128]; }; |
| 359 | void test4() { |
| 360 | char buffer[1024]; |
| 361 | j<A>(buffer); |
| 362 | } |
John McCall | e1e342f | 2010-03-01 19:12:25 +0000 | [diff] [blame] | 363 | // CHECK: define linkonce_odr void @_ZN5test01jINS_1AEEEvRAszdtcvT__E6buffer_c( |
John McCall | 0c8731a | 2012-01-30 18:36:31 +0000 | [diff] [blame] | 364 | |
| 365 | template <class T> void k(char (&buffer)[sizeof(T() + 0.0f)]) {} |
| 366 | void test5() { |
| 367 | char buffer[sizeof(float)]; |
| 368 | k<float>(buffer); |
| 369 | } |
| 370 | // CHECK: define linkonce_odr void @_ZN5test01kIfEEvRAszplcvT__ELf00000000E_c( |
| 371 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 372 | } |
Douglas Gregor | 32fb4e1 | 2010-02-05 20:45:00 +0000 | [diff] [blame] | 373 | |
| 374 | namespace test1 { |
| 375 | template<typename T> struct X { }; |
| 376 | template<template<class> class Y, typename T> void f(Y<T>) { } |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 377 | // CHECK: define weak_odr void @_ZN5test11fINS_1XEiEEvT_IT0_E |
Douglas Gregor | 32fb4e1 | 2010-02-05 20:45:00 +0000 | [diff] [blame] | 378 | template void f(X<int>); |
| 379 | } |
Anders Carlsson | aec2523 | 2010-02-06 04:52:27 +0000 | [diff] [blame] | 380 | |
John McCall | 74990f4 | 2011-03-22 06:34:45 +0000 | [diff] [blame] | 381 | // CHECK: define internal void @_ZL27functionWithInternalLinkagev() |
Anders Carlsson | aec2523 | 2010-02-06 04:52:27 +0000 | [diff] [blame] | 382 | static void functionWithInternalLinkage() { } |
| 383 | void g() { functionWithInternalLinkage(); } |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 384 | |
| 385 | namespace test2 { |
| 386 | template <class T> decltype(((T*) 0)->member) read_member(T& obj) { |
| 387 | return obj.member; |
| 388 | } |
| 389 | |
| 390 | struct A { int member; } obj; |
| 391 | int test() { |
| 392 | return read_member(obj); |
| 393 | } |
| 394 | |
| 395 | // CHECK: define linkonce_odr i32 @_ZN5test211read_memberINS_1AEEEDtptcvPT_Li0E6memberERS2_( |
| 396 | } |
| 397 | |
John McCall | a0ce15c | 2011-04-24 08:23:24 +0000 | [diff] [blame] | 398 | // rdar://problem/9280586 |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 399 | namespace test3 { |
| 400 | struct AmbiguousBase { int ab; }; |
| 401 | struct Path1 : AmbiguousBase { float p; }; |
| 402 | struct Path2 : AmbiguousBase { double p; }; |
| 403 | struct Derived : Path1, Path2 { }; |
| 404 | |
John McCall | 4f4e413 | 2011-05-04 01:45:19 +0000 | [diff] [blame] | 405 | // CHECK: define linkonce_odr i32 @_ZN5test38get_ab_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E2abERS2_( |
John McCall | a0ce15c | 2011-04-24 08:23:24 +0000 | [diff] [blame] | 406 | template <class T> decltype(((T*) 0)->Path1::ab) get_ab_1(T &ref) { return ref.Path1::ab; } |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 407 | |
John McCall | 4f4e413 | 2011-05-04 01:45:19 +0000 | [diff] [blame] | 408 | // CHECK: define linkonce_odr i32 @_ZN5test38get_ab_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E2abERS2_( |
John McCall | a0ce15c | 2011-04-24 08:23:24 +0000 | [diff] [blame] | 409 | template <class T> decltype(((T*) 0)->Path2::ab) get_ab_2(T &ref) { return ref.Path2::ab; } |
| 410 | |
John McCall | 4f4e413 | 2011-05-04 01:45:19 +0000 | [diff] [blame] | 411 | // CHECK: define linkonce_odr float @_ZN5test37get_p_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E1pERS2_( |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 412 | template <class T> decltype(((T*) 0)->Path1::p) get_p_1(T &ref) { return ref.Path1::p; } |
| 413 | |
John McCall | 4f4e413 | 2011-05-04 01:45:19 +0000 | [diff] [blame] | 414 | // CHECK: define linkonce_odr double @_ZN5test37get_p_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E1pERS2_( |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 415 | template <class T> decltype(((T*) 0)->Path2::p) get_p_2(T &ref) { return ref.Path2::p; } |
| 416 | |
| 417 | Derived obj; |
| 418 | void test() { |
John McCall | a0ce15c | 2011-04-24 08:23:24 +0000 | [diff] [blame] | 419 | get_ab_1(obj); |
| 420 | get_ab_2(obj); |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 421 | get_p_1(obj); |
| 422 | get_p_2(obj); |
| 423 | } |
| 424 | } |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 425 | |
| 426 | // CHECK: define void @_ZN5test41gEPNS_3zedIXadL_ZNS_3foo3barEEEEE |
| 427 | namespace test4 { |
| 428 | struct foo { int bar; }; |
| 429 | template <int (foo::*)> |
| 430 | struct zed {}; |
| 431 | void g(zed<&foo::bar>*) |
| 432 | {} |
| 433 | } |
| 434 | // CHECK: define void @_ZN5test51gEPNS_3zedIXadL_ZNS_3foo3barEEEEE |
| 435 | namespace test5 { |
| 436 | struct foo { static int bar; }; |
| 437 | template <int *> |
| 438 | struct zed {}; |
| 439 | void g(zed<&foo::bar>*) |
| 440 | {} |
| 441 | } |
| 442 | // CHECK: define void @_ZN5test61gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE |
| 443 | namespace test6 { |
| 444 | struct foo { int bar(); }; |
| 445 | template <int (foo::*)()> |
| 446 | struct zed {}; |
| 447 | void g(zed<&foo::bar>*) |
| 448 | {} |
| 449 | } |
| 450 | // CHECK: define void @_ZN5test71gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE |
| 451 | namespace test7 { |
| 452 | struct foo { static int bar(); }; |
| 453 | template <int (*f)()> |
| 454 | struct zed {}; |
| 455 | void g(zed<&foo::bar>*) |
| 456 | {} |
| 457 | } |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 458 | // CHECK: define weak_odr void @_ZN5test81AILZNS_1B5valueEEE3incEv |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 459 | namespace test8 { |
| 460 | template <int &counter> class A { void inc() { counter++; } }; |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 461 | class B { public: static int value; }; |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 462 | template class A<B::value>; |
| 463 | } |
Rafael Espindola | 9b35b25 | 2010-03-17 04:28:11 +0000 | [diff] [blame] | 464 | // CHECK: declare void @_ZN5test91fIiNS_3barEEEvRKNT0_3baz1XE |
| 465 | namespace test9 { |
| 466 | template<class T> |
| 467 | struct foo { |
| 468 | typedef T X; |
| 469 | }; |
| 470 | struct bar { |
| 471 | typedef foo<int> baz; |
| 472 | }; |
| 473 | template <class zaz, class zed> |
| 474 | void f(const typename zed::baz::X&); |
| 475 | void g() { |
| 476 | f<int, bar>( 0); |
| 477 | } |
| 478 | } |
John McCall | de81063 | 2010-04-09 21:48:08 +0000 | [diff] [blame] | 479 | |
| 480 | // <rdar://problem/7825453> |
| 481 | namespace test10 { |
| 482 | template <char P1> struct S {}; |
| 483 | template <char P2> void f(struct S<false ? 'a' : P2> ) {} |
| 484 | |
| 485 | // CHECK: define weak_odr void @_ZN6test101fILc3EEEvNS_1SIXquLb0ELc97ET_EEE( |
| 486 | template void f<(char) 3>(struct S<3>); |
| 487 | } |
Anders Carlsson | 9329668 | 2010-06-02 04:40:13 +0000 | [diff] [blame] | 488 | |
| 489 | namespace test11 { |
| 490 | // CHECK: @_ZN6test111fEz |
| 491 | void f(...) { } |
| 492 | |
| 493 | struct A { |
| 494 | void f(...); |
| 495 | }; |
| 496 | |
| 497 | // CHECK: @_ZN6test111A1fEz |
| 498 | void A::f(...) { } |
| 499 | } |
Anders Carlsson | dfc0d1f | 2010-06-02 05:07:26 +0000 | [diff] [blame] | 500 | |
| 501 | namespace test12 { |
| 502 | |
| 503 | // CHECK: _ZN6test121fENS_1AILt33000EEE |
| 504 | template <unsigned short> struct A { }; |
| 505 | void f(A<33000>) { } |
John McCall | b6f532e | 2010-07-14 06:43:17 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | // PR7446 |
| 509 | namespace test13 { |
| 510 | template <template <class> class T> class A {}; |
| 511 | template <class U> class B {}; |
| 512 | |
| 513 | template <template<class> class T> void foo(const A<T> &a) {} |
| 514 | |
| 515 | // CHECK: define weak_odr void @_ZN6test133fooINS_1BEEEvRKNS_1AIT_EE( |
| 516 | template void foo(const A<B> &a); |
| 517 | } |
Eli Friedman | c00cb64 | 2010-07-18 20:49:59 +0000 | [diff] [blame] | 518 | |
| 519 | namespace test14 { |
| 520 | extern "C" { |
| 521 | struct S { |
| 522 | static int a(), x; |
| 523 | }; |
| 524 | // CHECK: define i32 @_ZN6test141S1aEv |
| 525 | // CHECK: load i32* @_ZN6test141S1xE |
| 526 | int S::a() { return S::x; } |
| 527 | } |
| 528 | } |
John McCall | 3dc7e7b | 2010-07-24 01:17:35 +0000 | [diff] [blame] | 529 | |
| 530 | // rdar://problem/8204122 |
| 531 | namespace test15 { |
| 532 | enum E { e = 3 }; |
| 533 | template <int I> struct S {}; |
| 534 | |
| 535 | template <int I> void f(S<I + e>) {} |
| 536 | |
| 537 | // CHECK: define weak_odr void @_ZN6test151fILi7EEEvNS_1SIXplT_LNS_1EE3EEEE( |
| 538 | template void f<7>(S<7 + e>); |
| 539 | } |
John McCall | 7121c8f | 2010-08-05 22:02:13 +0000 | [diff] [blame] | 540 | |
John McCall | 6f615bc | 2010-08-17 21:51:21 +0000 | [diff] [blame] | 541 | // rdar://problem/8302148 |
| 542 | namespace test17 { |
| 543 | template <int N> struct A {}; |
| 544 | |
| 545 | struct B { |
| 546 | static int foo(void); |
| 547 | }; |
| 548 | |
| 549 | template <class T> A<sizeof(T::foo())> func(void); |
| 550 | |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 551 | // CHECK: define void @_ZN6test174testEv() |
John McCall | 6f615bc | 2010-08-17 21:51:21 +0000 | [diff] [blame] | 552 | // CHECK: call {{.*}} @_ZN6test174funcINS_1BEEENS_1AIXszclsrT_3fooEEEEv() |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 553 | void test() { |
| 554 | func<B>(); |
John McCall | 6f615bc | 2010-08-17 21:51:21 +0000 | [diff] [blame] | 555 | } |
| 556 | } |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 557 | |
| 558 | // PR7891 |
| 559 | namespace test18 { |
| 560 | struct A { |
| 561 | int operator+(); |
| 562 | int operator-(); |
| 563 | int operator*(); |
| 564 | int operator&(); |
| 565 | }; |
| 566 | template <int (A::*)()> struct S {}; |
| 567 | |
| 568 | template <typename T> void f(S<&T::operator+>) {} |
| 569 | template void f<A>(S<&A::operator+>); |
| 570 | |
| 571 | template <typename T> void f(S<&T::operator- >) {} |
| 572 | template void f<A>(S<&A::operator- >); |
| 573 | |
| 574 | template <typename T> void f(S<&T::operator*>) {} |
| 575 | template void f<A>(S<&A::operator*>); |
| 576 | |
| 577 | template <typename T> void f(S<&T::operator&>) {} |
| 578 | template void f<A>(S<&A::operator&>); |
| 579 | |
| 580 | // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_plEEE |
| 581 | // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_miEEE |
| 582 | // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_mlEEE |
| 583 | // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_anEEE |
| 584 | } |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 585 | |
| 586 | // rdar://problem/8332117 |
| 587 | namespace test19 { |
| 588 | struct A { |
| 589 | template <typename T> int f(); |
| 590 | int operator+(); |
| 591 | operator int(); |
| 592 | template <typename T> int operator-(); |
| 593 | }; |
| 594 | |
| 595 | template <int (A::*)()> struct S {}; |
| 596 | |
| 597 | template <typename T> void g (S<&T::template f<int> >) {} |
| 598 | template <typename T> void g (S<&T::operator+ >) {} |
| 599 | template <typename T> void g (S<&T::operator int>) {} |
| 600 | template <typename T> void g (S<&T::template operator- <double> >) {} |
| 601 | |
| 602 | // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_1fIiEEEE( |
| 603 | template void g<A>(S<&A::f<int> >); |
| 604 | // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_plEEE( |
| 605 | template void g<A>(S<&A::operator+>); |
| 606 | // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_cviEEE( |
| 607 | template void g<A>(S<&A::operator int>); |
| 608 | // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_miIdEEEE( |
| 609 | template void g<A>(S<&A::operator-<double> >); |
| 610 | } |
| 611 | |
| 612 | namespace test20 { |
| 613 | template <class T> T *f(const T&); |
| 614 | template <class T> T *f(T*); |
| 615 | |
| 616 | // CHECK: define weak_odr void @_ZN6test205test0IiEEvDTcl1fIPT_ELi0EEE( |
| 617 | template <class T> void test0(decltype(f<T*>(0))) {} |
| 618 | template void test0<int>(decltype(f<int*>(0))); |
| 619 | |
| 620 | // CHECK: define weak_odr void @_ZN6test205test1IiEEvDTcl1fIEcvT__EEE( |
| 621 | template <class T> void test1(decltype(f<>(T()))) {} |
| 622 | template void test1<int>(decltype(f<>(int()))); |
| 623 | } |
Fariborz Jahanian | 7281d1f | 2010-11-02 16:54:00 +0000 | [diff] [blame] | 624 | |
| 625 | // rdar:// 8620510 |
| 626 | namespace test21 { |
| 627 | // CHECK: define void @_ZN6test2112vla_arg_funcEiPA_i( |
| 628 | void vla_arg_func(int X, int a[X][X]) {} |
| 629 | } |
Anders Carlsson | e292368 | 2010-11-04 04:31:32 +0000 | [diff] [blame] | 630 | |
| 631 | namespace test22 { |
| 632 | // CHECK: define void @_ZN6test221fEDn( |
| 633 | void f(decltype(nullptr)) { } |
| 634 | } |
John McCall | b47f748 | 2011-01-26 20:05:40 +0000 | [diff] [blame] | 635 | |
| 636 | // rdar://problem/8913416 |
| 637 | namespace test23 { |
| 638 | typedef void * const vpc; |
| 639 | |
| 640 | // CHECK: define void @_ZN6test231fERA10_KPv( |
| 641 | void f(vpc (&)[10]) {} |
| 642 | |
| 643 | typedef vpc vpca5[5]; |
| 644 | void f(vpca5 volatile (&)[10]) {} |
| 645 | // CHECK: define void @_ZN6test231fERA10_A5_VKPv( |
| 646 | } |
John McCall | 74990f4 | 2011-03-22 06:34:45 +0000 | [diff] [blame] | 647 | |
| 648 | namespace test24 { |
| 649 | void test0() { |
| 650 | extern int foo(); |
| 651 | // CHECK: call i32 @_ZN6test243fooEv() |
| 652 | foo(); |
| 653 | } |
| 654 | |
| 655 | static char foo() {} |
| 656 | void test1() { |
| 657 | // CHECK: call signext i8 @_ZN6test24L3fooEv() |
| 658 | foo(); |
| 659 | } |
| 660 | } |
John McCall | c0a4559 | 2011-04-24 08:43:07 +0000 | [diff] [blame] | 661 | |
| 662 | // rdar://problem/8806641 |
| 663 | namespace test25 { |
| 664 | template <void (*fn)()> struct A { |
| 665 | static void call() { fn(); } |
| 666 | }; |
| 667 | void foo(); |
| 668 | void test() { |
| 669 | // CHECK: call void @_ZN6test251AIXadL_ZNS_3fooEvEEE4callEv() |
| 670 | A<foo>::call(); |
| 671 | } |
| 672 | } |
John McCall | 4f4e413 | 2011-05-04 01:45:19 +0000 | [diff] [blame] | 673 | |
| 674 | namespace test26 { |
| 675 | template <template <class> class T> void foo(decltype(T<float>::object) &object) {} |
| 676 | |
| 677 | template <class T> struct holder { static T object; }; |
| 678 | |
| 679 | void test() { |
| 680 | float f; |
| 681 | |
| 682 | // CHECK: call void @_ZN6test263fooINS_6holderEEEvRDtsrT_IfE6objectE( |
| 683 | foo<holder>(f); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | namespace test27 { |
| 688 | struct A { |
| 689 | struct inner { |
| 690 | float object; |
| 691 | }; |
| 692 | |
| 693 | float meth(); |
| 694 | }; |
| 695 | typedef A Alias; |
| 696 | |
| 697 | template <class T> void a(decltype(T::inner::object) &object) {} |
| 698 | template <class T> void b(decltype(T().Alias::meth()) &object) {} |
| 699 | |
| 700 | void test() { |
| 701 | float f; |
| 702 | // CHECK: call void @_ZN6test271aINS_1AEEEvRDtsrNT_5innerE6objectE( |
| 703 | a<A>(f); |
| 704 | // CHECK: call void @_ZN6test271bINS_1AEEEvRDTcldtcvT__Esr5AliasE4methEE( |
| 705 | b<A>(f); |
| 706 | } |
| 707 | } |
John McCall | d3d49bb | 2011-06-28 16:49:23 +0000 | [diff] [blame] | 708 | |
| 709 | // An injected class name type in a unresolved-name. |
| 710 | namespace test28 { |
| 711 | template <class T> struct A { |
| 712 | enum { bit }; |
| 713 | }; |
| 714 | |
| 715 | template <class T> void foo(decltype(A<T>::A::bit) x); |
| 716 | |
| 717 | void test() { |
| 718 | foo<char>(A<char>::bit); |
| 719 | // CHECK: call void @_ZN6test283fooIcEEvDtsr1AIT_E1AE3bitE( |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | // An enclosing template type parameter in an unresolved-name. |
| 724 | namespace test29 { |
| 725 | template <class T> struct A { |
| 726 | template <class U> static void foo(decltype(T::fn(U())) x); |
| 727 | }; |
| 728 | struct B { static int fn(int); static long fn(long); }; |
| 729 | |
| 730 | void test() { |
| 731 | A<B>::foo<int>(0); |
| 732 | // CHECK: call void @_ZN6test291AINS_1BEE3fooIiEEvDTclsrS1_2fncvT__EEE( |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | // An enclosing template template parameter in an unresolved-name. |
| 737 | namespace test30 { |
| 738 | template <template <class> class T> struct A { |
| 739 | template <class U> static void foo(decltype(T<U>::fn()) x); |
| 740 | }; |
| 741 | template <class T> struct B { static T fn(); }; |
| 742 | |
| 743 | void test() { |
| 744 | A<B>::foo<int>(0); |
John McCall | 68a51a7 | 2011-07-01 00:04:39 +0000 | [diff] [blame] | 745 | // CHECK: call void @_ZN6test301AINS_1BEE3fooIiEEvDTclsrS1_IT_EE2fnEE( |
John McCall | d3d49bb | 2011-06-28 16:49:23 +0000 | [diff] [blame] | 746 | } |
| 747 | } |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 748 | |
| 749 | namespace test31 { // instantiation-dependent mangling of decltype |
| 750 | int x; |
| 751 | template<class T> auto f1(T p)->decltype(x) { return 0; } |
| 752 | // The return type in the mangling of the template signature |
| 753 | // is encoded as "i". |
| 754 | template<class T> auto f2(T p)->decltype(p) { return 0; } |
| 755 | // The return type in the mangling of the template signature |
| 756 | // is encoded as "Dtfp_E". |
| 757 | void g(int); |
| 758 | template<class T> auto f3(T p)->decltype(g(p)) {} |
| 759 | |
| 760 | // CHECK: define weak_odr i32 @_ZN6test312f1IiEEiT_( |
| 761 | template int f1(int); |
| 762 | // CHECK: define weak_odr i32 @_ZN6test312f2IiEEDtfp_ET_ |
| 763 | template int f2(int); |
| 764 | // CHECK: define weak_odr void @_ZN6test312f3IiEEDTcl1gfp_EET_ |
| 765 | template void f3(int); |
| 766 | } |
John McCall | 35ee32e | 2011-07-01 02:19:08 +0000 | [diff] [blame] | 767 | |
| 768 | // PR10205 |
| 769 | namespace test32 { |
| 770 | template<typename T, int=T::value> struct A { |
| 771 | typedef int type; |
| 772 | }; |
| 773 | struct B { enum { value = 4 }; }; |
| 774 | |
| 775 | template <class T> typename A<T>::type foo() { return 0; } |
| 776 | void test() { |
| 777 | foo<B>(); |
| 778 | // CHECK: call i32 @_ZN6test323fooINS_1BEEENS_1AIT_XsrS3_5valueEE4typeEv() |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | namespace test33 { |
| 783 | template <class T> struct X { |
| 784 | enum { value = T::value }; |
| 785 | }; |
| 786 | |
| 787 | template<typename T, int=X<T>::value> struct A { |
| 788 | typedef int type; |
| 789 | }; |
| 790 | struct B { enum { value = 4 }; }; |
| 791 | |
| 792 | template <class T> typename A<T>::type foo() { return 0; } |
| 793 | |
| 794 | void test() { |
| 795 | foo<B>(); |
| 796 | // CHECK: call i32 @_ZN6test333fooINS_1BEEENS_1AIT_Xsr1XIS3_EE5valueEE4typeEv() |
| 797 | } |
| 798 | } |
Douglas Gregor | 5e78cd4 | 2011-07-11 22:38:07 +0000 | [diff] [blame] | 799 | |
| 800 | namespace test34 { |
Douglas Gregor | edee94b | 2011-07-12 04:47:20 +0000 | [diff] [blame] | 801 | // Mangling for instantiation-dependent decltype expressions. |
Douglas Gregor | 5e78cd4 | 2011-07-11 22:38:07 +0000 | [diff] [blame] | 802 | template<typename T> |
| 803 | void f(decltype(sizeof(decltype(T() + T())))) {} |
| 804 | |
| 805 | // CHECK: define weak_odr void @_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE |
| 806 | template void f<int>(decltype(sizeof(1))); |
Douglas Gregor | edee94b | 2011-07-12 04:47:20 +0000 | [diff] [blame] | 807 | |
| 808 | // Mangling for non-instantiation-dependent sizeof expressions. |
| 809 | template<unsigned N> |
| 810 | void f2(int (&)[N + sizeof(int*)]) {} |
| 811 | |
| 812 | // CHECK: define weak_odr void @_ZN6test342f2ILj4EEEvRAplT_Lm8E_i |
| 813 | template void f2<4>(int (&)[4 + sizeof(int*)]); |
| 814 | |
| 815 | // Mangling for non-instantiation-dependent sizeof expressions |
| 816 | // involving an implicit conversion of the result of the sizeof. |
| 817 | template<unsigned long long N> |
| 818 | void f3(int (&)[N + sizeof(int*)]) {} |
| 819 | |
| 820 | // CHECK: define weak_odr void @_ZN6test342f3ILy4EEEvRAplT_Ly8E_i |
| 821 | template void f3<4>(int (&)[4 + sizeof(int*)]); |
Douglas Gregor | f158866 | 2011-07-12 15:18:55 +0000 | [diff] [blame] | 822 | |
| 823 | // Mangling for instantiation-dependent sizeof() expressions as |
| 824 | // template arguments. |
| 825 | template<unsigned> struct A { }; |
| 826 | |
| 827 | template<typename T> void f4(::test34::A<sizeof(sizeof(decltype(T() + T())))>) { } |
| 828 | |
| 829 | // CHECK: define weak_odr void @_ZN6test342f4IiEEvNS_1AIXszstDTplcvT__EcvS2__EEEEE |
| 830 | template void f4<int>(A<sizeof(sizeof(int))>); |
Douglas Gregor | 5e78cd4 | 2011-07-11 22:38:07 +0000 | [diff] [blame] | 831 | } |
Douglas Gregor | 1961791 | 2011-07-12 05:06:05 +0000 | [diff] [blame] | 832 | |
| 833 | namespace test35 { |
| 834 | // Dependent operator names of unknown arity. |
| 835 | struct A { |
| 836 | template<typename U> A operator+(U) const; |
| 837 | }; |
| 838 | |
| 839 | template<typename T> |
| 840 | void f1(decltype(sizeof(&T::template operator+<int>))) {} |
| 841 | |
| 842 | // CHECK: define weak_odr void @_ZN6test352f1INS_1AEEEvDTszadsrT_plIiEE |
| 843 | template void f1<A>(__SIZE_TYPE__); |
| 844 | } |
Douglas Gregor | 9183236 | 2011-07-12 07:03:48 +0000 | [diff] [blame] | 845 | |
| 846 | namespace test36 { |
| 847 | template<unsigned> struct A { }; |
| 848 | |
| 849 | template<typename ...Types> |
| 850 | auto f1(Types... values) -> A<sizeof...(values)> { } |
| 851 | |
| 852 | // CHECK: define weak_odr {{.*}} @_ZN6test362f1IJifEEENS_1AIXsZfp_EEEDpT_ |
| 853 | template A<2> f1(int, float); |
| 854 | } |
David Blaikie | 66cff72 | 2012-11-14 01:52:05 +0000 | [diff] [blame] | 855 | |
| 856 | namespace test37 { |
| 857 | struct foo { |
| 858 | struct { |
| 859 | } a; |
| 860 | typedef struct { } b; |
| 861 | typedef struct { } *c; |
| 862 | struct { |
| 863 | } d; |
| 864 | }; |
| 865 | template<typename T> void func(T) { } |
| 866 | void test() { |
| 867 | // CHECK: define linkonce_odr void @_ZN6test374funcINS_3fooUt_EEEvT_ |
| 868 | func(foo().a); |
| 869 | // CHECK: define linkonce_odr void @_ZN6test374funcINS_3fooUt0_EEEvT_ |
| 870 | func(*foo::c()); |
| 871 | // CHECK: define linkonce_odr void @_ZN6test374funcINS_3fooUt1_EEEvT_ |
| 872 | func(foo().d); |
| 873 | } |
| 874 | } |
Tanya Lattner | f21107b | 2013-02-08 01:07:32 +0000 | [diff] [blame] | 875 | |
| 876 | // CHECK: define void @_Z6ASfuncPU3AS3i |
| 877 | void ASfunc(__attribute__((address_space(3))) int* x) {} |