xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/vector-casts.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc typedef int __v2si __attribute__((__vector_size__(8)));
3f4a2713aSLionel Sambuc typedef short __v4hi __attribute__((__vector_size__(8)));
4f4a2713aSLionel Sambuc typedef short __v8hi __attribute__((__vector_size__(16)));
5*0a6a1f1dSLionel Sambuc typedef short __v3hi __attribute__((__ext_vector_type__(3)));
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc struct S { }; // expected-note 2 {{candidate constructor}}
8f4a2713aSLionel Sambuc 
f()9f4a2713aSLionel Sambuc void f() {
10f4a2713aSLionel Sambuc   __v2si v2si;
11f4a2713aSLionel Sambuc   __v4hi v4hi;
12f4a2713aSLionel Sambuc   __v8hi v8hi;
13f4a2713aSLionel Sambuc   unsigned long long ll;
14f4a2713aSLionel Sambuc   unsigned char c;
15f4a2713aSLionel Sambuc   S s;
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc   (void)reinterpret_cast<__v2si>(v4hi);
18f4a2713aSLionel Sambuc   (void)(__v2si)v4hi;
19f4a2713aSLionel Sambuc   (void)reinterpret_cast<__v4hi>(v2si);
20f4a2713aSLionel Sambuc   (void)(__v4hi)v2si;
21f4a2713aSLionel Sambuc   (void)reinterpret_cast<unsigned long long>(v2si);
22f4a2713aSLionel Sambuc   (void)(unsigned long long)v2si;
23f4a2713aSLionel Sambuc   (void)reinterpret_cast<__v2si>(ll);
24f4a2713aSLionel Sambuc   (void)(__v2si)(ll);
25f4a2713aSLionel Sambuc 
26*0a6a1f1dSLionel Sambuc   (void)reinterpret_cast<S>(v2si); // expected-error {{reinterpret_cast from '__v2si' (vector of 2 'int' values) to 'S' is not allowed}}
27*0a6a1f1dSLionel Sambuc   (void)(S)v2si; // expected-error {{no matching conversion for C-style cast from '__v2si' (vector of 2 'int' values) to 'S'}}
28*0a6a1f1dSLionel Sambuc   (void)reinterpret_cast<__v2si>(s); // expected-error {{reinterpret_cast from 'S' to '__v2si' (vector of 2 'int' values) is not allowed}}
29*0a6a1f1dSLionel Sambuc   (void)(__v2si)s; // expected-error {{cannot convert 'S' to '__v2si' (vector of 2 'int' values) without a conversion operator}}
30f4a2713aSLionel Sambuc 
31*0a6a1f1dSLionel Sambuc   (void)reinterpret_cast<unsigned char>(v2si); // expected-error {{reinterpret_cast from vector '__v2si' (vector of 2 'int' values) to scalar 'unsigned char' of different size}}
32*0a6a1f1dSLionel Sambuc   (void)(unsigned char)v2si; // expected-error {{C-style cast from vector '__v2si' (vector of 2 'int' values) to scalar 'unsigned char' of different size}}
33*0a6a1f1dSLionel Sambuc   (void)reinterpret_cast<__v2si>(c); // expected-error {{reinterpret_cast from scalar 'unsigned char' to vector '__v2si' (vector of 2 'int' values) of different size}}
34f4a2713aSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc   (void)reinterpret_cast<__v8hi>(v4hi); // expected-error {{reinterpret_cast from vector '__v4hi' (vector of 4 'short' values) to vector '__v8hi' (vector of 8 'short' values) of different size}}
36*0a6a1f1dSLionel Sambuc   (void)(__v8hi)v4hi; // expected-error {{C-style cast from vector '__v4hi' (vector of 4 'short' values) to vector '__v8hi' (vector of 8 'short' values) of different size}}
37*0a6a1f1dSLionel Sambuc   (void)reinterpret_cast<__v4hi>(v8hi); // expected-error {{reinterpret_cast from vector '__v8hi' (vector of 8 'short' values) to vector '__v4hi' (vector of 4 'short' values) of different size}}
38*0a6a1f1dSLionel Sambuc   (void)(__v4hi)v8hi; // expected-error {{C-style cast from vector '__v8hi' (vector of 8 'short' values) to vector '__v4hi' (vector of 4 'short' values) of different size}}
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc struct testvec {
42*0a6a1f1dSLionel Sambuc   __v2si v;
maddtestvec43*0a6a1f1dSLionel Sambuc   void madd(const testvec& rhs) {
44*0a6a1f1dSLionel Sambuc     v = v + rhs; // expected-error {{can't convert between vector and non-scalar values}}
45*0a6a1f1dSLionel Sambuc   }
madd2testvec46*0a6a1f1dSLionel Sambuc   void madd2(testvec rhs) {
47*0a6a1f1dSLionel Sambuc     v = v + rhs; // expected-error {{can't convert between vector and non-scalar values}}
48*0a6a1f1dSLionel Sambuc   }
49*0a6a1f1dSLionel Sambuc };
50f4a2713aSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc // rdar://15931426
52*0a6a1f1dSLionel Sambuc //   Conversions for return values.
threeToFour(__v3hi v)53*0a6a1f1dSLionel Sambuc __v4hi threeToFour(__v3hi v) { // expected-note {{not viable}}
54*0a6a1f1dSLionel Sambuc   return v; // expected-error {{cannot initialize return object}}
55*0a6a1f1dSLionel Sambuc }
fourToThree(__v4hi v)56*0a6a1f1dSLionel Sambuc __v3hi fourToThree(__v4hi v) { // expected-note {{not viable}}
57*0a6a1f1dSLionel Sambuc   return v; // expected-error {{cannot initialize return object}}
58*0a6a1f1dSLionel Sambuc }
59*0a6a1f1dSLionel Sambuc //   Conversions for calls.
call3to4(__v4hi v)60*0a6a1f1dSLionel Sambuc void call3to4(__v4hi v) {
61*0a6a1f1dSLionel Sambuc   (void) threeToFour(v); // expected-error {{no matching function for call}}
62*0a6a1f1dSLionel Sambuc }
call4to3(__v3hi v)63*0a6a1f1dSLionel Sambuc void call4to3(__v3hi v) {
64*0a6a1f1dSLionel Sambuc   (void) fourToThree(v); // expected-error {{no matching function for call}}
65*0a6a1f1dSLionel Sambuc }
66