blob: 6395452010d4546a1a9120bd140498b70783f603 [file] [log] [blame]
Eric Christopher758aad72017-03-21 22:06:18 +00001// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec -fsyntax-only -verify -std=c++11 %s
2// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify -std=c++11 %s
3// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify -std=c++11 %s
Eric Christopher46502722016-03-24 01:26:08 +00004#include <altivec.h>
John Thompson22334602010-02-05 00:12:22 +00005
6__vector char vv_c;
7__vector signed char vv_sc;
8__vector unsigned char vv_uc;
9__vector short vv_s;
10__vector signed short vv_ss;
11__vector unsigned short vv_us;
12__vector short int vv_si;
13__vector signed short int vv_ssi;
14__vector unsigned short int vv_usi;
15__vector int vv_i;
16__vector signed int vv_sint;
17__vector unsigned int vv_ui;
18__vector float vv_f;
Chris Lattner37141f42010-06-23 06:00:24 +000019__vector bool char vv_bc;
20__vector bool short vv_bs;
21__vector bool int vv_bi;
Bill Seurer2351bec2015-03-03 20:08:43 +000022__vector __bool char vv___bc;
23__vector __bool short vv___bs;
24__vector __bool int vv___bi;
John Thompson22334602010-02-05 00:12:22 +000025__vector __pixel vv_p;
26__vector pixel vv__p;
27__vector int vf__r();
28void vf__a(__vector int a);
29void vf__a2(int b, __vector int a);
30
31vector char v_c;
32vector signed char v_sc;
33vector unsigned char v_uc;
34vector short v_s;
35vector signed short v_ss;
36vector unsigned short v_us;
37vector short int v_si;
38vector signed short int v_ssi;
39vector unsigned short int v_usi;
40vector int v_i;
41vector signed int v_sint;
42vector unsigned int v_ui;
43vector float v_f;
Chris Lattner37141f42010-06-23 06:00:24 +000044vector bool char v_bc;
45vector bool short v_bs;
46vector bool int v_bi;
Bill Seurer2351bec2015-03-03 20:08:43 +000047vector __bool char v___bc;
48vector __bool short v___bs;
49vector __bool int v___bi;
John Thompson22334602010-02-05 00:12:22 +000050vector __pixel v_p;
51vector pixel v__p;
52vector int f__r();
53void f_a(vector int a);
54void f_a2(int b, vector int a);
55
Chris Lattnerb596ac72010-04-20 05:19:10 +000056vector int v = (vector int)(-1);
57
John Thompson22334602010-02-05 00:12:22 +000058// These should have warnings.
Chris Lattner0a655742010-03-07 18:50:21 +000059__vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
60__vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
61__vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
62__vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
63__vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
64__vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
65vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
66vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
67vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
68vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
69vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
70vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
Bill Schmidt691e01d2014-10-31 19:19:24 +000071__vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}}
72vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}}
John Thompson22334602010-02-05 00:12:22 +000073
74// These should have errors.
Kit Barton8553bec2015-03-11 15:57:19 +000075__vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
76vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
77__vector bool long long v_bll1; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
78__vector __bool long long v_bll2; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
79vector bool long long v_bll3; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
80vector __bool long long v_bll4; // expected-error {{use of 'long long' with '__vector bool' requires VSX support (available on POWER7 or later) or extended Altivec support (available on POWER8 or later) to be enabled}}
Bill Schmidt691e01d2014-10-31 19:19:24 +000081__vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}}
82vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}}
Richard Trieu553b2b22011-12-15 00:38:15 +000083vector bool v_b; // expected-error {{C++ requires a type specifier for all declarations}}
Chris Lattner37141f42010-06-23 06:00:24 +000084vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}}
85vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}}
86vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
87vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
Bill Seurer2351bec2015-03-03 20:08:43 +000088vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
Chris Lattner37141f42010-06-23 06:00:24 +000089vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}}
Bill Seurer2351bec2015-03-03 20:08:43 +000090vector __bool float v___bf; // expected-error {{cannot use 'float' with '__vector bool'}}
91vector __bool double v___bd; // expected-error {{cannot use 'double' with '__vector bool'}}
92vector __bool pixel v___bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
93vector __bool signed char v___bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
94vector __bool unsigned int v___bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
95vector __bool long v___bl; // expected-error {{cannot use 'long' with '__vector bool'}}
John Thompson22334602010-02-05 00:12:22 +000096
Hal Finkel3a1f4c72014-08-24 04:50:19 +000097// vector long is deprecated, but vector long long is not.
98vector long long v_ll;
99vector signed long long v_sll;
100vector unsigned long long v_ull;
101
John Thompson22334602010-02-05 00:12:22 +0000102void f() {
103 __vector unsigned int v = {0,0,0,0};
104 __vector int v__cast = (__vector int)v;
105 __vector int v_cast = (vector int)v;
106 __vector char vb_cast = (vector char)v;
107
108 // Check some casting between gcc and altivec vectors.
109 #define gccvector __attribute__((vector_size(16)))
110 gccvector unsigned int gccv = {0,0,0,0};
111 gccvector unsigned int gccv1 = gccv;
112 gccvector int gccv2 = (gccvector int)gccv;
113 gccvector unsigned int gccv3 = v;
114 __vector unsigned int av = gccv;
115 __vector int avi = (__vector int)gccv;
116 gccvector unsigned int gv = v;
117 gccvector int gvi = (gccvector int)v;
118 __attribute__((vector_size(8))) unsigned int gv8;
Benjamin Kramer1adc8c32014-04-25 20:41:38 +0000119 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)}}
120 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 +0000121
122 v = gccv;
123 __vector unsigned int tv = gccv;
124 gccv = v;
125 gccvector unsigned int tgv = v;
126}
127
128// Now for the C++ version:
129
130class vc__v {
131 __vector int v;
132 __vector int f__r();
133 void f__a(__vector int a);
134 void f__a2(int b, __vector int a);
135};
136
137class c_v {
138 vector int v;
139 vector int f__r();
140 void f__a(vector int a);
141 void f__a2(int b, vector int a);
142};
143
John Thompson781ad172010-06-30 22:55:51 +0000144
145// bug 6895 - Vectorl literal casting confusion.
146vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
147vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
148vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
149vector int v4 = (vector int)(1, 2, 3, 4);
150vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
151vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
John Thompsoncdb847ba2010-08-09 21:53:52 +0000152
John Thompsoncdb847ba2010-08-09 21:53:52 +0000153// bug 7553 - Problem with '==' and vectors
154void func() {
Anton Yartsev3f8f2882010-11-18 03:19:30 +0000155 bool res_b;
156 res_b = (vv_sc == vv_sc);
157 res_b = (vv_uc != vv_uc);
158 res_b = (vv_s > vv_s);
159 res_b = (vv_us >= vv_us);
160 res_b = (vv_i < vv_i);
161 res_b = (vv_ui <= vv_ui);
162 res_b = (vv_f <= vv_f);
John Thompsoncdb847ba2010-08-09 21:53:52 +0000163}
John Thompsoncdb847ba2010-08-09 21:53:52 +0000164
165// vecreturn attribute test
166struct Vector
167{
168 __vector float xyzw;
169} __attribute__((vecreturn));
170
171Vector Add(Vector lhs, Vector rhs)
172{
173 Vector result;
174 result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
175 return result; // This will (eventually) be returned in a register
176}
John Thompson9a587aaa2010-09-18 01:12:07 +0000177
178// vecreturn attribute test - should error because of virtual function.
179class VectorClassNonPod
180{
181 __vector float xyzw;
182public:
183 VectorClassNonPod() {}
184 virtual ~VectorClassNonPod() {}
185} __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)}}
186
187// vecreturn attribute test - should error because of virtual function.
188class VectorClassMultipleMembers
189{
190public:
191 __vector float xyzw;
192 __vector float abcd;
193} __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 +0000194
195template<typename... Args> void PR16874() {
196 (void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
197}
Kit Barton8553bec2015-03-11 15:57:19 +0000198