1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify -std=c++11 %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s
3*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc __vector char vv_c;
6f4a2713aSLionel Sambuc __vector signed char vv_sc;
7f4a2713aSLionel Sambuc __vector unsigned char vv_uc;
8f4a2713aSLionel Sambuc __vector short vv_s;
9f4a2713aSLionel Sambuc __vector signed short vv_ss;
10f4a2713aSLionel Sambuc __vector unsigned short vv_us;
11f4a2713aSLionel Sambuc __vector short int vv_si;
12f4a2713aSLionel Sambuc __vector signed short int vv_ssi;
13f4a2713aSLionel Sambuc __vector unsigned short int vv_usi;
14f4a2713aSLionel Sambuc __vector int vv_i;
15f4a2713aSLionel Sambuc __vector signed int vv_sint;
16f4a2713aSLionel Sambuc __vector unsigned int vv_ui;
17f4a2713aSLionel Sambuc __vector float vv_f;
18f4a2713aSLionel Sambuc __vector bool char vv_bc;
19f4a2713aSLionel Sambuc __vector bool short vv_bs;
20f4a2713aSLionel Sambuc __vector bool int vv_bi;
21f4a2713aSLionel Sambuc __vector __pixel vv_p;
22f4a2713aSLionel Sambuc __vector pixel vv__p;
23f4a2713aSLionel Sambuc __vector int vf__r();
24f4a2713aSLionel Sambuc void vf__a(__vector int a);
25f4a2713aSLionel Sambuc void vf__a2(int b, __vector int a);
26f4a2713aSLionel Sambuc
27f4a2713aSLionel Sambuc vector char v_c;
28f4a2713aSLionel Sambuc vector signed char v_sc;
29f4a2713aSLionel Sambuc vector unsigned char v_uc;
30f4a2713aSLionel Sambuc vector short v_s;
31f4a2713aSLionel Sambuc vector signed short v_ss;
32f4a2713aSLionel Sambuc vector unsigned short v_us;
33f4a2713aSLionel Sambuc vector short int v_si;
34f4a2713aSLionel Sambuc vector signed short int v_ssi;
35f4a2713aSLionel Sambuc vector unsigned short int v_usi;
36f4a2713aSLionel Sambuc vector int v_i;
37f4a2713aSLionel Sambuc vector signed int v_sint;
38f4a2713aSLionel Sambuc vector unsigned int v_ui;
39f4a2713aSLionel Sambuc vector float v_f;
40f4a2713aSLionel Sambuc vector bool char v_bc;
41f4a2713aSLionel Sambuc vector bool short v_bs;
42f4a2713aSLionel Sambuc vector bool int v_bi;
43f4a2713aSLionel Sambuc vector __pixel v_p;
44f4a2713aSLionel Sambuc vector pixel v__p;
45f4a2713aSLionel Sambuc vector int f__r();
46f4a2713aSLionel Sambuc void f_a(vector int a);
47f4a2713aSLionel Sambuc void f_a2(int b, vector int a);
48f4a2713aSLionel Sambuc
49f4a2713aSLionel Sambuc vector int v = (vector int)(-1);
50f4a2713aSLionel Sambuc
51f4a2713aSLionel Sambuc // These should have warnings.
52f4a2713aSLionel Sambuc __vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
53f4a2713aSLionel Sambuc __vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
54f4a2713aSLionel Sambuc __vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
55f4a2713aSLionel Sambuc __vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
56f4a2713aSLionel Sambuc __vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
57f4a2713aSLionel Sambuc __vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
58f4a2713aSLionel Sambuc vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
59f4a2713aSLionel Sambuc vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
60f4a2713aSLionel Sambuc vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
61f4a2713aSLionel Sambuc vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
62f4a2713aSLionel Sambuc vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
63f4a2713aSLionel Sambuc vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
64*0a6a1f1dSLionel Sambuc __vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}}
65*0a6a1f1dSLionel Sambuc vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}}
66f4a2713aSLionel Sambuc
67f4a2713aSLionel Sambuc // These should have errors.
68*0a6a1f1dSLionel Sambuc __vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}}
69*0a6a1f1dSLionel Sambuc vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}}
70*0a6a1f1dSLionel Sambuc __vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}}
71*0a6a1f1dSLionel Sambuc vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}}
72f4a2713aSLionel Sambuc vector bool v_b; // expected-error {{C++ requires a type specifier for all declarations}}
73f4a2713aSLionel Sambuc vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}}
74f4a2713aSLionel Sambuc vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}}
75f4a2713aSLionel Sambuc vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
76f4a2713aSLionel Sambuc vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
77f4a2713aSLionel Sambuc vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
78f4a2713aSLionel Sambuc vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}}
79f4a2713aSLionel Sambuc vector bool long long v_bll; // expected-error {{cannot use 'long long' with '__vector bool'}}
80f4a2713aSLionel Sambuc
81*0a6a1f1dSLionel Sambuc // vector long is deprecated, but vector long long is not.
82*0a6a1f1dSLionel Sambuc vector long long v_ll;
83*0a6a1f1dSLionel Sambuc vector signed long long v_sll;
84*0a6a1f1dSLionel Sambuc vector unsigned long long v_ull;
85*0a6a1f1dSLionel Sambuc
f()86f4a2713aSLionel Sambuc void f() {
87f4a2713aSLionel Sambuc __vector unsigned int v = {0,0,0,0};
88f4a2713aSLionel Sambuc __vector int v__cast = (__vector int)v;
89f4a2713aSLionel Sambuc __vector int v_cast = (vector int)v;
90f4a2713aSLionel Sambuc __vector char vb_cast = (vector char)v;
91f4a2713aSLionel Sambuc
92f4a2713aSLionel Sambuc // Check some casting between gcc and altivec vectors.
93f4a2713aSLionel Sambuc #define gccvector __attribute__((vector_size(16)))
94f4a2713aSLionel Sambuc gccvector unsigned int gccv = {0,0,0,0};
95f4a2713aSLionel Sambuc gccvector unsigned int gccv1 = gccv;
96f4a2713aSLionel Sambuc gccvector int gccv2 = (gccvector int)gccv;
97f4a2713aSLionel Sambuc gccvector unsigned int gccv3 = v;
98f4a2713aSLionel Sambuc __vector unsigned int av = gccv;
99f4a2713aSLionel Sambuc __vector int avi = (__vector int)gccv;
100f4a2713aSLionel Sambuc gccvector unsigned int gv = v;
101f4a2713aSLionel Sambuc gccvector int gvi = (gccvector int)v;
102f4a2713aSLionel Sambuc __attribute__((vector_size(8))) unsigned int gv8;
103*0a6a1f1dSLionel Sambuc gv8 = gccv; // expected-error {{assigning to '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int' (vector of 4 'unsigned int' values)}}
104*0a6a1f1dSLionel Sambuc av = gv8; // expected-error {{assigning to '__vector unsigned int' (vector of 4 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values)}}
105f4a2713aSLionel Sambuc
106f4a2713aSLionel Sambuc v = gccv;
107f4a2713aSLionel Sambuc __vector unsigned int tv = gccv;
108f4a2713aSLionel Sambuc gccv = v;
109f4a2713aSLionel Sambuc gccvector unsigned int tgv = v;
110f4a2713aSLionel Sambuc }
111f4a2713aSLionel Sambuc
112f4a2713aSLionel Sambuc // Now for the C++ version:
113f4a2713aSLionel Sambuc
114f4a2713aSLionel Sambuc class vc__v {
115f4a2713aSLionel Sambuc __vector int v;
116f4a2713aSLionel Sambuc __vector int f__r();
117f4a2713aSLionel Sambuc void f__a(__vector int a);
118f4a2713aSLionel Sambuc void f__a2(int b, __vector int a);
119f4a2713aSLionel Sambuc };
120f4a2713aSLionel Sambuc
121f4a2713aSLionel Sambuc class c_v {
122f4a2713aSLionel Sambuc vector int v;
123f4a2713aSLionel Sambuc vector int f__r();
124f4a2713aSLionel Sambuc void f__a(vector int a);
125f4a2713aSLionel Sambuc void f__a2(int b, vector int a);
126f4a2713aSLionel Sambuc };
127f4a2713aSLionel Sambuc
128f4a2713aSLionel Sambuc
129f4a2713aSLionel Sambuc // bug 6895 - Vectorl literal casting confusion.
130f4a2713aSLionel Sambuc vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
131f4a2713aSLionel Sambuc vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
132f4a2713aSLionel Sambuc vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
133f4a2713aSLionel Sambuc vector int v4 = (vector int)(1, 2, 3, 4);
134f4a2713aSLionel Sambuc vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
135f4a2713aSLionel Sambuc vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
136f4a2713aSLionel Sambuc
137f4a2713aSLionel Sambuc // bug 7553 - Problem with '==' and vectors
func()138f4a2713aSLionel Sambuc void func() {
139f4a2713aSLionel Sambuc bool res_b;
140f4a2713aSLionel Sambuc res_b = (vv_sc == vv_sc);
141f4a2713aSLionel Sambuc res_b = (vv_uc != vv_uc);
142f4a2713aSLionel Sambuc res_b = (vv_s > vv_s);
143f4a2713aSLionel Sambuc res_b = (vv_us >= vv_us);
144f4a2713aSLionel Sambuc res_b = (vv_i < vv_i);
145f4a2713aSLionel Sambuc res_b = (vv_ui <= vv_ui);
146f4a2713aSLionel Sambuc res_b = (vv_f <= vv_f);
147f4a2713aSLionel Sambuc }
148f4a2713aSLionel Sambuc
149f4a2713aSLionel Sambuc // vecreturn attribute test
150f4a2713aSLionel Sambuc struct Vector
151f4a2713aSLionel Sambuc {
152f4a2713aSLionel Sambuc __vector float xyzw;
153f4a2713aSLionel Sambuc } __attribute__((vecreturn));
154f4a2713aSLionel Sambuc
Add(Vector lhs,Vector rhs)155f4a2713aSLionel Sambuc Vector Add(Vector lhs, Vector rhs)
156f4a2713aSLionel Sambuc {
157f4a2713aSLionel Sambuc Vector result;
158f4a2713aSLionel Sambuc result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
159f4a2713aSLionel Sambuc return result; // This will (eventually) be returned in a register
160f4a2713aSLionel Sambuc }
161f4a2713aSLionel Sambuc
162f4a2713aSLionel Sambuc // vecreturn attribute test - should error because of virtual function.
163f4a2713aSLionel Sambuc class VectorClassNonPod
164f4a2713aSLionel Sambuc {
165f4a2713aSLionel Sambuc __vector float xyzw;
166f4a2713aSLionel Sambuc public:
VectorClassNonPod()167f4a2713aSLionel Sambuc VectorClassNonPod() {}
~VectorClassNonPod()168f4a2713aSLionel Sambuc virtual ~VectorClassNonPod() {}
169f4a2713aSLionel Sambuc } __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a POD (plain old data) class or structure (i.e. no virtual functions)}}
170f4a2713aSLionel Sambuc
171f4a2713aSLionel Sambuc // vecreturn attribute test - should error because of virtual function.
172f4a2713aSLionel Sambuc class VectorClassMultipleMembers
173f4a2713aSLionel Sambuc {
174f4a2713aSLionel Sambuc public:
175f4a2713aSLionel Sambuc __vector float xyzw;
176f4a2713aSLionel Sambuc __vector float abcd;
177f4a2713aSLionel Sambuc } __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a class or structure with one member, which must be a vector}}
178f4a2713aSLionel Sambuc
PR16874()179f4a2713aSLionel Sambuc template<typename... Args> void PR16874() {
180f4a2713aSLionel Sambuc (void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
181f4a2713aSLionel Sambuc }
182