• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wall -W -Wno-comment -triple arm64-linux-gnu -target-feature +sve -std=c90 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -Wall -W -triple arm64-linux-gnu -target-feature +sve -std=c11 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -Wall -W -triple arm64-linux-gnu -target-feature +sve -std=gnu11 %s
4 
5 typedef __SVInt8_t svint8_t;
6 typedef __SVInt16_t svint16_t;
7 
8 svint8_t global_int8;          // expected-error {{non-local variable with sizeless type 'svint8_t'}}
9 extern svint8_t extern_int8;   // expected-error {{non-local variable with sizeless type 'svint8_t'}}
10 static svint8_t static_int8;   // expected-error {{non-local variable with sizeless type 'svint8_t'}}
11 __thread svint8_t thread_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
12 svint8_t *global_int8_ptr;
13 extern svint8_t *extern_int8_ptr;
14 static svint8_t *static_int8_ptr;
15 
16 typedef svint8_t int8_typedef;
17 typedef svint8_t *int8_ptr_typedef;
18 
19 int sizeof_int8 = sizeof(svint8_t);             // expected-error {{invalid application of 'sizeof' to sizeless type 'svint8_t'}}
20 int sizeof_int8_var = sizeof(*extern_int8_ptr); // expected-error {{invalid application of 'sizeof' to sizeless type 'svint8_t'}}
21 int sizeof_int8_var_ptr = sizeof(extern_int8_ptr);
22 
23 int alignof_int8 = _Alignof(svint8_t);                // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}}
24 int alignof_int8_var = _Alignof(*extern_int8_ptr);    // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}} expected-warning {{GNU extension}}
25 int alignof_int8_var_ptr = _Alignof(extern_int8_ptr); // expected-warning {{GNU extension}}
26 
27 void pass_int8(svint8_t); // expected-note {{passing argument to parameter here}}
28 
29 svint8_t return_int8();
30 
31 typedef svint8_t vec_int8_a __attribute__((vector_size(64)));    // expected-error {{invalid vector element type}}
32 typedef svint8_t vec_int8_b __attribute__((ext_vector_type(4))); // expected-error {{invalid vector element type}}
33 
34 void dump(const volatile void *);
35 
36 void __attribute__((overloadable)) overf(svint8_t);
37 void __attribute__((overloadable)) overf(svint16_t);
38 
39 void __attribute__((overloadable)) overf8(svint8_t); // expected-note + {{not viable}}
40 void __attribute__((overloadable)) overf8(int);      // expected-note + {{not viable}}
41 
42 void __attribute__((overloadable)) overf16(svint16_t); // expected-note + {{not viable}}
43 void __attribute__((overloadable)) overf16(int);       // expected-note + {{not viable}}
44 
45 void noproto();
46 void varargs(int, ...);
47 
unused()48 void unused() {
49   svint8_t unused_int8; // expected-warning {{unused}}
50 }
51 
52 struct incomplete_struct *incomplete_ptr;
53 
54 typedef svint8_t sizeless_array[1]; // expected-error {{array has sizeless element type}}
55 
func(int sel)56 void func(int sel) {
57   static svint8_t static_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
58 
59   svint8_t local_int8;
60   svint16_t local_int16;
61 
62   svint8_t __attribute__((aligned)) aligned_int8_1;    // expected-error {{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
63   svint8_t __attribute__((aligned(4))) aligned_int8_2; // expected-error {{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
64   svint8_t _Alignas(int) aligned_int8_3;               // expected-error {{'_Alignas' attribute cannot be applied to sizeless type 'svint8_t'}}
65 
66   int _Alignas(svint8_t) aligned_int; // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}}
67 
68   // Using pointers to sizeless data isn't wrong here, but because the
69   // type is incomplete, it doesn't provide any alignment guarantees.
70   _Static_assert(__atomic_is_lock_free(1, &local_int8) == __atomic_is_lock_free(1, incomplete_ptr), "");
71   _Static_assert(__atomic_is_lock_free(2, &local_int8) == __atomic_is_lock_free(2, incomplete_ptr), ""); // expected-error {{static_assert expression is not an integral constant expression}}
72   _Static_assert(__atomic_always_lock_free(1, &local_int8) == __atomic_always_lock_free(1, incomplete_ptr), "");
73 
74   local_int8; // expected-warning {{expression result unused}}
75 
76   (void)local_int8;
77 
78   local_int8, 0; // expected-warning + {{expression result unused}}
79 
80   0, local_int8; // expected-warning + {{expression result unused}}
81 
82   svint8_t init_int8 = local_int8;
83   svint8_t bad_init_int8 = for; // expected-error {{expected expression}}
84 
85   int empty_brace_init_int = {}; // expected-error {{scalar initializer cannot be empty}}
86   svint8_t empty_brace_init_int8 = {}; // expected-error {{initializer for sizeless type 'svint8_t' (aka '__SVInt8_t') cannot be empty}}
87   svint8_t brace_init_int8 = {local_int8};
88   svint8_t bad_brace_init_int8_1 = {local_int8, 0};    // expected-warning {{excess elements in initializer for indivisible sizeless type 'svint8_t'}}
89   svint8_t bad_brace_init_int8_2 = {0};                // expected-error {{incompatible type 'int'}}
90   svint8_t bad_brace_init_int8_3 = {local_int16};      // expected-error {{incompatible type 'svint16_t'}}
91   svint8_t bad_brace_init_int8_4 = {[0] = local_int8}; // expected-error {{designator in initializer for indivisible sizeless type 'svint8_t'}}
92   svint8_t bad_brace_init_int8_5 = {{local_int8}};     // expected-warning {{too many braces around initializer}}
93   svint8_t bad_brace_init_int8_6 = {{local_int8, 0}};  // expected-warning {{too many braces around initializer}}
94 
95   const svint8_t const_int8 = local_int8; // expected-note {{declared const here}}
96   const svint8_t uninit_const_int8;
97 
98   volatile svint8_t volatile_int8;
99 
100   const volatile svint8_t const_volatile_int8 = local_int8; // expected-note {{declared const here}}
101   const volatile svint8_t uninit_const_volatile_int8;
102 
103   _Atomic svint8_t atomic_int8;      // expected-error {{_Atomic cannot be applied to sizeless type 'svint8_t'}}
104   __restrict svint8_t restrict_int8; // expected-error {{requires a pointer or reference}}
105 
106   svint8_t array_int8[1];          // expected-error {{array has sizeless element type}}
107   svint8_t array_int8_init[] = {}; // expected-error {{array has sizeless element type}}
108 
109   _Bool test_int8 = init_int8; // expected-error {{initializing '_Bool' with an expression of incompatible type 'svint8_t'}}
110 
111   int int_int8 = init_int8; // expected-error {{initializing 'int' with an expression of incompatible type 'svint8_t'}}
112 
113   init_int8 = local_int8;
114   init_int8 = local_int16; // expected-error {{assigning to 'svint8_t' (aka '__SVInt8_t') from incompatible type 'svint16_t'}}
115   init_int8 = sel;         // expected-error {{assigning to 'svint8_t' (aka '__SVInt8_t') from incompatible type 'int'}}
116 
117   sel = local_int8; // expected-error {{assigning to 'int' from incompatible type 'svint8_t'}}
118 
119   local_int8 = (svint8_t)local_int8;
120   local_int8 = (const svint8_t)local_int8;
121   local_int8 = (svint8_t)local_int16; // expected-error {{used type 'svint8_t' (aka '__SVInt8_t') where arithmetic or pointer type is required}}
122   local_int8 = (svint8_t)0;           // expected-error {{used type 'svint8_t' (aka '__SVInt8_t') where arithmetic or pointer type is required}}
123   sel = (int)local_int8;              // expected-error {{operand of type 'svint8_t' (aka '__SVInt8_t') where arithmetic or pointer type is required}}
124 
125   init_int8 = local_int8;
126   init_int8 = const_int8;
127   init_int8 = volatile_int8;
128   init_int8 = const_volatile_int8;
129 
130   const_int8 = local_int8; // expected-error {{cannot assign to variable 'const_int8' with const-qualified type 'const svint8_t'}}
131 
132   volatile_int8 = local_int8;
133   volatile_int8 = const_int8;
134   volatile_int8 = volatile_int8;
135   volatile_int8 = const_volatile_int8;
136 
137   const_volatile_int8 = local_int8; // expected-error {{cannot assign to variable 'const_volatile_int8' with const-qualified type 'const volatile svint8_t'}}
138 
139   init_int8 = sel ? init_int8 : local_int8;
140   init_int8 = sel ? init_int8 : const_int8;
141   init_int8 = sel ? volatile_int8 : const_int8;
142   init_int8 = sel ? volatile_int8 : const_volatile_int8;
143 
144   pass_int8(local_int8);
145   pass_int8(local_int16); // expected-error {{passing 'svint16_t' (aka '__SVInt16_t') to parameter of incompatible type 'svint8_t'}}
146 
147   local_int8 = return_int8();
148   local_int16 = return_int8(); // expected-error {{assigning to 'svint16_t' (aka '__SVInt16_t') from incompatible type 'svint8_t'}}
149 
150   dump(&local_int8);
151   dump(&const_int8);
152   dump(&volatile_int8);
153   dump(&const_volatile_int8);
154 
155   dump(&local_int8 + 1); // expected-error {{arithmetic on a pointer to sizeless type}}
156 
157   *&local_int8 = local_int8;
158   *&const_int8 = local_int8; // expected-error {{read-only variable is not assignable}}
159   *&volatile_int8 = local_int8;
160   *&const_volatile_int8 = local_int8; // expected-error {{read-only variable is not assignable}}
161 
162   global_int8_ptr[0] = local_int8;       // expected-error {{subscript of pointer to sizeless type 'svint8_t'}}
163   global_int8_ptr[1] = local_int8;       // expected-error {{subscript of pointer to sizeless type 'svint8_t'}}
164   global_int8_ptr = &global_int8_ptr[2]; // expected-error {{subscript of pointer to sizeless type 'svint8_t'}}
165 
166   overf(local_int8);
167   overf(local_int16);
168 
169   overf8(local_int8);
170   overf8(local_int16); // expected-error {{no matching function}}
171 
172   overf16(local_int8); // expected-error {{no matching function}}
173   overf16(local_int16);
174 
175   noproto(local_int8);
176   varargs(1, local_int8, local_int16);
177 
178   global_int8_ptr++;                 // expected-error {{arithmetic on a pointer to sizeless type}}
179   global_int8_ptr--;                 // expected-error {{arithmetic on a pointer to sizeless type}}
180   ++global_int8_ptr;                 // expected-error {{arithmetic on a pointer to sizeless type}}
181   --global_int8_ptr;                 // expected-error {{arithmetic on a pointer to sizeless type}}
182   global_int8_ptr + 1;               // expected-error {{arithmetic on a pointer to sizeless type}}
183   global_int8_ptr - 1;               // expected-error {{arithmetic on a pointer to sizeless type}}
184   global_int8_ptr += 1;              // expected-error {{arithmetic on a pointer to sizeless type}}
185   global_int8_ptr -= 1;              // expected-error {{arithmetic on a pointer to sizeless type}}
186   global_int8_ptr - global_int8_ptr; // expected-error {{arithmetic on a pointer to sizeless type}}
187 
188   +init_int8;       // expected-error {{invalid argument type 'svint8_t'}}
189   ++init_int8;      // expected-error {{cannot increment value of type 'svint8_t'}}
190   init_int8++;      // expected-error {{cannot increment value of type 'svint8_t'}}
191   -init_int8;       // expected-error {{invalid argument type 'svint8_t'}}
192   --init_int8;      // expected-error {{cannot decrement value of type 'svint8_t'}}
193   init_int8--;      // expected-error {{cannot decrement value of type 'svint8_t'}}
194   ~init_int8;       // expected-error {{invalid argument type 'svint8_t'}}
195   !init_int8;       // expected-error {{invalid argument type 'svint8_t'}}
196   *init_int8;       // expected-error {{indirection requires pointer operand}}
197   __real init_int8; // expected-error {{invalid type 'svint8_t'}}
198   __imag init_int8; // expected-error {{invalid type 'svint8_t'}}
199 
200   local_int8 + init_int8;  // expected-error {{invalid operands to binary expression}}
201   local_int8 - init_int8;  // expected-error {{invalid operands to binary expression}}
202   local_int8 *init_int8;   // expected-error {{invalid operands to binary expression}}
203   local_int8 / init_int8;  // expected-error {{invalid operands to binary expression}}
204   local_int8 % init_int8;  // expected-error {{invalid operands to binary expression}}
205   local_int8 &init_int8;   // expected-error {{invalid operands to binary expression}}
206   local_int8 | init_int8;  // expected-error {{invalid operands to binary expression}}
207   local_int8 ^ init_int8;  // expected-error {{invalid operands to binary expression}}
208   local_int8 << init_int8; // expected-error {{invalid operands to binary expression}}
209   local_int8 >> init_int8; // expected-error {{invalid operands to binary expression}}
210   local_int8 < init_int8;  // expected-error {{invalid operands to binary expression}}
211   local_int8 <= init_int8; // expected-error {{invalid operands to binary expression}}
212   local_int8 == init_int8; // expected-error {{invalid operands to binary expression}}
213   local_int8 != init_int8; // expected-error {{invalid operands to binary expression}}
214   local_int8 >= init_int8; // expected-error {{invalid operands to binary expression}}
215   local_int8 > init_int8;  // expected-error {{invalid operands to binary expression}}
216   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}}
217   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}}
218 
219   local_int8 += init_int8;  // expected-error {{invalid operands to binary expression}}
220   local_int8 -= init_int8;  // expected-error {{invalid operands to binary expression}}
221   local_int8 *= init_int8;  // expected-error {{invalid operands to binary expression}}
222   local_int8 /= init_int8;  // expected-error {{invalid operands to binary expression}}
223   local_int8 %= init_int8;  // expected-error {{invalid operands to binary expression}}
224   local_int8 &= init_int8;  // expected-error {{invalid operands to binary expression}}
225   local_int8 |= init_int8;  // expected-error {{invalid operands to binary expression}}
226   local_int8 ^= init_int8;  // expected-error {{invalid operands to binary expression}}
227   local_int8 <<= init_int8; // expected-error {{invalid operands to binary expression}}
228   local_int8 >>= init_int8; // expected-error {{invalid operands to binary expression}}
229 
230   local_int8 + 0;  // expected-error {{invalid operands to binary expression}}
231   local_int8 - 0;  // expected-error {{invalid operands to binary expression}}
232   local_int8 * 0;  // expected-error {{invalid operands to binary expression}}
233   local_int8 / 0;  // expected-error {{invalid operands to binary expression}}
234   local_int8 % 0;  // expected-error {{invalid operands to binary expression}}
235   local_int8 & 0;  // expected-error {{invalid operands to binary expression}}
236   local_int8 | 0;  // expected-error {{invalid operands to binary expression}}
237   local_int8 ^ 0;  // expected-error {{invalid operands to binary expression}}
238   local_int8 << 0; // expected-error {{invalid operands to binary expression}}
239   local_int8 >> 0; // expected-error {{invalid operands to binary expression}}
240   local_int8 < 0;  // expected-error {{invalid operands to binary expression}}
241   local_int8 <= 0; // expected-error {{invalid operands to binary expression}}
242   local_int8 == 0; // expected-error {{invalid operands to binary expression}}
243   local_int8 != 0; // expected-error {{invalid operands to binary expression}}
244   local_int8 >= 0; // expected-error {{invalid operands to binary expression}}
245   local_int8 > 0;  // expected-error {{invalid operands to binary expression}}
246   local_int8 && 0; // expected-error {{invalid operands to binary expression}}
247   local_int8 || 0; // expected-error {{invalid operands to binary expression}}
248 
249   if (local_int8) { // expected-error {{statement requires expression of scalar type}}
250   }
251   while (local_int8) { // expected-error {{statement requires expression of scalar type}}
252   }
253   do { // expected-error {{statement requires expression of scalar type}}
254   } while (local_int8);
255   switch (local_int8) { // expected-error {{statement requires expression of integer type}}
256   default:;
257   }
258 }
259 
vararg_receiver(int count,svint8_t first,...)260 int vararg_receiver(int count, svint8_t first, ...) {
261   __builtin_va_list va;
262 
263   __builtin_va_start(va, first);
264   __builtin_va_arg(va, svint8_t);
265   __builtin_va_end(va);
266   return count;
267 }
268 
269 struct sized_struct {
270   int f1;
271   svint8_t f2;     // expected-error {{field has sizeless type 'svint8_t'}}
272   svint8_t f3 : 2; // expected-error {{field has sizeless type 'svint8_t'}}
273   svint8_t : 3;    // expected-error {{field has sizeless type 'svint8_t'}}
274 };
275 
276 union sized_union {
277   int f1;
278   svint8_t f2;     // expected-error {{field has sizeless type 'svint8_t'}}
279   svint8_t f3 : 2; // expected-error {{field has sizeless type 'svint8_t'}}
280   svint8_t : 3;    // expected-error {{field has sizeless type 'svint8_t'}}
281 };
282 
283 #if __STDC_VERSION__ >= 201112L
test_generic(void)284 void test_generic(void) {
285   svint8_t local_int8;
286   svint16_t local_int16;
287 
288   int a1[_Generic(local_int8, svint8_t : 1, svint16_t : 2, default : 3) == 1 ? 1 : -1];
289   int a2[_Generic(local_int16, svint8_t : 1, svint16_t : 2, default : 3) == 2 ? 1 : -1];
290   int a3[_Generic(0, svint8_t : 1, svint16_t : 2, default : 3) == 3 ? 1 : -1];
291   (void)_Generic(0, svint8_t : 1, svint8_t : 2, default : 3); // expected-error {{type 'svint8_t' (aka '__SVInt8_t') in generic association compatible with previously specified type 'svint8_t'}} expected-note {{compatible type}}
292 }
293 
test_compound_literal(void)294 void test_compound_literal(void) {
295   svint8_t local_int8;
296 
297   (void)(svint8_t){local_int8};
298 }
299 #endif
300