1 // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec -fsyntax-only -verify=expected,nonaix %s
2 // RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify=expected,nonaix %s
3 // RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify=expected,nonaix %s
4 // RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix %s
5 // RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix %s
6
7 __vector char vv_c;
8 __vector signed char vv_sc;
9 __vector unsigned char vv_uc;
10 __vector short vv_s;
11 __vector signed short vv_ss;
12 __vector unsigned short vv_us;
13 __vector short int vv_si;
14 __vector signed short int vv_ssi;
15 __vector unsigned short int vv_usi;
16 __vector int vv_i;
17 __vector signed int vv_sint;
18 __vector unsigned int vv_ui;
19 __vector float vv_f;
20 __vector bool char vv_bc;
21 __vector bool short vv_bs;
22 __vector bool int vv_bi;
23 __vector __bool char vv___bc;
24 __vector __bool short vv___bs;
25 __vector __bool int vv___bi;
26 __vector __pixel vv_p;
27 __vector pixel vv__p;
28 __vector int vf__r();
29 void vf__a(__vector int a);
30 void vf__a2(int b, __vector int a);
31
32 vector char v_c;
33 vector signed char v_sc;
34 vector unsigned char v_uc;
35 vector short v_s;
36 vector signed short v_ss;
37 vector unsigned short v_us;
38 vector short int v_si;
39 vector signed short int v_ssi;
40 vector unsigned short int v_usi;
41 vector int v_i;
42 vector signed int v_sint;
43 vector unsigned int v_ui;
44 vector float v_f;
45 vector bool char v_bc;
46 vector bool short v_bs;
47 vector bool int v_bi;
48 vector __bool char v___bc;
49 vector __bool short v___bs;
50 vector __bool int v___bi;
51 vector __pixel v_p;
52 vector pixel v__p;
53 vector int f__r();
54 void f_a(vector int a);
55 void f_a2(int b, vector int a);
56
57 vector int v = (vector int)(-1);
58
59 // These should have errors on AIX and warnings otherwise.
60 __vector long vv_l; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
61 // aix-error@-1 {{cannot use 'long' with '__vector'}}
62 __vector signed long vv_sl; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
63 // aix-error@-1 {{cannot use 'long' with '__vector'}}
64 __vector unsigned long vv_ul; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
65 // aix-error@-1 {{cannot use 'long' with '__vector'}}
66 __vector long int vv_li; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
67 // aix-error@-1 {{cannot use 'long' with '__vector'}}
68 __vector signed long int vv_sli; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
69 // aix-error@-1 {{cannot use 'long' with '__vector'}}
70 __vector unsigned long int vv_uli; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
71 // aix-error@-1 {{cannot use 'long' with '__vector'}}
72 vector long v_l; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
73 // aix-error@-1 {{cannot use 'long' with '__vector'}}
74 vector signed long v_sl; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
75 // aix-error@-1 {{cannot use 'long' with '__vector'}}
76 vector unsigned long v_ul; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
77 // aix-error@-1 {{cannot use 'long' with '__vector'}}
78 vector long int v_li; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
79 // aix-error@-1 {{cannot use 'long' with '__vector'}}
80 vector signed long int v_sli; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
81 // aix-error@-1 {{cannot use 'long' with '__vector'}}
82 vector unsigned long int v_uli; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
83 // aix-error@-1 {{cannot use 'long' with '__vector'}}
84
85 // These should have warnings.
86 __vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}}
87 vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}}
88 vector bool v_b; // expected-warning {{type specifier missing, defaults to 'int'}}
89 vector __bool v___b; // expected-warning {{type specifier missing, defaults to 'int'}}
90
91 // These should have errors.
92 __vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
93 vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
94 __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}}
95 __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}}
96 vector 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}}
97 vector __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}}
98 __vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}}
99 vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}}
100 vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}}
101 vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}}
102 vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
103 vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
104 vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
105 vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}}
106 vector __bool float v___bf; // expected-error {{cannot use 'float' with '__vector bool'}}
107 vector __bool double v___bd; // expected-error {{cannot use 'double' with '__vector bool'}}
108 vector __bool pixel v___bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
109 vector __bool signed char v___bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
110 vector __bool unsigned int v___bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
111 vector __bool long v___bl; // expected-error {{cannot use 'long' with '__vector bool'}}
112
113 // vector long is deprecated, but vector long long is not.
114 vector long long v_ll;
115 vector signed long long v_sll;
116 vector unsigned long long v_ull;
117
118 typedef char i8;
119 typedef short i16;
120 typedef int i32;
121 struct S {
122 // i8, i16, i32 here are field names, not type names.
123 vector bool i8; // expected-error {{requires a specifier or qualifier}}
124 vector pixel i16;
125 vector short i32;
126 };
127
f()128 void f() {
129 __vector unsigned int v = {0,0,0,0};
130 __vector int v__cast = (__vector int)v;
131 __vector int v_cast = (vector int)v;
132 __vector char vb_cast = (vector char)v;
133
134 // Check some casting between gcc and altivec vectors.
135 #define gccvector __attribute__((vector_size(16)))
136 gccvector unsigned int gccv = {0,0,0,0};
137 gccvector unsigned int gccv1 = gccv;
138 gccvector int gccv2 = (gccvector int)gccv;
139 gccvector unsigned int gccv3 = v;
140 __vector unsigned int av = gccv;
141 __vector int avi = (__vector int)gccv;
142 gccvector unsigned int gv = v;
143 gccvector int gvi = (gccvector int)v;
144 __attribute__((vector_size(8))) unsigned int gv8;
145 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)}}
146 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)}}
147
148 v = gccv;
149 __vector unsigned int tv = gccv;
150 gccv = v;
151 gccvector unsigned int tgv = v;
152
153 int res_i;
154 // bug 7553 - Problem with '==' and vectors
155 res_i = (vv_sc == vv_sc);
156 res_i = (vv_uc != vv_uc);
157 res_i = (vv_s > vv_s);
158 res_i = (vv_us >= vv_us);
159 res_i = (vv_i < vv_i);
160 res_i = (vv_ui <= vv_ui);
161 res_i = (vv_f <= vv_f);
162 }
163
164 // bug 6895 - Vectorl literal casting confusion.
165 vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
166 vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
167 vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
168 vector int v4 = (vector int)(1, 2, 3, 4);
169 vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
170 vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
171