blob: 769b4dec98fcf43a7adb5edd5a2e66c33e553acd [file] [log] [blame]
Eric Christopher758aad72017-03-21 22:06:18 +00001// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec -fsyntax-only -verify %s
2// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify %s
3// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify %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;
Bill Seurercf2c96b2015-01-12 19:35:51 +000021__vector __bool char vv___bc;
22__vector __bool short vv___bs;
Bill Seurer2351bec2015-03-03 20:08:43 +000023__vector __bool int vv___bi;
John Thompson22334602010-02-05 00:12:22 +000024__vector __pixel vv_p;
25__vector pixel vv__p;
26__vector int vf__r();
27void vf__a(__vector int a);
28void vf__a2(int b, __vector int a);
29
30vector char v_c;
31vector signed char v_sc;
32vector unsigned char v_uc;
33vector short v_s;
34vector signed short v_ss;
35vector unsigned short v_us;
36vector short int v_si;
37vector signed short int v_ssi;
38vector unsigned short int v_usi;
39vector int v_i;
40vector signed int v_sint;
41vector unsigned int v_ui;
42vector float v_f;
Chris Lattner37141f42010-06-23 06:00:24 +000043vector bool char v_bc;
44vector bool short v_bs;
45vector bool int v_bi;
Bill Seurercf2c96b2015-01-12 19:35:51 +000046vector __bool char v___bc;
47vector __bool short v___bs;
48vector __bool int v___bi;
John Thompson22334602010-02-05 00:12:22 +000049vector __pixel v_p;
50vector pixel v__p;
51vector int f__r();
52void f_a(vector int a);
53void f_a2(int b, vector int a);
54
Chris Lattnerb596ac72010-04-20 05:19:10 +000055vector int v = (vector int)(-1);
56
John Thompson22334602010-02-05 00:12:22 +000057// These should have warnings.
Chris Lattner0a655742010-03-07 18:50:21 +000058__vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
59__vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
60__vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
61__vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
62__vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
63__vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
64vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
65vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
66vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
67vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
68vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
69vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
Bill Schmidt691e01d2014-10-31 19:19:24 +000070__vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}}
71vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}}
Chris Lattner37141f42010-06-23 06:00:24 +000072vector bool v_b; // expected-warning {{type specifier missing, defaults to 'int'}}
Bill Seurercf2c96b2015-01-12 19:35:51 +000073vector __bool v___b; // expected-warning {{type specifier missing, defaults to 'int'}}
John Thompson22334602010-02-05 00:12:22 +000074
75// These should have errors.
Kit Barton8553bec2015-03-11 15:57:19 +000076__vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
77vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
78__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}}
79__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}}
80vector 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}}
81vector __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 +000082__vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}}
83vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}}
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'}}
88vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
89vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}}
Bill Seurercf2c96b2015-01-12 19:35:51 +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
Richard Smith3092a3b2012-05-09 18:56:43 +0000102typedef char i8;
103typedef short i16;
104typedef int i32;
105struct S {
106 // i8, i16, i32 here are field names, not type names.
107 vector bool i8; // expected-error {{requires a specifier or qualifier}}
108 vector pixel i16;
109 vector long i32; // expected-warning {{deprecated}}
110};
111
John Thompson22334602010-02-05 00:12:22 +0000112void f() {
113 __vector unsigned int v = {0,0,0,0};
114 __vector int v__cast = (__vector int)v;
115 __vector int v_cast = (vector int)v;
116 __vector char vb_cast = (vector char)v;
117
118 // Check some casting between gcc and altivec vectors.
119 #define gccvector __attribute__((vector_size(16)))
120 gccvector unsigned int gccv = {0,0,0,0};
121 gccvector unsigned int gccv1 = gccv;
122 gccvector int gccv2 = (gccvector int)gccv;
123 gccvector unsigned int gccv3 = v;
124 __vector unsigned int av = gccv;
125 __vector int avi = (__vector int)gccv;
126 gccvector unsigned int gv = v;
127 gccvector int gvi = (gccvector int)v;
128 __attribute__((vector_size(8))) unsigned int gv8;
Benjamin Kramer1adc8c32014-04-25 20:41:38 +0000129 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)}}
130 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 +0000131
132 v = gccv;
133 __vector unsigned int tv = gccv;
134 gccv = v;
135 gccvector unsigned int tgv = v;
Anton Yartsev3f8f2882010-11-18 03:19:30 +0000136
137 int res_i;
138 // bug 7553 - Problem with '==' and vectors
139 res_i = (vv_sc == vv_sc);
140 res_i = (vv_uc != vv_uc);
141 res_i = (vv_s > vv_s);
142 res_i = (vv_us >= vv_us);
143 res_i = (vv_i < vv_i);
144 res_i = (vv_ui <= vv_ui);
145 res_i = (vv_f <= vv_f);
John Thompson22334602010-02-05 00:12:22 +0000146}
John Thompson781ad172010-06-30 22:55:51 +0000147
148// bug 6895 - Vectorl literal casting confusion.
Chandler Carruthbc0f9ae2011-04-25 07:09:43 +0000149vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
150vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
151vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
152vector int v4 = (vector int)(1, 2, 3, 4);
John Thompson781ad172010-06-30 22:55:51 +0000153vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
154vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));