blob: 7adca6143bde4b1a7ee9490332316b6763bf6ae8 [file] [log] [blame]
Chris Lattnerdad40622010-04-14 03:54:58 +00001// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify %s
Bill Schmidt1cf7c642014-06-13 18:30:06 +00002// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -faltivec -fsyntax-only -verify %s
3// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -faltivec -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;
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'}}
Chris Lattner37141f42010-06-23 06:00:24 +000066vector bool v_b; // expected-warning {{type specifier missing, defaults to 'int'}}
John Thompson22334602010-02-05 00:12:22 +000067
68// These should have errors.
Bill Schmidt691e01d2014-10-31 19:19:24 +000069__vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}}
70vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}}
71__vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}}
72vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}}
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
Richard Smith3092a3b2012-05-09 18:56:43 +000086typedef char i8;
87typedef short i16;
88typedef int i32;
89struct S {
90 // i8, i16, i32 here are field names, not type names.
91 vector bool i8; // expected-error {{requires a specifier or qualifier}}
92 vector pixel i16;
93 vector long i32; // expected-warning {{deprecated}}
94};
95
John Thompson22334602010-02-05 00:12:22 +000096void f() {
97 __vector unsigned int v = {0,0,0,0};
98 __vector int v__cast = (__vector int)v;
99 __vector int v_cast = (vector int)v;
100 __vector char vb_cast = (vector char)v;
101
102 // Check some casting between gcc and altivec vectors.
103 #define gccvector __attribute__((vector_size(16)))
104 gccvector unsigned int gccv = {0,0,0,0};
105 gccvector unsigned int gccv1 = gccv;
106 gccvector int gccv2 = (gccvector int)gccv;
107 gccvector unsigned int gccv3 = v;
108 __vector unsigned int av = gccv;
109 __vector int avi = (__vector int)gccv;
110 gccvector unsigned int gv = v;
111 gccvector int gvi = (gccvector int)v;
112 __attribute__((vector_size(8))) unsigned int gv8;
Benjamin Kramer1adc8c32014-04-25 20:41:38 +0000113 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)}}
114 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 +0000115
116 v = gccv;
117 __vector unsigned int tv = gccv;
118 gccv = v;
119 gccvector unsigned int tgv = v;
Anton Yartsev3f8f2882010-11-18 03:19:30 +0000120
121 int res_i;
122 // bug 7553 - Problem with '==' and vectors
123 res_i = (vv_sc == vv_sc);
124 res_i = (vv_uc != vv_uc);
125 res_i = (vv_s > vv_s);
126 res_i = (vv_us >= vv_us);
127 res_i = (vv_i < vv_i);
128 res_i = (vv_ui <= vv_ui);
129 res_i = (vv_f <= vv_f);
John Thompson22334602010-02-05 00:12:22 +0000130}
John Thompson781ad172010-06-30 22:55:51 +0000131
132// bug 6895 - Vectorl literal casting confusion.
Chandler Carruthbc0f9ae2011-04-25 07:09:43 +0000133vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
134vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
135vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
136vector int v4 = (vector int)(1, 2, 3, 4);
John Thompson781ad172010-06-30 22:55:51 +0000137vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
138vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));