John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks -std=c++0x | 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 | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 79 | // CHECK: define void @_Z2f22S3ILb1EE |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 80 | void f2(S3<100>) {} |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 81 | |
| 82 | struct S; |
| 83 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 84 | // CHECK: define void @_Z1fM1SKFvvE |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 85 | void f(void (S::*)() const) {} |
| 86 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 87 | // CHECK: define void @_Z1fM1SFvvE |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 88 | void f(void (S::*)()) {} |
Anders Carlsson | cf85b93 | 2009-09-16 23:53:19 +0000 | [diff] [blame] | 89 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 90 | // CHECK: define void @_Z1fi |
Anders Carlsson | cf85b93 | 2009-09-16 23:53:19 +0000 | [diff] [blame] | 91 | void f(const int) { } |
| 92 | |
Anders Carlsson | 03c9d53 | 2009-09-17 04:02:31 +0000 | [diff] [blame] | 93 | template<typename T, typename U> void ft1(U u, T t) { } |
| 94 | |
| 95 | template<typename T> void ft2(T t, void (*)(T), void (*)(T)) { } |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 96 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 97 | template<typename T, typename U = S1<T> > struct S4 { }; |
| 98 | template<typename T> void ft3(S4<T>*) { } |
| 99 | |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 100 | namespace NS { |
| 101 | template<typename T> void ft1(T) { } |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 104 | void g1() { |
Anders Carlsson | 03c9d53 | 2009-09-17 04:02:31 +0000 | [diff] [blame] | 105 | // CHECK: @_Z3ft1IidEvT0_T_ |
| 106 | ft1<int, double>(1, 0); |
| 107 | |
| 108 | // CHECK: @_Z3ft2IcEvT_PFvS0_ES2_ |
| 109 | ft2<char>(1, 0, 0); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 110 | |
| 111 | // CHECK: @_Z3ft3IiEvP2S4IT_2S1IS1_EE |
| 112 | ft3<int>(0); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 113 | |
| 114 | // CHECK: @_ZN2NS3ft1IiEEvT_ |
| 115 | NS::ft1<int>(1); |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 116 | } |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 117 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 118 | // Expressions |
| 119 | template<int I> struct S5 { }; |
| 120 | |
| 121 | template<int I> void ft4(S5<I>) { } |
| 122 | void g2() { |
| 123 | // CHECK: @_Z3ft4ILi10EEv2S5IXT_EE |
| 124 | ft4(S5<10>()); |
| 125 | |
| 126 | // CHECK: @_Z3ft4ILi20EEv2S5IXT_EE |
| 127 | ft4(S5<20>()); |
| 128 | } |
| 129 | |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 130 | extern "C++" { |
| 131 | // CHECK: @_Z1hv |
| 132 | void h() { } |
| 133 | } |
| 134 | |
Anders Carlsson | 5cc58c6 | 2009-09-22 17:23:30 +0000 | [diff] [blame] | 135 | // PR5019 |
| 136 | extern "C" { struct a { int b; }; } |
| 137 | |
| 138 | // CHECK: @_Z1fP1a |
| 139 | int f(struct a *x) { |
| 140 | return x->b; |
| 141 | } |
Anders Carlsson | add2882 | 2009-09-22 20:33:31 +0000 | [diff] [blame] | 142 | |
| 143 | // PR5017 |
| 144 | extern "C" { |
| 145 | struct Debug { |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 146 | const Debug& operator<< (unsigned a) const { return *this; } |
Anders Carlsson | add2882 | 2009-09-22 20:33:31 +0000 | [diff] [blame] | 147 | }; |
| 148 | Debug dbg; |
| 149 | // CHECK: @_ZNK5DebuglsEj |
| 150 | int main(void) { dbg << 32 ;} |
| 151 | } |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 152 | |
| 153 | template<typename T> struct S6 { |
| 154 | typedef int B; |
| 155 | }; |
| 156 | |
| 157 | template<typename T> void ft5(typename S6<T>::B) { } |
| 158 | // CHECK: @_Z3ft5IiEvN2S6IT_E1BE |
| 159 | template void ft5<int>(int); |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 160 | |
| 161 | template<typename T> class A {}; |
| 162 | |
| 163 | namespace NS { |
| 164 | template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; } |
| 165 | } |
| 166 | |
Anders Carlsson | aeb8537 | 2009-09-26 22:18:22 +0000 | [diff] [blame] | 167 | // CHECK: @_ZN2NSeqIcEEbRK1AIT_ES5_ |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 168 | template bool NS::operator==(const ::A<char>&, const ::A<char>&); |
| 169 | |
| 170 | namespace std { |
| 171 | template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; } |
| 172 | } |
| 173 | |
| 174 | // CHECK: @_ZSteqIcEbRK1AIT_ES4_ |
| 175 | template bool std::operator==(const ::A<char>&, const ::A<char>&); |
| 176 | |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 177 | struct S { |
| 178 | typedef int U; |
| 179 | }; |
| 180 | |
| 181 | template <typename T> typename T::U ft6(const T&) { return 0; } |
| 182 | |
| 183 | // CHECK: @_Z3ft6I1SENT_1UERKS1_ |
| 184 | template int ft6<S>(const S&); |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 185 | |
| 186 | template<typename> struct __is_scalar { |
| 187 | enum { __value = 1 }; |
| 188 | }; |
| 189 | |
| 190 | template<bool, typename> struct __enable_if { }; |
| 191 | |
| 192 | template<typename T> struct __enable_if<true, T> { |
| 193 | typedef T __type; |
| 194 | }; |
| 195 | |
| 196 | // PR5063 |
| 197 | template<typename T> typename __enable_if<__is_scalar<T>::__value, void>::__type ft7() { } |
| 198 | |
| 199 | // CHECK: @_Z3ft7IiEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv |
| 200 | template void ft7<int>(); |
| 201 | // CHECK: @_Z3ft7IPvEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv |
| 202 | template void ft7<void*>(); |
Anders Carlsson | b217c1b | 2009-10-06 21:58:01 +0000 | [diff] [blame] | 203 | |
| 204 | // PR5144 |
| 205 | extern "C" { |
| 206 | void extern_f(void); |
| 207 | }; |
| 208 | |
| 209 | // CHECK: @extern_f |
| 210 | void extern_f(void) { } |
| 211 | |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 212 | struct S7 { |
Anders Carlsson | 5c478cf | 2009-12-04 22:33:25 +0000 | [diff] [blame] | 213 | S7(); |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 214 | |
Anders Carlsson | 5c478cf | 2009-12-04 22:33:25 +0000 | [diff] [blame] | 215 | struct S { S(); }; |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 216 | struct { |
| 217 | S s; |
| 218 | } a; |
| 219 | }; |
| 220 | |
| 221 | // PR5139 |
John McCall | 8e51a1f | 2010-02-18 21:31:48 +0000 | [diff] [blame] | 222 | // CHECK: @_ZN2S7C1Ev |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 223 | // CHECK: @_ZN2S7C2Ev |
| 224 | // CHECK: @"_ZN2S73$_0C1Ev" |
| 225 | S7::S7() {} |
| 226 | |
Anders Carlsson | a769408 | 2009-11-06 02:50:19 +0000 | [diff] [blame] | 227 | // PR5063 |
| 228 | template<typename T> typename __enable_if<(__is_scalar<T>::__value), void>::__type ft8() { } |
| 229 | // CHECK: @_Z3ft8IiEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv |
| 230 | template void ft8<int>(); |
| 231 | // CHECK: @_Z3ft8IPvEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv |
| 232 | template void ft8<void*>(); |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 233 | |
Anders Carlsson | 58040a5 | 2009-12-16 05:48:46 +0000 | [diff] [blame] | 234 | // PR5796 |
| 235 | namespace PR5796 { |
| 236 | template<typename> struct __is_scalar { |
| 237 | enum { __value = 0 }; |
| 238 | }; |
| 239 | |
| 240 | template<bool, typename> struct __enable_if {}; |
| 241 | template<typename T> struct __enable_if<true, T> { typedef T __type; }; |
| 242 | template<typename T> |
| 243 | |
| 244 | // CHECK: define linkonce_odr void @_ZN6PR57968__fill_aIiEENS_11__enable_ifIXntsrNS_11__is_scalarIT_EE7__valueEvE6__typeEv |
| 245 | typename __enable_if<!__is_scalar<T>::__value, void>::__type __fill_a() { }; |
| 246 | |
| 247 | void f() { __fill_a<int>(); } |
| 248 | } |
| 249 | |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 250 | namespace Expressions { |
| 251 | // Unary operators. |
| 252 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 253 | // CHECK: define weak_odr void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 254 | template <int i> void f1(int (*)[(-i) + 2]) { }; |
| 255 | template void f1<1>(int (*)[1]); |
| 256 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 257 | // CHECK: define weak_odr void @_ZN11Expressions2f2ILi1EEEvPApsT__i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 258 | template <int i> void f2(int (*)[+i]) { }; |
| 259 | template void f2<1>(int (*)[1]); |
| 260 | |
| 261 | // Binary operators. |
| 262 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 263 | // CHECK: define weak_odr void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 264 | template <int i> void f3(int (*)[i+i]) { }; |
| 265 | template void f3<1>(int (*)[2]); |
| 266 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 267 | // CHECK: define weak_odr void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 268 | template <int i> void f4(int (*)[2 + i+i]) { }; |
| 269 | template void f4<1>(int (*)[4]); |
| 270 | |
| 271 | // The ternary operator. |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 272 | // CHECK: define weak_odr void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 273 | template <bool b> void f4(int (*)[b ? 1 : 2]) { }; |
| 274 | template void f4<true>(int (*)[1]); |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 275 | } |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 276 | |
| 277 | struct Ops { |
| 278 | Ops& operator+(const Ops&); |
| 279 | Ops& operator-(const Ops&); |
| 280 | Ops& operator&(const Ops&); |
| 281 | Ops& operator*(const Ops&); |
| 282 | |
| 283 | void *v; |
| 284 | }; |
| 285 | |
| 286 | // CHECK: define %struct.Ops* @_ZN3OpsplERKS_ |
| 287 | Ops& Ops::operator+(const Ops&) { return *this; } |
| 288 | // CHECK: define %struct.Ops* @_ZN3OpsmiERKS_ |
| 289 | Ops& Ops::operator-(const Ops&) { return *this; } |
| 290 | // CHECK: define %struct.Ops* @_ZN3OpsanERKS_ |
| 291 | Ops& Ops::operator&(const Ops&) { return *this; } |
| 292 | // CHECK: define %struct.Ops* @_ZN3OpsmlERKS_ |
| 293 | Ops& Ops::operator*(const Ops&) { return *this; } |
| 294 | |
Anders Carlsson | 9e85c74 | 2009-12-23 19:30:55 +0000 | [diff] [blame] | 295 | // PR5861 |
| 296 | namespace PR5861 { |
| 297 | template<bool> class P; |
| 298 | template<> class P<true> {}; |
| 299 | |
| 300 | template<template <bool> class, bool> |
| 301 | struct Policy { }; |
| 302 | |
| 303 | template<typename T, typename = Policy<P, true> > class Alloc |
| 304 | { |
| 305 | T *allocate(int, const void*) { return 0; } |
| 306 | }; |
| 307 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 308 | // CHECK: define weak_odr i8* @_ZN6PR58615AllocIcNS_6PolicyINS_1PELb1EEEE8allocateEiPKv |
Anders Carlsson | 9e85c74 | 2009-12-23 19:30:55 +0000 | [diff] [blame] | 309 | template class Alloc<char>; |
| 310 | } |
Anders Carlsson | f28c687 | 2009-12-23 22:31:44 +0000 | [diff] [blame] | 311 | |
| 312 | // CHECK: define void @_Z1fU13block_pointerFiiiE |
Nuno Lopes | a9efbf0 | 2010-01-07 09:36:51 +0000 | [diff] [blame] | 313 | void f(int (^)(int, int)) { } |
| 314 | |
Sean Hunt | 3145525 | 2010-01-24 03:04:27 +0000 | [diff] [blame] | 315 | void pr5966_foo() { |
| 316 | extern int pr5966_i; |
| 317 | pr5966_i = 0; |
| 318 | } |
| 319 | |
| 320 | static int pr5966_i; |
| 321 | |
| 322 | void pr5966_bar() { |
| 323 | pr5966_i = 0; |
| 324 | } |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 325 | |
| 326 | namespace test0 { |
| 327 | int ovl(int x); |
| 328 | char ovl(double x); |
| 329 | |
| 330 | template <class T> void f(T, char (&buffer)[sizeof(ovl(T()))]) {} |
| 331 | |
| 332 | void test0() { |
| 333 | char buffer[1]; |
| 334 | f(0.0, buffer); |
| 335 | } |
| 336 | // CHECK: define void @_ZN5test05test0Ev() |
| 337 | // CHECK: define linkonce_odr void @_ZN5test01fIdEEvT_RAszcl3ovlcvS1__EE_c( |
| 338 | |
| 339 | void test1() { |
| 340 | char buffer[sizeof(int)]; |
| 341 | f(1, buffer); |
| 342 | } |
| 343 | // CHECK: define void @_ZN5test05test1Ev() |
| 344 | // CHECK: define linkonce_odr void @_ZN5test01fIiEEvT_RAszcl3ovlcvS1__EE_c( |
| 345 | |
| 346 | template <class T> void g(char (&buffer)[sizeof(T() + 5.0f)]) {} |
| 347 | void test2() { |
| 348 | char buffer[sizeof(float)]; |
| 349 | g<float>(buffer); |
| 350 | } |
| 351 | // CHECK: define linkonce_odr void @_ZN5test01gIfEEvRAszplcvT__ELf40A00000E_c( |
| 352 | |
| 353 | template <class T> void h(char (&buffer)[sizeof(T() + 5.0)]) {} |
| 354 | void test3() { |
| 355 | char buffer[sizeof(double)]; |
| 356 | h<float>(buffer); |
| 357 | } |
| 358 | // CHECK: define linkonce_odr void @_ZN5test01hIfEEvRAszplcvT__ELd4014000000000000E_c( |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 359 | |
| 360 | template <class T> void j(char (&buffer)[sizeof(T().buffer)]) {} |
| 361 | struct A { double buffer[128]; }; |
| 362 | void test4() { |
| 363 | char buffer[1024]; |
| 364 | j<A>(buffer); |
| 365 | } |
John McCall | e1e342f | 2010-03-01 19:12:25 +0000 | [diff] [blame] | 366 | // CHECK: define linkonce_odr void @_ZN5test01jINS_1AEEEvRAszdtcvT__E6buffer_c( |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 367 | } |
Douglas Gregor | 32fb4e1 | 2010-02-05 20:45:00 +0000 | [diff] [blame] | 368 | |
| 369 | namespace test1 { |
| 370 | template<typename T> struct X { }; |
| 371 | template<template<class> class Y, typename T> void f(Y<T>) { } |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 372 | // CHECK: define weak_odr void @_ZN5test11fINS_1XEiEEvT_IT0_E |
Douglas Gregor | 32fb4e1 | 2010-02-05 20:45:00 +0000 | [diff] [blame] | 373 | template void f(X<int>); |
| 374 | } |
Anders Carlsson | aec2523 | 2010-02-06 04:52:27 +0000 | [diff] [blame] | 375 | |
| 376 | // CHECK: define internal void @_Z27functionWithInternalLinkagev() |
| 377 | static void functionWithInternalLinkage() { } |
| 378 | void g() { functionWithInternalLinkage(); } |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 379 | |
| 380 | namespace test2 { |
| 381 | template <class T> decltype(((T*) 0)->member) read_member(T& obj) { |
| 382 | return obj.member; |
| 383 | } |
| 384 | |
| 385 | struct A { int member; } obj; |
| 386 | int test() { |
| 387 | return read_member(obj); |
| 388 | } |
| 389 | |
| 390 | // CHECK: define linkonce_odr i32 @_ZN5test211read_memberINS_1AEEEDtptcvPT_Li0E6memberERS2_( |
| 391 | } |
| 392 | |
| 393 | namespace test3 { |
| 394 | struct AmbiguousBase { int ab; }; |
| 395 | struct Path1 : AmbiguousBase { float p; }; |
| 396 | struct Path2 : AmbiguousBase { double p; }; |
| 397 | struct Derived : Path1, Path2 { }; |
| 398 | |
| 399 | //template <class T> decltype(((T*) 0)->Path1::ab) get_ab_1(T &ref) { return ref.Path1::ab; } |
| 400 | //template <class T> decltype(((T*) 0)->Path2::ab) get_ab_2(T &ref) { return ref.Path2::ab; } |
| 401 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 402 | // define weak_odr float @_ZN5test37get_p_1INS_7DerivedEEEDtptcvPT_Li0E5Path11pERS2_( |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 403 | template <class T> decltype(((T*) 0)->Path1::p) get_p_1(T &ref) { return ref.Path1::p; } |
| 404 | |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 405 | // define weak_odr double @_ZN5test37get_p_1INS_7DerivedEEEDtptcvPT_Li0E5Path21pERS2_( |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 406 | template <class T> decltype(((T*) 0)->Path2::p) get_p_2(T &ref) { return ref.Path2::p; } |
| 407 | |
| 408 | Derived obj; |
| 409 | void test() { |
| 410 | // FIXME: uncomment these when we support diamonds competently |
| 411 | //get_ab_1(obj); |
| 412 | //get_ab_2(obj); |
| 413 | get_p_1(obj); |
| 414 | get_p_2(obj); |
| 415 | } |
| 416 | } |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 417 | |
| 418 | // CHECK: define void @_ZN5test41gEPNS_3zedIXadL_ZNS_3foo3barEEEEE |
| 419 | namespace test4 { |
| 420 | struct foo { int bar; }; |
| 421 | template <int (foo::*)> |
| 422 | struct zed {}; |
| 423 | void g(zed<&foo::bar>*) |
| 424 | {} |
| 425 | } |
| 426 | // CHECK: define void @_ZN5test51gEPNS_3zedIXadL_ZNS_3foo3barEEEEE |
| 427 | namespace test5 { |
| 428 | struct foo { static int bar; }; |
| 429 | template <int *> |
| 430 | struct zed {}; |
| 431 | void g(zed<&foo::bar>*) |
| 432 | {} |
| 433 | } |
| 434 | // CHECK: define void @_ZN5test61gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE |
| 435 | namespace test6 { |
| 436 | struct foo { int bar(); }; |
| 437 | template <int (foo::*)()> |
| 438 | struct zed {}; |
| 439 | void g(zed<&foo::bar>*) |
| 440 | {} |
| 441 | } |
| 442 | // CHECK: define void @_ZN5test71gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE |
| 443 | namespace test7 { |
| 444 | struct foo { static int bar(); }; |
| 445 | template <int (*f)()> |
| 446 | struct zed {}; |
| 447 | void g(zed<&foo::bar>*) |
| 448 | {} |
| 449 | } |
Douglas Gregor | 8f51a4f | 2010-03-13 18:23:07 +0000 | [diff] [blame] | 450 | // CHECK: define weak_odr void @_ZN5test81AILZNS_1B5valueEEE3incEv |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 451 | namespace test8 { |
| 452 | template <int &counter> class A { void inc() { counter++; } }; |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 453 | class B { public: static int value; }; |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 454 | template class A<B::value>; |
| 455 | } |
Rafael Espindola | 9b35b25 | 2010-03-17 04:28:11 +0000 | [diff] [blame] | 456 | // CHECK: declare void @_ZN5test91fIiNS_3barEEEvRKNT0_3baz1XE |
| 457 | namespace test9 { |
| 458 | template<class T> |
| 459 | struct foo { |
| 460 | typedef T X; |
| 461 | }; |
| 462 | struct bar { |
| 463 | typedef foo<int> baz; |
| 464 | }; |
| 465 | template <class zaz, class zed> |
| 466 | void f(const typename zed::baz::X&); |
| 467 | void g() { |
| 468 | f<int, bar>( 0); |
| 469 | } |
| 470 | } |
John McCall | de81063 | 2010-04-09 21:48:08 +0000 | [diff] [blame] | 471 | |
| 472 | // <rdar://problem/7825453> |
| 473 | namespace test10 { |
| 474 | template <char P1> struct S {}; |
| 475 | template <char P2> void f(struct S<false ? 'a' : P2> ) {} |
| 476 | |
| 477 | // CHECK: define weak_odr void @_ZN6test101fILc3EEEvNS_1SIXquLb0ELc97ET_EEE( |
| 478 | template void f<(char) 3>(struct S<3>); |
| 479 | } |
Anders Carlsson | 9329668 | 2010-06-02 04:40:13 +0000 | [diff] [blame] | 480 | |
| 481 | namespace test11 { |
| 482 | // CHECK: @_ZN6test111fEz |
| 483 | void f(...) { } |
| 484 | |
| 485 | struct A { |
| 486 | void f(...); |
| 487 | }; |
| 488 | |
| 489 | // CHECK: @_ZN6test111A1fEz |
| 490 | void A::f(...) { } |
| 491 | } |
Anders Carlsson | dfc0d1f | 2010-06-02 05:07:26 +0000 | [diff] [blame] | 492 | |
| 493 | namespace test12 { |
| 494 | |
| 495 | // CHECK: _ZN6test121fENS_1AILt33000EEE |
| 496 | template <unsigned short> struct A { }; |
| 497 | void f(A<33000>) { } |
John McCall | b6f532e | 2010-07-14 06:43:17 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | // PR7446 |
| 501 | namespace test13 { |
| 502 | template <template <class> class T> class A {}; |
| 503 | template <class U> class B {}; |
| 504 | |
| 505 | template <template<class> class T> void foo(const A<T> &a) {} |
| 506 | |
| 507 | // CHECK: define weak_odr void @_ZN6test133fooINS_1BEEEvRKNS_1AIT_EE( |
| 508 | template void foo(const A<B> &a); |
| 509 | } |
Eli Friedman | c00cb64 | 2010-07-18 20:49:59 +0000 | [diff] [blame] | 510 | |
| 511 | namespace test14 { |
| 512 | extern "C" { |
| 513 | struct S { |
| 514 | static int a(), x; |
| 515 | }; |
| 516 | // CHECK: define i32 @_ZN6test141S1aEv |
| 517 | // CHECK: load i32* @_ZN6test141S1xE |
| 518 | int S::a() { return S::x; } |
| 519 | } |
| 520 | } |
John McCall | 3dc7e7b | 2010-07-24 01:17:35 +0000 | [diff] [blame] | 521 | |
| 522 | // rdar://problem/8204122 |
| 523 | namespace test15 { |
| 524 | enum E { e = 3 }; |
| 525 | template <int I> struct S {}; |
| 526 | |
| 527 | template <int I> void f(S<I + e>) {} |
| 528 | |
| 529 | // CHECK: define weak_odr void @_ZN6test151fILi7EEEvNS_1SIXplT_LNS_1EE3EEEE( |
| 530 | template void f<7>(S<7 + e>); |
| 531 | } |
John McCall | 7121c8f | 2010-08-05 22:02:13 +0000 | [diff] [blame] | 532 | |
| 533 | // rdar://problem/8125400. Don't crash. |
| 534 | namespace test16 { |
| 535 | static union {}; |
| 536 | static union { union {}; }; |
| 537 | static union { struct {}; }; |
| 538 | static union { union { union {}; }; }; |
| 539 | static union { union { struct {}; }; }; |
| 540 | static union { struct { union {}; }; }; |
| 541 | static union { struct { struct {}; }; }; |
| 542 | } |
John McCall | 6f615bc | 2010-08-17 21:51:21 +0000 | [diff] [blame] | 543 | |
| 544 | // rdar://problem/8302148 |
| 545 | namespace test17 { |
| 546 | template <int N> struct A {}; |
| 547 | |
| 548 | struct B { |
| 549 | static int foo(void); |
| 550 | }; |
| 551 | |
| 552 | template <class T> A<sizeof(T::foo())> func(void); |
| 553 | |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 554 | // CHECK: define void @_ZN6test174testEv() |
John McCall | 6f615bc | 2010-08-17 21:51:21 +0000 | [diff] [blame] | 555 | // CHECK: call {{.*}} @_ZN6test174funcINS_1BEEENS_1AIXszclsrT_3fooEEEEv() |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 556 | void test() { |
| 557 | func<B>(); |
John McCall | 6f615bc | 2010-08-17 21:51:21 +0000 | [diff] [blame] | 558 | } |
| 559 | } |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 560 | |
| 561 | // PR7891 |
| 562 | namespace test18 { |
| 563 | struct A { |
| 564 | int operator+(); |
| 565 | int operator-(); |
| 566 | int operator*(); |
| 567 | int operator&(); |
| 568 | }; |
| 569 | template <int (A::*)()> struct S {}; |
| 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 | template <typename T> void f(S<&T::operator&>) {} |
| 581 | template void f<A>(S<&A::operator&>); |
| 582 | |
| 583 | // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_plEEE |
| 584 | // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_miEEE |
| 585 | // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_mlEEE |
| 586 | // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_anEEE |
| 587 | } |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 588 | |
| 589 | // rdar://problem/8332117 |
| 590 | namespace test19 { |
| 591 | struct A { |
| 592 | template <typename T> int f(); |
| 593 | int operator+(); |
| 594 | operator int(); |
| 595 | template <typename T> int operator-(); |
| 596 | }; |
| 597 | |
| 598 | template <int (A::*)()> struct S {}; |
| 599 | |
| 600 | template <typename T> void g (S<&T::template f<int> >) {} |
| 601 | template <typename T> void g (S<&T::operator+ >) {} |
| 602 | template <typename T> void g (S<&T::operator int>) {} |
| 603 | template <typename T> void g (S<&T::template operator- <double> >) {} |
| 604 | |
| 605 | // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_1fIiEEEE( |
| 606 | template void g<A>(S<&A::f<int> >); |
| 607 | // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_plEEE( |
| 608 | template void g<A>(S<&A::operator+>); |
| 609 | // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_cviEEE( |
| 610 | template void g<A>(S<&A::operator int>); |
| 611 | // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_miIdEEEE( |
| 612 | template void g<A>(S<&A::operator-<double> >); |
| 613 | } |
| 614 | |
| 615 | namespace test20 { |
| 616 | template <class T> T *f(const T&); |
| 617 | template <class T> T *f(T*); |
| 618 | |
| 619 | // CHECK: define weak_odr void @_ZN6test205test0IiEEvDTcl1fIPT_ELi0EEE( |
| 620 | template <class T> void test0(decltype(f<T*>(0))) {} |
| 621 | template void test0<int>(decltype(f<int*>(0))); |
| 622 | |
| 623 | // CHECK: define weak_odr void @_ZN6test205test1IiEEvDTcl1fIEcvT__EEE( |
| 624 | template <class T> void test1(decltype(f<>(T()))) {} |
| 625 | template void test1<int>(decltype(f<>(int()))); |
| 626 | } |