blob: 9b2b1af22f6e59e990c89286794871fb4e74ad1e [file] [log] [blame]
Chris Lattnerdd173942010-04-14 03:54:58 +00001// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify %s
John Thompson82287d12010-02-05 00:12:22 +00002
3__vector char vv_c;
4__vector signed char vv_sc;
5__vector unsigned char vv_uc;
6__vector short vv_s;
7__vector signed short vv_ss;
8__vector unsigned short vv_us;
9__vector short int vv_si;
10__vector signed short int vv_ssi;
11__vector unsigned short int vv_usi;
12__vector int vv_i;
13__vector signed int vv_sint;
14__vector unsigned int vv_ui;
15__vector float vv_f;
Chris Lattner788b0fd2010-06-23 06:00:24 +000016__vector bool char vv_bc;
17__vector bool short vv_bs;
18__vector bool int vv_bi;
John Thompson82287d12010-02-05 00:12:22 +000019__vector __pixel vv_p;
20__vector pixel vv__p;
21__vector int vf__r();
22void vf__a(__vector int a);
23void vf__a2(int b, __vector int a);
24
25vector char v_c;
26vector signed char v_sc;
27vector unsigned char v_uc;
28vector short v_s;
29vector signed short v_ss;
30vector unsigned short v_us;
31vector short int v_si;
32vector signed short int v_ssi;
33vector unsigned short int v_usi;
34vector int v_i;
35vector signed int v_sint;
36vector unsigned int v_ui;
37vector float v_f;
Chris Lattner788b0fd2010-06-23 06:00:24 +000038vector bool char v_bc;
39vector bool short v_bs;
40vector bool int v_bi;
John Thompson82287d12010-02-05 00:12:22 +000041vector __pixel v_p;
42vector pixel v__p;
43vector int f__r();
44void f_a(vector int a);
45void f_a2(int b, vector int a);
46
Chris Lattnere12a7792010-04-20 05:19:10 +000047vector int v = (vector int)(-1);
48
John Thompson82287d12010-02-05 00:12:22 +000049// These should have warnings.
Chris Lattnerffaf4c52010-03-07 18:50:21 +000050__vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
51__vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
52__vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
53__vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
54__vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
55__vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
56vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
57vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
58vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
59vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
60vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
61vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
62__vector long double vv_ld; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}}
63vector long double v_ld; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}}
John Thompson82287d12010-02-05 00:12:22 +000064
65// These should have errors.
Chris Lattnerffaf4c52010-03-07 18:50:21 +000066__vector double vv_d1; // expected-error {{cannot use 'double' with '__vector'}}
67vector double v_d2; // expected-error {{cannot use 'double' with '__vector'}}
68__vector long double vv_ld3; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}}
69vector long double v_ld4; // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}}
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000070vector bool v_b; // expected-error {{C++ requires a type specifier for all declarations}}
Chris Lattner788b0fd2010-06-23 06:00:24 +000071vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}}
72vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}}
73vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
74vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
75vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
76vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}}
77vector bool long long v_bll; // expected-error {{cannot use 'long long' with '__vector bool'}}
John Thompson82287d12010-02-05 00:12:22 +000078
79void f() {
80 __vector unsigned int v = {0,0,0,0};
81 __vector int v__cast = (__vector int)v;
82 __vector int v_cast = (vector int)v;
83 __vector char vb_cast = (vector char)v;
84
85 // Check some casting between gcc and altivec vectors.
86 #define gccvector __attribute__((vector_size(16)))
87 gccvector unsigned int gccv = {0,0,0,0};
88 gccvector unsigned int gccv1 = gccv;
89 gccvector int gccv2 = (gccvector int)gccv;
90 gccvector unsigned int gccv3 = v;
91 __vector unsigned int av = gccv;
92 __vector int avi = (__vector int)gccv;
93 gccvector unsigned int gv = v;
94 gccvector int gvi = (gccvector int)v;
95 __attribute__((vector_size(8))) unsigned int gv8;
Douglas Gregord4eea832010-04-09 00:35:39 +000096 gv8 = gccv; // expected-error {{assigning to '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' from incompatible type '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int'}}
97 av = gv8; // expected-error {{assigning to '__vector unsigned int' from incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int'}}
John Thompson82287d12010-02-05 00:12:22 +000098
99 v = gccv;
100 __vector unsigned int tv = gccv;
101 gccv = v;
102 gccvector unsigned int tgv = v;
103}
104
105// Now for the C++ version:
106
107class vc__v {
108 __vector int v;
109 __vector int f__r();
110 void f__a(__vector int a);
111 void f__a2(int b, __vector int a);
112};
113
114class c_v {
115 vector int v;
116 vector int f__r();
117 void f__a(vector int a);
118 void f__a2(int b, vector int a);
119};
120
John Thompson8bb59a82010-06-30 22:55:51 +0000121
122// bug 6895 - Vectorl literal casting confusion.
123vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
124vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
125vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
126vector int v4 = (vector int)(1, 2, 3, 4);
127vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
128vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
John Thompson35cc9622010-08-09 21:53:52 +0000129
John Thompson35cc9622010-08-09 21:53:52 +0000130// bug 7553 - Problem with '==' and vectors
131void func() {
Anton Yartsevaa4fe052010-11-18 03:19:30 +0000132 bool res_b;
133 res_b = (vv_sc == vv_sc);
134 res_b = (vv_uc != vv_uc);
135 res_b = (vv_s > vv_s);
136 res_b = (vv_us >= vv_us);
137 res_b = (vv_i < vv_i);
138 res_b = (vv_ui <= vv_ui);
139 res_b = (vv_f <= vv_f);
John Thompson35cc9622010-08-09 21:53:52 +0000140}
John Thompson35cc9622010-08-09 21:53:52 +0000141
142// vecreturn attribute test
143struct Vector
144{
145 __vector float xyzw;
146} __attribute__((vecreturn));
147
148Vector Add(Vector lhs, Vector rhs)
149{
150 Vector result;
151 result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
152 return result; // This will (eventually) be returned in a register
153}
John Thompson01add592010-09-18 01:12:07 +0000154
155// vecreturn attribute test - should error because of virtual function.
156class VectorClassNonPod
157{
158 __vector float xyzw;
159public:
160 VectorClassNonPod() {}
161 virtual ~VectorClassNonPod() {}
162} __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)}}
163
164// vecreturn attribute test - should error because of virtual function.
165class VectorClassMultipleMembers
166{
167public:
168 __vector float xyzw;
169 __vector float abcd;
170} __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a class or structure with one member, which must be a vector}}