Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Sema / ext_vector_ops.c
blob5dc3047e145f177b090df497450994a9691daaef
1 // RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversion -triple x86_64-apple-darwin10
3 typedef unsigned int v2u __attribute__ ((ext_vector_type(2)));
4 typedef int v2s __attribute__ ((ext_vector_type(2)));
5 typedef float v2f __attribute__ ((ext_vector_type(2)));
7 void test1(v2u v2ua, v2s v2sa, v2f v2fa) {
8 // Bitwise binary operators
9 (void)(v2ua & v2ua);
10 (void)(v2fa & v2fa); // expected-error{{invalid operands to binary expression}}
12 // Unary operators
13 (void)(~v2ua);
14 (void)(~v2fa); // expected-error{{invalid argument type 'v2f' (vector of 2 'float' values) to unary}}
16 // Comparison operators
17 v2sa = (v2ua==v2sa);
19 // Arrays
20 int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u' (vector of 2 'unsigned int' values}}
21 int array2[17];
22 // FIXME: error message below needs type!
23 (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}}
25 v2u *v2u_ptr = 0;
26 v2s *v2s_ptr;
29 void test_int_vector_scalar(unsigned int ua, v2u v2ua) {
30 // Operations with one integer vector and one scalar. These splat the scalar.
31 (void)(v2ua + ua);
32 (void)(ua + v2ua);
33 (void)(v2ua - ua);
34 (void)(ua - v2ua);
35 (void)(v2ua * ua);
36 (void)(ua * v2ua);
37 (void)(v2ua / ua);
38 (void)(ua / v2ua);
39 (void)(v2ua % ua);
40 (void)(ua % v2ua);
42 (void)(v2ua == ua);
43 (void)(ua == v2ua);
44 (void)(v2ua != ua);
45 (void)(ua != v2ua);
46 (void)(v2ua <= ua);
47 (void)(ua <= v2ua);
48 (void)(v2ua >= ua);
49 (void)(ua >= v2ua);
50 (void)(v2ua < ua);
51 (void)(ua < v2ua);
52 (void)(v2ua > ua);
53 (void)(ua > v2ua);
54 (void)(v2ua && ua);
55 (void)(ua && v2ua);
56 (void)(v2ua || ua);
57 (void)(ua || v2ua);
59 (void)(v2ua & ua);
60 (void)(ua & v2ua);
61 (void)(v2ua | ua);
62 (void)(ua | v2ua);
63 (void)(v2ua ^ ua);
64 (void)(ua ^ v2ua);
65 (void)(v2ua << ua);
66 (void)(ua << v2ua);
67 (void)(v2ua >> ua);
68 (void)(ua >> v2ua);
70 v2ua += ua;
71 v2ua -= ua;
72 v2ua *= ua;
73 v2ua /= ua;
74 v2ua %= ua;
75 v2ua &= ua;
76 v2ua |= ua;
77 v2ua ^= ua;
78 v2ua >>= ua;
79 v2ua <<= ua;
81 ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
82 ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
83 ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
84 ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
85 ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
86 ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
87 ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
88 ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
89 ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
90 ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
93 void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {
94 // Operations with one float vector and one scalar. These splat the scalar.
95 (void)(v2fa + fa);
96 (void)(fa + v2fa);
97 (void)(v2fa - fa);
98 (void)(fa - v2fa);
99 (void)(v2fa * fa);
100 (void)(fa * v2fa);
101 (void)(v2fa / fa);
102 (void)(fa / v2fa);
103 (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}
104 (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}
106 (void)(v2fa == fa);
107 (void)(fa == v2fa);
108 (void)(v2fa != fa);
109 (void)(fa != v2fa);
110 (void)(v2fa <= fa);
111 (void)(fa <= v2fa);
112 (void)(v2fa >= fa);
113 (void)(fa >= v2fa);
114 (void)(v2fa < fa);
115 (void)(fa < v2fa);
116 (void)(v2fa > fa);
117 (void)(fa > v2fa);
118 (void)(v2fa && fa);
119 (void)(fa && v2fa);
120 (void)(v2fa || fa);
121 (void)(fa || v2fa);
123 (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}
124 (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}
125 (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}
126 (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}
127 (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}
128 (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}
129 (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
130 (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
131 (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}
132 (void)(ua << v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
133 (void)(v2fa >> fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
134 (void)(v2fa >> ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
135 (void)(fa >> v2fa); // expected-error{{used type 'float' where integer is required}}
136 (void)(ua >> v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
138 v2fa += fa;
139 v2fa -= fa;
140 v2fa *= fa;
141 v2fa /= fa;
142 v2fa %= fa; // expected-error{{invalid operands to binary expression}}
143 v2fa &= fa; // expected-error{{invalid operands to binary expression}}
144 v2fa |= fa; // expected-error{{invalid operands to binary expression}}
145 v2fa ^= fa; // expected-error{{invalid operands to binary expression}}
146 v2fa >>= fa; // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
147 v2fa <<= fa; // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
149 fa += v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
150 fa -= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
151 fa *= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
152 fa /= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
153 fa %= v2fa; // expected-error{{invalid operands to binary expression}}
154 fa &= v2fa; // expected-error{{invalid operands to binary expression}}
155 fa |= v2fa; // expected-error{{invalid operands to binary expression}}
156 fa ^= v2fa; // expected-error{{invalid operands to binary expression}}
157 fa >>= v2fa; // expected-error{{used type 'float' where integer is required}}
158 fa <<= v2fa; // expected-error{{used type 'float' where integer is required}}
161 enum Enum { ENUM };
163 void test_enum_vector_scalar(enum Enum ea, v2u v2ua) {
164 // Operations with one integer vector and one enum scalar.
165 // These splat the scalar and do implicit integral conversions.
166 (void)(v2ua + ea);
167 (void)(ea + v2ua);
168 (void)(v2ua - ea);
169 (void)(ea - v2ua);
170 (void)(v2ua * ea);
171 (void)(ea * v2ua);
172 (void)(v2ua / ea);
173 (void)(ea / v2ua);
174 (void)(v2ua % ea);
175 (void)(ea % v2ua);
177 (void)(v2ua == ea);
178 (void)(ea == v2ua);
179 (void)(v2ua != ea);
180 (void)(ea != v2ua);
181 (void)(v2ua <= ea);
182 (void)(ea <= v2ua);
183 (void)(v2ua >= ea);
184 (void)(ea >= v2ua);
185 (void)(v2ua < ea);
186 (void)(ea < v2ua);
187 (void)(v2ua > ea);
188 (void)(ea > v2ua);
189 (void)(v2ua && ea);
190 (void)(ea && v2ua);
191 (void)(v2ua || ea);
192 (void)(ea || v2ua);
194 (void)(v2ua & ea);
195 (void)(ea & v2ua);
196 (void)(v2ua | ea);
197 (void)(ea | v2ua);
198 (void)(v2ua ^ ea);
199 (void)(ea ^ v2ua);
200 (void)(v2ua << ea);
201 (void)(ea << v2ua);
202 (void)(v2ua >> ea);
203 (void)(ea >> v2ua);
205 v2ua += ea;
206 v2ua -= ea;
207 v2ua *= ea;
208 v2ua /= ea;
209 v2ua %= ea;
210 v2ua &= ea;
211 v2ua |= ea;
212 v2ua ^= ea;
213 v2ua >>= ea;
214 v2ua <<= ea;
216 ea += v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
217 ea -= v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
218 ea *= v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
219 ea /= v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
220 ea %= v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
221 ea &= v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
222 ea |= v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
223 ea ^= v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
224 ea >>= v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
225 ea <<= v2ua; // expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
229 // An incomplete enum type doesn't count as an integral type.
230 enum Enum2;
232 void test_incomplete_enum(enum Enum2 *ea, v2u v2ua) {
233 (void)(v2ua + *ea); // expected-error{{cannot convert between vector and non-scalar values}}
234 (void)(*ea + v2ua); // expected-error{{cannot convert between vector and non-scalar values}}