comparison gcc/testsuite/g++.dg/ext/sve-sizeless-2.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // { dg-do compile { target aarch64*-*-* } }
2 // { dg-options "-Wclass-memaccess -msve-vector-bits=256" }
3
4 #pragma GCC target "+sve"
5
6 typedef __SIZE_TYPE__ size_t;
7 inline void *operator new (size_t, void *__p) throw() { return __p; }
8
9 #include <arm_sve.h>
10
11 typedef signed char int8x32_t __attribute__((__vector_size__ (32)));
12
13 // Sizeless objects with global scope.
14
15 svint8_t global_sve_sc; // { dg-error {SVE type 'svint8_t' does not have a fixed size} }
16 static svint8_t local_sve_sc; // { dg-error {SVE type 'svint8_t' does not have a fixed size} }
17 extern svint8_t extern_sve_sc; // { dg-error {SVE type 'svint8_t' does not have a fixed size} }
18 __thread svint8_t tls_sve_sc; // { dg-error {variables of type 'svint8_t' cannot have thread-local storage duration} }
19
20 // Sizeless arrays.
21
22 typedef svint8_t array_type[2]; // { dg-error {array elements cannot have SVE type 'svint8_t'} }
23 extern svint8_t extern_array[]; // { dg-error {array elements cannot have SVE type 'svint8_t'} }
24
25 // Sizeless member variables.
26
27 struct struct1 {
28 svint8_t a; // { dg-error {member variables cannot have SVE type 'svint8_t'} }
29 };
30
31 union union1 {
32 svint8_t a; // { dg-error {member variables cannot have SVE type 'svint8_t'} }
33 };
34
35 #if __cplusplus >= 201103L
36 struct static_sve_sc {
37 static svint8_t sve_sc1 = {}; // { dg-error {SVE type 'svint8_t' does not have a fixed size} "" { target c++11 } }
38 };
39 #endif
40
41 // Sizeless member variables in templated structures.
42
43 template<typename T>
44 struct templated_struct1 {
45 svint8_t a; // { dg-error {member variables cannot have SVE type 'svint8_t'} }
46 };
47
48 template<typename T>
49 struct templated_struct2 {
50 T a; // { dg-error {member variables cannot have SVE type '(svint8_t|__SVInt8_t)'} }
51 };
52
53 template class templated_struct2<svint8_t>;
54
55 template<typename T>
56 struct templated_struct3 {
57 T &a;
58 };
59
60 template class templated_struct3<svint8_t>;
61
62 #if __cplusplus >= 201103L
63 template<typename T>
64 struct templated_struct4 {
65 static T a; // { dg-error {SVE type '(svint8_t|__SVInt8_t)' does not have a fixed size} "" { target c++11 } }
66 static T b = {}; // { dg-error {SVE type '(svint8_t|__SVInt8_t)' does not have a fixed size} "" { target c++11 } }
67 };
68
69 template class templated_struct4<svint8_t>;
70 #endif
71
72 template<typename T> struct templated_struct5 : T {}; // { dg-error {base type '[^']*' fails to be a struct or class type} }
73 template class templated_struct5<svint8_t>;
74
75 #if __cplusplus >= 201103L
76 template<int N> using typedef_sizeless1 = svint8_t;
77 template<int N> using typedef_sizeless1 = svint8_t;
78 template<typename T> using array = T[2];
79 #endif
80
81 // Pointers to sizeless types.
82
83 svint8_t *global_sve_sc_ptr;
84
85 // Sizeless arguments and return values.
86
87 void ext_consume_sve_sc (svint8_t);
88 void ext_consume_const_int_ref (const int &);
89 void ext_consume_varargs (int, ...);
90 svint8_t ext_produce_sve_sc ();
91
92 // Sizeless types in throw specifications.
93
94 #if __cplusplus < 201103L
95 void thrower1 () throw (svint8_t); // { dg-error {cannot throw or catch SVE type 'svint8_t'} "" { target c++98_only } }
96 void thrower2 () throw (svint8_t); // { dg-error {cannot throw or catch SVE type 'svint8_t'} "" { target c++98_only } }
97 void thrower3 () throw (svint8_t); // { dg-error {cannot throw or catch SVE type 'svint8_t'} "" { target c++98_only } }
98 #endif
99
100 // Main tests for statements and expressions.
101
102 void
103 statements (int n)
104 {
105 // Local declarations.
106
107 svint8_t sve_sc1, sve_sc2;
108 volatile svint8_t volatile_sve_sc1;
109 int8x32_t gnu_sc1;
110 svint16_t sve_sh1;
111
112 // Layout queries.
113
114 sizeof (svint8_t); // { dg-error {SVE type 'svint8_t' does not have a fixed size} }
115 sizeof (sve_sc1); // { dg-error {SVE type 'svint8_t' does not have a fixed size} }
116 sizeof (ext_produce_sve_sc ()); // { dg-error {SVE type 'svint8_t' does not have a fixed size} }
117 __alignof (svint8_t); // { dg-error {SVE type 'svint8_t' does not have a defined alignment} }
118 __alignof (sve_sc1); // { dg-error {SVE type 'svint8_t' does not have a defined alignment} }
119 __alignof (ext_produce_sve_sc ()); // { dg-error {SVE type 'svint8_t' does not have a defined alignment} }
120
121 #if __cplusplus >= 201103L
122 array<svint8_t> foo = {}; // { dg-error {array elements cannot have SVE type '(svint8_t|__SVInt8_t)'} "" { target c++11 } }
123 #endif
124
125 // Initialization.
126
127 int init_int1 = sve_sc1; // { dg-error {cannot convert 'svint8_t' to 'int' in initialization} }
128 int init_int2 = { sve_sc1 }; // { dg-error {cannot convert 'svint8_t' to 'int' in initialization} }
129
130 svint8_t init_sve_sc1 (sve_sc1);
131 svint8_t init_sve_sc2 (sve_sh1); // { dg-error {cannot convert 'svint16_t' to 'svint8_t'} }
132 svint8_t init_sve_sc3 = sve_sc1;
133 svint8_t init_sve_sc4 = sve_sh1; // { dg-error {cannot convert 'svint16_t' to 'svint8_t'} }
134 svint8_t init_sve_sc5 = {};
135 svint8_t init_sve_sc6 = { sve_sc1 };
136 svint8_t init_sve_sc7 = { sve_sh1 }; // { dg-error {cannot convert 'svint16_t' to 'svint8_t'} }
137
138 // Constructor calls.
139
140 (0, svint8_t ());
141
142 // Lvalue reference binding
143
144 svint8_t &lvalue_ref_sve_sc1 = sve_sc1;
145 svint8_t &lvalue_ref_sve_sc2 = ext_produce_sve_sc (); // { dg-error {cannot bind non-const lvalue reference of type 'svint8_t&' to an rvalue of type 'svint8_t'} }
146 svint8_t &lvalue_ref_sve_sc3 = sve_sh1; // { dg-error {invalid initialization of reference of type 'svint8_t&' from expression of type 'svint16_t'} }
147
148 const svint8_t &const_lvalue_ref_sve_sc1 = sve_sc1;
149 const svint8_t &const_lvalue_ref_sve_sc2 = ext_produce_sve_sc ();
150 const svint8_t &const_lvalue_ref_sve_sc3 = sve_sh1; // { dg-error {invalid initialization of reference of type 'const svint8_t&' from expression of type 'svint16_t'} }
151
152 // Compound literals.
153
154 (int) { sve_sc1 }; // { dg-error {cannot convert 'svint8_t' to 'int' in initialization} }
155
156 // Arrays.
157
158 svint8_t array[2]; // { dg-error {array elements cannot have SVE type 'svint8_t'} }
159 svint8_t zero_length_array[0]; // { dg-error {array elements cannot have SVE type 'svint8_t'} }
160 svint8_t empty_init_array[] = {}; // { dg-error {array elements cannot have SVE type 'svint8_t'} }
161
162 // Assignment.
163
164 n = sve_sc1; // { dg-error {cannot convert 'svint8_t' to 'int' in assignment} }
165
166 sve_sc1 = 0; // { dg-error {cannot convert 'int' to 'svint8_t' in assignment} }
167 sve_sc1 = sve_sc1;
168 sve_sc1 = gnu_sc1;
169 gnu_sc1 = sve_sc1;
170 sve_sc1 = sve_sh1; // { dg-error {cannot convert 'svint16_t' to 'svint8_t'} }
171
172 // Casting.
173
174 (void) sve_sc1;
175 (void) volatile_sve_sc1;
176 (void) *&volatile_sve_sc1;
177
178 // Addressing and dereferencing.
179
180 svint8_t *sve_sc_ptr = &sve_sc1;
181 int8x32_t *gnu_sc_ptr = &gnu_sc1;
182 sve_sc_ptr = (svint16_t *) 0; // { dg-error {cannot convert 'svint16_t\*' to 'svint8_t\*' in assignment} }
183
184 // Pointer assignment.
185
186 gnu_sc_ptr = sve_sc_ptr; // { dg-error {invalid conversion from 'svint8_t\*' to 'int8x32_t\*'} }
187 sve_sc_ptr = gnu_sc_ptr; // { dg-error {invalid conversion from 'int8x32_t\*'[^\n]* to 'svint8_t\*'} }
188
189 // Pointer arithmetic.
190
191 ++sve_sc_ptr; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
192 --sve_sc_ptr; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
193 sve_sc_ptr++; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
194 sve_sc_ptr--; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
195 sve_sc_ptr += 0; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
196 sve_sc_ptr += 1; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
197 sve_sc_ptr -= 0; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
198 sve_sc_ptr -= 1; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
199 sve_sc_ptr - sve_sc_ptr; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
200 gnu_sc_ptr - sve_sc_ptr; // { dg-error {invalid operands of types 'int8x32_t\*'[^\n]* and 'svint8_t\*' to binary 'operator-'} }
201 sve_sc_ptr - gnu_sc_ptr; // { dg-error {invalid operands of types 'svint8_t\*' and 'int8x32_t\*'[^\n]* to binary 'operator-'} }
202 sve_sc1 = sve_sc_ptr[0]; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
203 sve_sc1 = sve_sc_ptr[1]; // { dg-error {arithmetic on pointer to SVE type 'svint8_t'} }
204
205 // Pointer comparison.
206
207 sve_sc_ptr == &sve_sc1;
208 sve_sc_ptr != &sve_sc1;
209 sve_sc_ptr < &sve_sc1;
210 sve_sc_ptr <= &sve_sc1;
211 sve_sc_ptr > &sve_sc1;
212 sve_sc_ptr >= &sve_sc1;
213 gnu_sc_ptr == sve_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
214 gnu_sc_ptr != sve_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
215 gnu_sc_ptr < sve_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
216 gnu_sc_ptr <= sve_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
217 gnu_sc_ptr > sve_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
218 gnu_sc_ptr >= sve_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
219 sve_sc_ptr == gnu_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
220 sve_sc_ptr != gnu_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
221 sve_sc_ptr < gnu_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
222 sve_sc_ptr <= gnu_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
223 sve_sc_ptr > gnu_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
224 sve_sc_ptr >= gnu_sc_ptr; // { dg-error {comparison between distinct pointer types [^\n]*lacks a cast} }
225
226 // New and delete.
227
228 new svint8_t; // { dg-error {cannot allocate objects with SVE type 'svint8_t'} }
229 new svint8_t (); // { dg-error {cannot allocate objects with SVE type 'svint8_t'} }
230
231 new (global_sve_sc_ptr) svint8_t; // { dg-error {cannot allocate objects with SVE type 'svint8_t'} }
232 new (global_sve_sc_ptr) svint8_t (); // { dg-error {cannot allocate objects with SVE type 'svint8_t'} }
233
234 sve_sc1.~svint8_t(); // { dg-error {expected class-name before '\(' token} }
235 delete sve_sc_ptr; // { dg-error {cannot delete objects with SVE type '(svint8_t|__SVInt8_t)'} }
236 delete[] sve_sc_ptr; // { dg-error {cannot delete objects with SVE type 'svint8_t'} }
237
238 // Conditional expressions.
239
240 0 ? sve_sc1 : sve_sc1;
241 0 ? sve_sc1 : sve_sh1; // { dg-error {different types 'svint8_t' and 'svint16_t'} }
242 0 ? sve_sc1 : 0; // { dg-error {different types 'svint8_t' and 'int'} }
243 0 ? 0 : sve_sc1; // { dg-error {different types 'int' and 'svint8_t'} }
244 0 ? sve_sc1 : sve_sc1;
245 0 ? sve_sc_ptr : sve_sc_ptr;
246 0 ? sve_sc_ptr : gnu_sc_ptr; // { dg-error {conditional expression between distinct pointer types [^\n]*lacks a cast} }
247 0 ? gnu_sc_ptr : sve_sc_ptr; // { dg-error {conditional expression between distinct pointer types [^\n]*lacks a cast} }
248
249 // Function arguments.
250
251 ext_consume_sve_sc (sve_sc1);
252 ext_consume_sve_sc (sve_sh1); // { dg-error {cannot convert 'svint16_t' to 'svint8_t'} }
253 ext_consume_const_int_ref (sve_sc1); // { dg-error {invalid initialization of reference of type 'const int&' from expression of type 'svint8_t'} }
254 ext_consume_varargs (sve_sc1); // { dg-error {cannot convert 'svint8_t' to 'int'} }
255 ext_consume_varargs (1, sve_sc1);
256
257 // Function returns.
258
259 ext_produce_sve_sc ();
260 sve_sc1 = ext_produce_sve_sc ();
261 sve_sh1 = ext_produce_sve_sc (); // { dg-error {cannot convert 'svint8_t' to 'svint16_t' in assignment} }
262
263 // Auto
264
265 #if __cplusplus >= 201103L
266 auto auto_sve_sc1 = sve_sc1;
267 auto auto_sve_sc1_return = ext_produce_sve_sc ();
268 #endif
269
270 // Varargs processing.
271
272 __builtin_va_list valist;
273 __builtin_va_arg (valist, svint8_t);
274
275 // Other built-ins
276
277 __builtin_launder (sve_sc1); // { dg-error {non-pointer argument to '__builtin_launder'} }
278 __builtin_memcpy (&sve_sc1, &sve_sc2, 2);
279
280 // Lambdas
281
282 #if __cplusplus >= 201103L
283 [sve_sc1] () {}; // { dg-error {capture by copy of SVE type 'svint8_t'} "" { target c++11 } }
284 [=] () { &sve_sc1; }; // { dg-error {capture by copy of SVE type 'svint8_t'} "" { target c++11 } }
285 [&sve_sc1] () { sve_sc1 = sve_sc2; }; // { dg-error {'sve_sc2' is not captured} "" { target c++11 } }
286 [&sve_sc1, &sve_sc2] () { sve_sc1 = sve_sc2; };
287 [&] () { sve_sc1 = sve_sc2; };
288 [] () { return ext_produce_sve_sc (); } ();
289 #endif
290
291 // Exceptions
292
293 throw svint8_t (); // { dg-error {cannot throw or catch SVE type 'svint8_t'} }
294 try {} catch (svint8_t x) {} // { dg-error {cannot throw or catch SVE type 'svint8_t'} }
295 try {} catch (svint8_t &x) {} // { dg-error {cannot throw or catch SVE type 'svint8_t'} }
296 try {} catch (svint8_t *x) {}
297 #if __cplusplus < 201103L
298 thrower2 ();
299 #endif
300
301 // Use in traits. Doesn't use static_assert so that tests work with
302 // earlier -std=s.
303
304 { typedef int f[__has_nothrow_assign (svint8_t) ? 1 : -1]; }
305 { typedef int f[__has_trivial_assign (svint8_t) ? 1 : -1]; }
306 { typedef int f[__has_nothrow_constructor (svint8_t) ? 1 : -1]; }
307 { typedef int f[__has_trivial_constructor (svint8_t) ? 1 : -1]; }
308 { typedef int f[__has_nothrow_copy (svint8_t) ? 1 : -1]; }
309 { typedef int f[__has_trivial_copy (svint8_t) ? 1 : -1]; }
310 { typedef int f[__has_trivial_destructor (svint8_t) ? 1 : -1]; }
311 { typedef int f[__has_unique_object_representations (svint8_t) ? 1 : -1]; }
312 { typedef int f[!__has_virtual_destructor (svint8_t) ? 1 : -1]; }
313 { typedef int f[!__is_abstract (svint8_t) ? 1 : -1]; }
314 { typedef int f[!__is_aggregate (svint8_t) ? 1 : -1]; }
315 { typedef int f[!__is_base_of (svint8_t, svint8_t) ? 1 : -1]; }
316 { typedef int f[!__is_base_of (svint8_t, svint16_t) ? 1 : -1]; }
317 { typedef int f[!__is_class (svint8_t) ? 1 : -1]; }
318 { typedef int f[!__is_empty (svint8_t) ? 1 : -1]; }
319 { typedef int f[!__is_enum (svint8_t) ? 1 : -1]; }
320 { typedef int f[!__is_final (svint8_t) ? 1 : -1]; }
321 { typedef int f[__is_pod (svint8_t) ? 1 : -1]; }
322 { typedef int f[!__is_polymorphic (svint8_t) ? 1 : -1]; }
323 { typedef int f[__is_same_as (svint8_t, svint8_t) ? 1 : -1]; }
324 { typedef int f[!__is_same_as (svint8_t, int8x32_t) ? 1 : -1]; }
325 { typedef int f[!__is_same_as (int8x32_t, svint8_t) ? 1 : -1]; }
326 { typedef int f[__is_same_as (svint8_t *, svint8_t *) ? 1 : -1]; }
327 { typedef int f[!__is_same_as (svint8_t *, int8x32_t *) ? 1 : -1]; }
328 { typedef int f[!__is_same_as (int8x32_t *, svint8_t *) ? 1 : -1]; }
329 { typedef int f[!__is_same_as (svint8_t, int) ? 1 : -1]; }
330 { typedef int f[!__is_same_as (svint8_t, svint16_t) ? 1 : -1]; }
331 { typedef int f[__is_trivial (svint8_t) ? 1 : -1]; }
332 { typedef int f[!__is_union (svint8_t) ? 1 : -1]; }
333 { typedef int f[__is_trivially_copyable (svint8_t) ? 1 : -1]; }
334 /* The intention is that svint8_t should behave like int8x32_t here. If the behavior
335 for int8x32_t changes then the behavior for svint8_t should change in the same
336 way. */
337 { typedef int f[!__is_trivially_assignable (int8x32_t, int8x32_t) ? 1 : -1]; }
338 { typedef int f[!__is_trivially_assignable (svint8_t, svint8_t) ? 1 : -1]; }
339 { typedef int f[!__is_trivially_assignable (svint8_t, int8x32_t) ? 1 : -1]; }
340 { typedef int f[!__is_trivially_assignable (int8x32_t, svint8_t) ? 1 : -1]; }
341 { typedef int f[!__is_trivially_assignable (svint8_t, int) ? 1 : -1]; }
342 { typedef int f[!__is_trivially_assignable (svint8_t, svint16_t) ? 1 : -1]; }
343 { typedef int f[!__is_assignable (int8x32_t, int8x32_t) ? 1 : -1]; }
344 { typedef int f[!__is_assignable (svint8_t, svint8_t) ? 1 : -1]; }
345 { typedef int f[!__is_assignable (svint8_t, int8x32_t) ? 1 : -1]; }
346 { typedef int f[!__is_assignable (int8x32_t, svint8_t) ? 1 : -1]; }
347 { typedef int f[!__is_assignable (svint8_t, int) ? 1 : -1]; }
348 { typedef int f[!__is_assignable (svint8_t, svint16_t) ? 1 : -1]; }
349 { typedef int f[__is_trivially_constructible (svint8_t) ? 1 : -1]; }
350 { typedef int f[__is_trivially_constructible (int8x32_t, int8x32_t) ? 1 : -1]; }
351 { typedef int f[__is_trivially_constructible (svint8_t, svint8_t) ? 1 : -1]; }
352 { typedef int f[__is_trivially_constructible (svint8_t, int8x32_t) ? 1 : -1]; }
353 { typedef int f[__is_trivially_constructible (int8x32_t, svint8_t) ? 1 : -1]; }
354 { typedef int f[!__is_trivially_constructible (svint8_t, int) ? 1 : -1]; }
355 { typedef int f[!__is_trivially_constructible (svint8_t, svint16_t) ? 1 : -1]; }
356 { typedef int f[__is_constructible (svint8_t) ? 1 : -1]; }
357 { typedef int f[__is_constructible (int8x32_t, int8x32_t) ? 1 : -1]; }
358 { typedef int f[__is_constructible (svint8_t, svint8_t) ? 1 : -1]; }
359 { typedef int f[__is_constructible (svint8_t, int8x32_t) ? 1 : -1]; }
360 { typedef int f[__is_constructible (int8x32_t, svint8_t) ? 1 : -1]; }
361 { typedef int f[!__is_constructible (svint8_t, int) ? 1 : -1]; }
362 { typedef int f[!__is_constructible (svint8_t, svint16_t) ? 1 : -1]; }
363 }
364
365 // Function parameters in definitions.
366
367 void
368 unnamed_st1 (svint8_t)
369 {
370 }
371
372 void
373 named_st1 (svint8_t param1)
374 {
375 svint8_t sve_sc1 = param1;
376 }
377
378 // Function return values in definitions.
379
380 svint8_t
381 ret_st1 (svint8_t param)
382 {
383 return param;
384 }
385
386 svint8_t
387 bad_ret_st1 (svint16_t param)
388 {
389 return param; // { dg-error {cannot convert 'svint16_t' to 'svint8_t' in return} }
390 }
391
392 #if __cplusplus >= 201103L
393 template<typename T>
394 void
395 const_to_sve_sc (T i)
396 {
397 constexpr svint8_t a = (svint8_t) i;
398 }
399 #endif
400
401 template<typename T>
402 int
403 get_x (T *a)
404 {
405 return a->a; // { dg-error {request for member 'a' in '\* a', which is of non-class type} }
406 }
407 template int get_x<svint8_t>(svint8_t *);
408
409 #if __cplusplus < 201103L
410 void thrower3 () throw (svint8_t) {} // { dg-error {cannot throw or catch SVE type 'svint8_t'} "" { target c++98_only } }
411 #endif
412
413 // Using "auto" as a return type.
414
415 #if __cplusplus >= 201402L
416 auto auto_ret_sve_sc (svint8_t *ptr) { return *ptr; }
417 const auto &auto_ret_const_sve_sc_ref (svint8_t *ptr) { return *ptr; }
418 auto &auto_ret_sve_sc_ref (svint8_t *ptr) { return *ptr; }
419 auto &&auto_ret_sve_sc_rvalue_ref (svint8_t *ptr) { return *ptr; }
420 #endif