1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++11 %s
5 typedef char char16 __attribute__ ((__vector_size__ (16)));
6 typedef long long longlong16 __attribute__ ((__vector_size__ (16)));
7 typedef char char16_e __attribute__ ((__ext_vector_type__ (16)));
8 typedef long long longlong16_e __attribute__ ((__ext_vector_type__ (2)));
10 // Test overloading and function calls with vector types.
13 void f0_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) {
20 int &f1(char16); // expected-note 2{{candidate function}}
21 float &f1(longlong16); // expected-note 2{{candidate function}}
23 void f1_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) {
25 float &fr1 = f1(ll16);
26 f1(c16e); // expected-error{{call to 'f1' is ambiguous}}
27 f1(ll16e); // expected-error{{call to 'f1' is ambiguous}}
30 void f2(char16_e); // expected-note{{no known conversion from 'longlong16_e' (vector of 2 'long long' values) to 'char16_e' (vector of 16 'char' values) for 1st argument}} \
31 // expected-note{{candidate function not viable: no known conversion from 'convertible_to<longlong16_e>' to 'char16_e' (vector of 16 'char' values) for 1st argument}}
33 void f2_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) {
37 f2(ll16e); // expected-error{{no matching function}}
42 // Test the conditional operator with vector types.
43 void conditional(bool Cond, char16 c16, longlong16 ll16, char16_e c16e,
45 // Conditional operators with the same type.
46 __typeof__(Cond? c16 : c16) *c16p1 = &c16;
47 __typeof__(Cond? ll16 : ll16) *ll16p1 = &ll16;
48 __typeof__(Cond? c16e : c16e) *c16ep1 = &c16e;
49 __typeof__(Cond? ll16e : ll16e) *ll16ep1 = &ll16e;
51 // Conditional operators with similar types.
52 __typeof__(Cond? c16 : c16e) *c16ep2 = &c16e;
53 __typeof__(Cond? c16e : c16) *c16ep3 = &c16e;
54 __typeof__(Cond? ll16 : ll16e) *ll16ep2 = &ll16e;
55 __typeof__(Cond? ll16e : ll16) *ll16ep3 = &ll16e;
57 // Conditional operators with compatible types under -flax-vector-conversions (default)
58 (void)(Cond? c16 : ll16);
59 (void)(Cond? ll16e : c16e);
60 (void)(Cond? ll16e : c16);
63 // Test C++ cast'ing of vector types.
64 void casts(longlong16 ll16, longlong16_e ll16e) {
68 (void)(longlong16)ll16;
69 (void)(longlong16_e)ll16;
71 (void)(char16_e)ll16e;
72 (void)(longlong16)ll16e;
73 (void)(longlong16_e)ll16e;
75 // Function-style casts.
78 (void)longlong16(ll16);
79 (void)longlong16_e(ll16);
81 (void)char16_e(ll16e);
82 (void)longlong16(ll16e);
83 (void)longlong16_e(ll16e);
86 (void)static_cast<char16>(ll16);
87 (void)static_cast<char16_e>(ll16);
88 (void)static_cast<longlong16>(ll16);
89 (void)static_cast<longlong16_e>(ll16);
90 (void)static_cast<char16>(ll16e);
91 (void)static_cast<char16_e>(ll16e); // expected-error{{static_cast from 'longlong16_e' (vector of 2 'long long' values) to 'char16_e' (vector of 16 'char' values) is not allowed}}
92 (void)static_cast<longlong16>(ll16e);
93 (void)static_cast<longlong16_e>(ll16e);
96 (void)reinterpret_cast<char16>(ll16);
97 (void)reinterpret_cast<char16_e>(ll16);
98 (void)reinterpret_cast<longlong16>(ll16);
99 (void)reinterpret_cast<longlong16_e>(ll16);
100 (void)reinterpret_cast<char16>(ll16e);
101 (void)reinterpret_cast<char16_e>(ll16e);
102 (void)reinterpret_cast<longlong16>(ll16e);
103 (void)reinterpret_cast<longlong16_e>(ll16e);
107 struct convertible_to { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable}}
108 #if __cplusplus >= 201103L // C++11 or later
109 // expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}}
114 void test_implicit_conversions(bool Cond, char16 c16, longlong16 ll16,
115 char16_e c16e, longlong16_e ll16e,
116 convertible_to<char16> to_c16,
117 convertible_to<longlong16> to_ll16,
118 convertible_to<char16_e> to_c16e,
119 convertible_to<longlong16_e> to_ll16e,
120 convertible_to<char16&> rto_c16,
121 convertible_to<char16_e&> rto_c16e) {
129 f2(to_ll16e); // expected-error{{no matching function}}
132 (void)(c16 == to_c16);
136 (void)(to_c16 == to_c16e);
137 (void)(to_c16 != to_c16e);
138 (void)(to_c16 < to_c16e);
139 (void)(to_c16 <= to_c16e);
140 (void)(to_c16 > to_c16e);
141 (void)(to_c16 >= to_c16e);
142 (void)(to_c16 + to_c16);
143 (void)(to_c16 - to_c16);
144 (void)(to_c16 * to_c16);
145 (void)(to_c16 / to_c16);
146 (void)(rto_c16 = to_c16); // expected-error{{no viable overloaded '='}}
147 (void)(rto_c16 += to_c16);
148 (void)(rto_c16 -= to_c16);
149 (void)(rto_c16 *= to_c16);
150 (void)(rto_c16 /= to_c16);
155 (void)(to_c16e == to_c16e);
156 (void)(to_c16e != to_c16e);
157 (void)(to_c16e < to_c16e);
158 (void)(to_c16e <= to_c16e);
159 (void)(to_c16e > to_c16e);
160 (void)(to_c16e >= to_c16e);
161 (void)(to_c16e + to_c16);
162 (void)(to_c16e - to_c16);
163 (void)(to_c16e * to_c16);
164 (void)(to_c16e / to_c16);
165 (void)(rto_c16e = to_c16); // expected-error{{no viable overloaded '='}}
166 (void)(rto_c16e += to_c16);
167 (void)(rto_c16e -= to_c16);
168 (void)(rto_c16e *= to_c16);
169 (void)(rto_c16e /= to_c16);
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)(to_c16 > to_c16e);
179 (void)(to_c16 >= to_c16e);
180 (void)(to_c16 + to_c16e);
181 (void)(to_c16 - to_c16e);
182 (void)(to_c16 * to_c16e);
183 (void)(to_c16 / to_c16e);
184 (void)(rto_c16 = c16e); // expected-error{{no viable overloaded '='}}
185 (void)(rto_c16 += to_c16e);
186 (void)(rto_c16 -= to_c16e);
187 (void)(rto_c16 *= to_c16e);
188 (void)(rto_c16 /= to_c16e);
190 (void)(Cond? to_c16 : to_c16e);
191 (void)(Cond? to_ll16e : to_ll16);
193 // These 2 are convertible with -flax-vector-conversions (default)
194 (void)(Cond? to_c16 : to_ll16);
195 (void)(Cond? to_c16e : to_ll16e);
198 typedef float fltx2 __attribute__((__vector_size__(8)));
199 typedef float fltx4 __attribute__((__vector_size__(16)));
200 typedef double dblx2 __attribute__((__vector_size__(16)));
201 typedef double dblx4 __attribute__((__vector_size__(32)));
203 void accept_fltx2(fltx2); // expected-note{{candidate function not viable: no known conversion from 'double' to 'fltx2' (vector of 2 'float' values) for 1st argument}}
204 void accept_fltx4(fltx4);
205 void accept_dblx2(dblx2);
206 void accept_dblx4(dblx4);
207 void accept_bool(bool); // expected-note{{candidate function not viable: no known conversion from 'fltx2' (vector of 2 'float' values) to 'bool' for 1st argument}}
209 void test(fltx2 fltx2_val, fltx4 fltx4_val, dblx2 dblx2_val, dblx4 dblx4_val) {
211 accept_fltx2(fltx2_val);
212 accept_fltx4(fltx4_val);
213 accept_dblx2(dblx2_val);
214 accept_dblx4(dblx4_val);
216 // Same-size conversions
217 // FIXME: G++ rejects these conversions, we accept them. Revisit this!
218 accept_fltx4(dblx2_val);
219 accept_dblx2(fltx4_val);
221 // Conversion to bool.
222 accept_bool(fltx2_val); // expected-error{{no matching function for call to 'accept_bool'}}
224 // Scalar-to-vector conversions.
225 accept_fltx2(1.0); // expected-error{{no matching function for call to 'accept_fltx2'}}
228 typedef int intx4 __attribute__((__vector_size__(16)));
229 typedef int inte4 __attribute__((__ext_vector_type__(4)));
230 typedef int flte4 __attribute__((__ext_vector_type__(4)));
232 void test_mixed_vector_types(fltx4 f, intx4 n, flte4 g, flte4 m) {
277 template<typename T> void test_pseudo_dtor_tmpl(T *ptr) {
282 void test_pseudo_dtor(fltx4 *f) {
285 test_pseudo_dtor_tmpl(f);
289 typedef __attribute__((ext_vector_type(4))) int vi4;
290 const int &reference_to_vec_element = vi4(1).x;
293 typedef bool bad __attribute__((__vector_size__(16))); // expected-error {{invalid vector element type 'bool'}}
295 namespace Templates {
296 template <typename Elt, unsigned Size>
297 struct TemplateVectorType {
298 typedef Elt __attribute__((__vector_size__(Size))) type;
301 template <int N, typename T>
303 typedef T __attribute__((vector_size(N * sizeof(T)))) type;
304 typedef T __attribute__((vector_size(8192))) type2;
305 typedef T __attribute__((vector_size(3))) type3;
309 const TemplateVectorType<float, 32>::type Works = {};
310 const TemplateVectorType<int, 32>::type Works2 = {};
311 // expected-error@298 {{invalid vector element type 'bool'}}
312 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<bool, 32>' requested here}}
313 const TemplateVectorType<bool, 32>::type NoBool;
314 // expected-error@298 {{invalid vector element type 'int __attribute__((ext_vector_type(4)))' (vector of 4 'int' values)}}
315 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int __attribute__((ext_vector_type(4))), 32>' requested here}}
316 const TemplateVectorType<vi4, 32>::type NoComplex;
317 // expected-error@298 {{vector size not an integral multiple of component size}}
318 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 33>' requested here}}
319 const TemplateVectorType<int, 33>::type BadSize;
320 // expected-error@298 {{vector size too large}}
321 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 8192>' requested here}}
322 const TemplateVectorType<int, 8192>::type TooLarge;
323 // expected-error@298 {{zero vector size}}
324 // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 0>' requested here}}
325 const TemplateVectorType<int, 0>::type Zero;
327 // expected-error@304 {{vector size too large}}
328 // expected-error@305 {{vector size not an integral multiple of component size}}
329 // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, int>' requested here}}
330 const PR15730<8, int>::type PR15730_1 = {};
331 // expected-error@304 {{vector size too large}}
332 // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, char>' requested here}}
333 const PR15730<8, char>::type2 PR15730_2 = {};
336 } // namespace Templates