Douglas Gregor | fb4a543 | 2010-05-18 22:42:18 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s |
| 2 | typedef char char16 __attribute__ ((__vector_size__ (16))); |
| 3 | typedef long long longlong16 __attribute__ ((__vector_size__ (16))); |
| 4 | typedef char char16_e __attribute__ ((__ext_vector_type__ (16))); |
| 5 | typedef long long longlong16_e __attribute__ ((__ext_vector_type__ (2))); |
| 6 | |
Douglas Gregor | fb4a543 | 2010-05-18 22:42:18 +0000 | [diff] [blame] | 7 | // Test overloading and function calls with vector types. |
| 8 | void f0(char16); |
| 9 | |
| 10 | void f0_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) { |
| 11 | f0(c16); |
| 12 | f0(ll16); |
| 13 | f0(c16e); |
| 14 | f0(ll16e); |
| 15 | } |
| 16 | |
| 17 | int &f1(char16); // expected-note 2{{candidate function}} |
| 18 | float &f1(longlong16); // expected-note 2{{candidate function}} |
| 19 | |
| 20 | void f1_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) { |
| 21 | int &ir1 = f1(c16); |
| 22 | float &fr1 = f1(ll16); |
| 23 | f1(c16e); // expected-error{{call to 'f1' is ambiguous}} |
| 24 | f1(ll16e); // expected-error{{call to 'f1' is ambiguous}} |
| 25 | } |
| 26 | |
Douglas Gregor | a115855 | 2010-05-18 23:05:44 +0000 | [diff] [blame] | 27 | void f2(char16_e); // expected-note{{no known conversion from 'longlong16_e' to 'char16_e' for 1st argument}} \ |
| 28 | // expected-note{{candidate function not viable: no known conversion from 'convertible_to<longlong16_e>' to 'char16_e' for 1st argument}} |
Douglas Gregor | fb4a543 | 2010-05-18 22:42:18 +0000 | [diff] [blame] | 29 | |
| 30 | void f2_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) { |
| 31 | f2(c16); |
| 32 | f2(ll16); |
| 33 | f2(c16e); |
| 34 | f2(ll16e); // expected-error{{no matching function}} |
| 35 | f2('a'); |
| 36 | f2(17); |
| 37 | } |
Douglas Gregor | fb4a543 | 2010-05-18 22:42:18 +0000 | [diff] [blame] | 38 | |
| 39 | // Test the conditional operator with vector types. |
| 40 | void conditional(bool Cond, char16 c16, longlong16 ll16, char16_e c16e, |
| 41 | longlong16_e ll16e) { |
| 42 | // Conditional operators with the same type. |
| 43 | __typeof__(Cond? c16 : c16) *c16p1 = &c16; |
| 44 | __typeof__(Cond? ll16 : ll16) *ll16p1 = &ll16; |
| 45 | __typeof__(Cond? c16e : c16e) *c16ep1 = &c16e; |
| 46 | __typeof__(Cond? ll16e : ll16e) *ll16ep1 = &ll16e; |
| 47 | |
| 48 | // Conditional operators with similar types. |
| 49 | __typeof__(Cond? c16 : c16e) *c16ep2 = &c16e; |
| 50 | __typeof__(Cond? c16e : c16) *c16ep3 = &c16e; |
| 51 | __typeof__(Cond? ll16 : ll16e) *ll16ep2 = &ll16e; |
| 52 | __typeof__(Cond? ll16e : ll16) *ll16ep3 = &ll16e; |
| 53 | |
Eric Christopher | e84f9eb | 2010-08-26 00:42:16 +0000 | [diff] [blame] | 54 | // Conditional operators with compatible types under -flax-vector-conversions (default) |
| 55 | (void)(Cond? c16 : ll16); |
| 56 | (void)(Cond? ll16e : c16e); |
| 57 | (void)(Cond? ll16e : c16); |
Douglas Gregor | fb4a543 | 2010-05-18 22:42:18 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // Test C++ cast'ing of vector types. |
| 61 | void casts(longlong16 ll16, longlong16_e ll16e) { |
| 62 | // C-style casts. |
| 63 | (void)(char16)ll16; |
| 64 | (void)(char16_e)ll16; |
| 65 | (void)(longlong16)ll16; |
| 66 | (void)(longlong16_e)ll16; |
| 67 | (void)(char16)ll16e; |
| 68 | (void)(char16_e)ll16e; |
| 69 | (void)(longlong16)ll16e; |
| 70 | (void)(longlong16_e)ll16e; |
| 71 | |
| 72 | // Function-style casts. |
| 73 | (void)char16(ll16); |
| 74 | (void)char16_e(ll16); |
| 75 | (void)longlong16(ll16); |
| 76 | (void)longlong16_e(ll16); |
| 77 | (void)char16(ll16e); |
| 78 | (void)char16_e(ll16e); |
| 79 | (void)longlong16(ll16e); |
| 80 | (void)longlong16_e(ll16e); |
| 81 | |
| 82 | // static_cast |
| 83 | (void)static_cast<char16>(ll16); |
| 84 | (void)static_cast<char16_e>(ll16); |
| 85 | (void)static_cast<longlong16>(ll16); |
| 86 | (void)static_cast<longlong16_e>(ll16); |
| 87 | (void)static_cast<char16>(ll16e); |
| 88 | (void)static_cast<char16_e>(ll16e); // expected-error{{static_cast from 'longlong16_e' to 'char16_e' is not allowed}} |
| 89 | (void)static_cast<longlong16>(ll16e); |
| 90 | (void)static_cast<longlong16_e>(ll16e); |
| 91 | |
| 92 | // reinterpret_cast |
| 93 | (void)reinterpret_cast<char16>(ll16); |
| 94 | (void)reinterpret_cast<char16_e>(ll16); |
| 95 | (void)reinterpret_cast<longlong16>(ll16); |
| 96 | (void)reinterpret_cast<longlong16_e>(ll16); |
| 97 | (void)reinterpret_cast<char16>(ll16e); |
| 98 | (void)reinterpret_cast<char16_e>(ll16e); |
| 99 | (void)reinterpret_cast<longlong16>(ll16e); |
| 100 | (void)reinterpret_cast<longlong16_e>(ll16e); |
| 101 | } |
Douglas Gregor | a115855 | 2010-05-18 23:05:44 +0000 | [diff] [blame] | 102 | |
| 103 | template<typename T> |
Douglas Gregor | 26bcf67 | 2010-05-19 03:21:00 +0000 | [diff] [blame] | 104 | struct convertible_to { // expected-note 3 {{candidate function (the implicit copy assignment operator)}} |
Douglas Gregor | a115855 | 2010-05-18 23:05:44 +0000 | [diff] [blame] | 105 | operator T() const; |
| 106 | }; |
| 107 | |
Douglas Gregor | 26bcf67 | 2010-05-19 03:21:00 +0000 | [diff] [blame] | 108 | void test_implicit_conversions(bool Cond, char16 c16, longlong16 ll16, |
| 109 | char16_e c16e, longlong16_e ll16e, |
Douglas Gregor | a115855 | 2010-05-18 23:05:44 +0000 | [diff] [blame] | 110 | convertible_to<char16> to_c16, |
| 111 | convertible_to<longlong16> to_ll16, |
| 112 | convertible_to<char16_e> to_c16e, |
Douglas Gregor | 26bcf67 | 2010-05-19 03:21:00 +0000 | [diff] [blame] | 113 | convertible_to<longlong16_e> to_ll16e, |
| 114 | convertible_to<char16&> rto_c16, |
| 115 | convertible_to<char16_e&> rto_c16e) { |
Douglas Gregor | a115855 | 2010-05-18 23:05:44 +0000 | [diff] [blame] | 116 | f0(to_c16); |
| 117 | f0(to_ll16); |
| 118 | f0(to_c16e); |
| 119 | f0(to_ll16e); |
| 120 | f2(to_c16); |
| 121 | f2(to_ll16); |
| 122 | f2(to_c16e); |
| 123 | f2(to_ll16e); // expected-error{{no matching function}} |
Douglas Gregor | 26bcf67 | 2010-05-19 03:21:00 +0000 | [diff] [blame] | 124 | |
| 125 | (void)(c16 == c16e); |
| 126 | (void)(c16 == to_c16); |
| 127 | (void)+to_c16; |
| 128 | (void)-to_c16; |
| 129 | (void)~to_c16; |
| 130 | (void)(to_c16 == to_c16e); |
| 131 | (void)(to_c16 != to_c16e); |
| 132 | (void)(to_c16 < to_c16e); |
| 133 | (void)(to_c16 <= to_c16e); |
| 134 | (void)(to_c16 > to_c16e); |
| 135 | (void)(to_c16 >= to_c16e); |
| 136 | (void)(to_c16 + to_c16); |
| 137 | (void)(to_c16 - to_c16); |
| 138 | (void)(to_c16 * to_c16); |
| 139 | (void)(to_c16 / to_c16); |
| 140 | (void)(rto_c16 = to_c16); // expected-error{{no viable overloaded '='}} |
| 141 | (void)(rto_c16 += to_c16); |
| 142 | (void)(rto_c16 -= to_c16); |
| 143 | (void)(rto_c16 *= to_c16); |
| 144 | (void)(rto_c16 /= to_c16); |
| 145 | |
| 146 | (void)+to_c16e; |
| 147 | (void)-to_c16e; |
| 148 | (void)~to_c16e; |
| 149 | (void)(to_c16e == to_c16e); |
| 150 | (void)(to_c16e != to_c16e); |
| 151 | (void)(to_c16e < to_c16e); |
| 152 | (void)(to_c16e <= to_c16e); |
| 153 | (void)(to_c16e > to_c16e); |
| 154 | (void)(to_c16e >= to_c16e); |
| 155 | (void)(to_c16e + to_c16); |
| 156 | (void)(to_c16e - to_c16); |
| 157 | (void)(to_c16e * to_c16); |
| 158 | (void)(to_c16e / to_c16); |
| 159 | (void)(rto_c16e = to_c16); // expected-error{{no viable overloaded '='}} |
| 160 | (void)(rto_c16e += to_c16); |
| 161 | (void)(rto_c16e -= to_c16); |
| 162 | (void)(rto_c16e *= to_c16); |
| 163 | (void)(rto_c16e /= to_c16); |
| 164 | |
| 165 | (void)+to_c16; |
| 166 | (void)-to_c16; |
| 167 | (void)~to_c16; |
| 168 | (void)(to_c16 == to_c16e); |
| 169 | (void)(to_c16 != to_c16e); |
| 170 | (void)(to_c16 < to_c16e); |
| 171 | (void)(to_c16 <= to_c16e); |
| 172 | (void)(to_c16 > to_c16e); |
| 173 | (void)(to_c16 >= to_c16e); |
| 174 | (void)(to_c16 + to_c16e); |
| 175 | (void)(to_c16 - to_c16e); |
| 176 | (void)(to_c16 * to_c16e); |
| 177 | (void)(to_c16 / to_c16e); |
| 178 | (void)(rto_c16 = c16e); // expected-error{{no viable overloaded '='}} |
Eli Friedman | b9b4b78 | 2011-06-23 18:10:35 +0000 | [diff] [blame] | 179 | (void)(rto_c16 += to_c16e); |
| 180 | (void)(rto_c16 -= to_c16e); |
| 181 | (void)(rto_c16 *= to_c16e); |
| 182 | (void)(rto_c16 /= to_c16e); |
Douglas Gregor | 26bcf67 | 2010-05-19 03:21:00 +0000 | [diff] [blame] | 183 | |
| 184 | (void)(Cond? to_c16 : to_c16e); |
| 185 | (void)(Cond? to_ll16e : to_ll16); |
Eric Christopher | e84f9eb | 2010-08-26 00:42:16 +0000 | [diff] [blame] | 186 | |
| 187 | // These 2 are convertable with -flax-vector-conversions (default) |
| 188 | (void)(Cond? to_c16 : to_ll16); |
| 189 | (void)(Cond? to_c16e : to_ll16e); |
Douglas Gregor | a115855 | 2010-05-18 23:05:44 +0000 | [diff] [blame] | 190 | } |
Douglas Gregor | 7c5b109 | 2010-06-22 16:52:27 +0000 | [diff] [blame] | 191 | |
| 192 | typedef float fltx2 __attribute__((__vector_size__(8))); |
| 193 | typedef float fltx4 __attribute__((__vector_size__(16))); |
| 194 | typedef double dblx2 __attribute__((__vector_size__(16))); |
| 195 | typedef double dblx4 __attribute__((__vector_size__(32))); |
| 196 | |
| 197 | void accept_fltx2(fltx2); // expected-note{{candidate function not viable: no known conversion from 'double' to 'fltx2' for 1st argument}} |
| 198 | void accept_fltx4(fltx4); |
| 199 | void accept_dblx2(dblx2); |
| 200 | void accept_dblx4(dblx4); |
| 201 | void accept_bool(bool); // expected-note{{candidate function not viable: no known conversion from 'fltx2' to 'bool' for 1st argument}} |
| 202 | |
| 203 | void test(fltx2 fltx2_val, fltx4 fltx4_val, dblx2 dblx2_val, dblx4 dblx4_val) { |
| 204 | // Exact matches |
| 205 | accept_fltx2(fltx2_val); |
| 206 | accept_fltx4(fltx4_val); |
| 207 | accept_dblx2(dblx2_val); |
| 208 | accept_dblx4(dblx4_val); |
| 209 | |
| 210 | // Same-size conversions |
| 211 | // FIXME: G++ rejects these conversions, we accept them. Revisit this! |
| 212 | accept_fltx4(dblx2_val); |
| 213 | accept_dblx2(fltx4_val); |
| 214 | |
| 215 | // Conversion to bool. |
| 216 | accept_bool(fltx2_val); // expected-error{{no matching function for call to 'accept_bool'}} |
| 217 | |
| 218 | // Scalar-to-vector conversions. |
| 219 | accept_fltx2(1.0); // expected-error{{no matching function for call to 'accept_fltx2'}} |
| 220 | } |