blob: f2ba28b641a67389baeacd4931fd8cdaba02bc66 [file] [log] [blame]
Eli Friedman7a15c4a2013-08-13 23:38:34 +00001// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify -std=c++11 %s
Bill Schmidt1cf7c642014-06-13 18:30:06 +00002// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s
3// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -faltivec -fsyntax-only -verify -std=c++11 %s
John Thompson22334602010-02-05 00:12:22 +00004
5__vector char vv_c;
6__vector signed char vv_sc;
7__vector unsigned char vv_uc;
8__vector short vv_s;
9__vector signed short vv_ss;
10__vector unsigned short vv_us;
11__vector short int vv_si;
12__vector signed short int vv_ssi;
13__vector unsigned short int vv_usi;
14__vector int vv_i;
15__vector signed int vv_sint;
16__vector unsigned int vv_ui;
17__vector float vv_f;
Chris Lattner37141f42010-06-23 06:00:24 +000018__vector bool char vv_bc;
19__vector bool short vv_bs;
20__vector bool int vv_bi;
John Thompson22334602010-02-05 00:12:22 +000021__vector __pixel vv_p;
22__vector pixel vv__p;
23__vector int vf__r();
24void vf__a(__vector int a);
25void vf__a2(int b, __vector int a);
26
27vector char v_c;
28vector signed char v_sc;
29vector unsigned char v_uc;
30vector short v_s;
31vector signed short v_ss;
32vector unsigned short v_us;
33vector short int v_si;
34vector signed short int v_ssi;
35vector unsigned short int v_usi;
36vector int v_i;
37vector signed int v_sint;
38vector unsigned int v_ui;
39vector float v_f;
Chris Lattner37141f42010-06-23 06:00:24 +000040vector bool char v_bc;
41vector bool short v_bs;
42vector bool int v_bi;
John Thompson22334602010-02-05 00:12:22 +000043vector __pixel v_p;
44vector pixel v__p;
45vector int f__r();
46void f_a(vector int a);
47void f_a2(int b, vector int a);
48
Chris Lattnerb596ac72010-04-20 05:19:10 +000049vector int v = (vector int)(-1);
50
John Thompson22334602010-02-05 00:12:22 +000051// These should have warnings.
Chris Lattner0a655742010-03-07 18:50:21 +000052__vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
53__vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
54__vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
55__vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
56__vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
57__vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
58vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
59vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
60vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
61vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
62vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
63vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
Bill Schmidt691e01d2014-10-31 19:19:24 +000064__vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}}
65vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}}
John Thompson22334602010-02-05 00:12:22 +000066
67// These should have errors.
Bill Schmidt691e01d2014-10-31 19:19:24 +000068__vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}}
69vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}}
70__vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}}
71vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}}
Richard Trieu553b2b22011-12-15 00:38:15 +000072vector bool v_b; // expected-error {{C++ requires a type specifier for all declarations}}
Chris Lattner37141f42010-06-23 06:00:24 +000073vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}}
74vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}}
75vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
76vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
77vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
78vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}}
79vector bool long long v_bll; // expected-error {{cannot use 'long long' with '__vector bool'}}
John Thompson22334602010-02-05 00:12:22 +000080
Hal Finkel3a1f4c72014-08-24 04:50:19 +000081// vector long is deprecated, but vector long long is not.
82vector long long v_ll;
83vector signed long long v_sll;
84vector unsigned long long v_ull;
85
John Thompson22334602010-02-05 00:12:22 +000086void f() {
87 __vector unsigned int v = {0,0,0,0};
88 __vector int v__cast = (__vector int)v;
89 __vector int v_cast = (vector int)v;
90 __vector char vb_cast = (vector char)v;
91
92 // Check some casting between gcc and altivec vectors.
93 #define gccvector __attribute__((vector_size(16)))
94 gccvector unsigned int gccv = {0,0,0,0};
95 gccvector unsigned int gccv1 = gccv;
96 gccvector int gccv2 = (gccvector int)gccv;
97 gccvector unsigned int gccv3 = v;
98 __vector unsigned int av = gccv;
99 __vector int avi = (__vector int)gccv;
100 gccvector unsigned int gv = v;
101 gccvector int gvi = (gccvector int)v;
102 __attribute__((vector_size(8))) unsigned int gv8;
Benjamin Kramer1adc8c32014-04-25 20:41:38 +0000103 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 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)}}
John Thompson22334602010-02-05 00:12:22 +0000105
106 v = gccv;
107 __vector unsigned int tv = gccv;
108 gccv = v;
109 gccvector unsigned int tgv = v;
110}
111
112// Now for the C++ version:
113
114class vc__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
121class c_v {
122 vector int v;
123 vector int f__r();
124 void f__a(vector int a);
125 void f__a2(int b, vector int a);
126};
127
John Thompson781ad172010-06-30 22:55:51 +0000128
129// bug 6895 - Vectorl literal casting confusion.
130vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
131vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
132vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
133vector int v4 = (vector int)(1, 2, 3, 4);
134vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
135vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
John Thompsoncdb847ba2010-08-09 21:53:52 +0000136
John Thompsoncdb847ba2010-08-09 21:53:52 +0000137// bug 7553 - Problem with '==' and vectors
138void func() {
Anton Yartsev3f8f2882010-11-18 03:19:30 +0000139 bool res_b;
140 res_b = (vv_sc == vv_sc);
141 res_b = (vv_uc != vv_uc);
142 res_b = (vv_s > vv_s);
143 res_b = (vv_us >= vv_us);
144 res_b = (vv_i < vv_i);
145 res_b = (vv_ui <= vv_ui);
146 res_b = (vv_f <= vv_f);
John Thompsoncdb847ba2010-08-09 21:53:52 +0000147}
John Thompsoncdb847ba2010-08-09 21:53:52 +0000148
149// vecreturn attribute test
150struct Vector
151{
152 __vector float xyzw;
153} __attribute__((vecreturn));
154
155Vector Add(Vector lhs, Vector rhs)
156{
157 Vector result;
158 result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
159 return result; // This will (eventually) be returned in a register
160}
John Thompson9a587aaa2010-09-18 01:12:07 +0000161
162// vecreturn attribute test - should error because of virtual function.
163class VectorClassNonPod
164{
165 __vector float xyzw;
166public:
167 VectorClassNonPod() {}
168 virtual ~VectorClassNonPod() {}
169} __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)}}
170
171// vecreturn attribute test - should error because of virtual function.
172class VectorClassMultipleMembers
173{
174public:
175 __vector float xyzw;
176 __vector float abcd;
177} __attribute__((vecreturn)); // expected-error {{the vecreturn attribute can only be used on a class or structure with one member, which must be a vector}}
Eli Friedman7a15c4a2013-08-13 23:38:34 +0000178
179template<typename... Args> void PR16874() {
180 (void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
181}