[ORC-RT][LoongArch] Add initial support for loongarch64 in ELFNixPlatform (#123575)
[llvm-project.git] / clang / test / Sema / attr-sized-by-late-parsed-struct-ptrs.c
blob07f8801787d668909c2b6aca3f8f76512dcf75d5
1 // RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s
3 #define __sized_by(f) __attribute__((sized_by(f)))
5 struct size_unknown;
6 struct size_known {
7 int field;
8 };
10 typedef void(*fn_ptr_ty)(void);
12 //==============================================================================
13 // __sized_by on struct member pointer in decl attribute position
14 //==============================================================================
16 struct on_member_pointer_complete_ty {
17 struct size_known * buf __sized_by(size);
18 int size;
21 struct on_member_pointer_incomplete_ty {
22 struct size_unknown * buf __sized_by(size);
23 int size;
26 struct on_member_pointer_const_incomplete_ty {
27 const struct size_unknown * buf __sized_by(size);
28 int size;
31 struct on_member_pointer_void_ty {
32 void* buf __sized_by(size);
33 int size;
36 struct on_member_pointer_fn_ptr_ty {
37 // buffer of `size` function pointers is allowed
38 void (**fn_ptr)(void) __sized_by(size);
39 int size;
43 struct on_member_pointer_fn_ptr_ty_ptr_ty {
44 // buffer of `size` function pointers is allowed
45 fn_ptr_ty* fn_ptr __sized_by(size);
46 int size;
49 struct on_member_pointer_fn_ty {
50 // buffer of function(s) with size `size` is allowed
51 // expected-error@+1{{'sized_by' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
52 void (*fn_ptr)(void) __sized_by(size);
53 int size;
56 struct on_member_pointer_fn_ptr_ty_ty {
57 // buffer of function(s) with size `size` is allowed
58 // expected-error@+1{{'sized_by' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
59 fn_ptr_ty fn_ptr __sized_by(size);
60 int size;
63 struct has_unannotated_vla {
64 int size;
65 int buffer[];
68 struct on_member_pointer_struct_with_vla {
69 // expected-error@+1{{'sized_by' cannot be applied to a pointer with pointee of unknown size because 'struct has_unannotated_vla' is a struct type with a flexible array member}}
70 struct has_unannotated_vla* objects __sized_by(size);
71 int size;
74 struct has_annotated_vla {
75 int size;
76 // expected-error@+1{{'sized_by' only applies to pointers; did you mean to use 'counted_by'?}}
77 int buffer[] __sized_by(size);
80 struct on_member_pointer_struct_with_annotated_vla {
81 // expected-error@+1{{'sized_by' cannot be applied to a pointer with pointee of unknown size because 'struct has_annotated_vla' is a struct type with a flexible array member}}
82 struct has_annotated_vla* objects __sized_by(size);
83 int size;
86 struct on_pointer_anon_buf {
87 // TODO: Support referring to parent scope
88 struct {
89 // expected-error@+1{{use of undeclared identifier 'size'}}
90 struct size_known *buf __sized_by(size);
92 int size;
95 struct on_pointer_anon_count {
96 struct size_known *buf __sized_by(size);
97 struct {
98 int size;
102 //==============================================================================
103 // __sized_by on struct member pointer in type attribute position
104 //==============================================================================
105 // TODO: Correctly parse sized_by as a type attribute. Currently it is parsed
106 // as a declaration attribute and is **not** late parsed resulting in the `size`
107 // field being unavailable.
109 struct on_member_pointer_complete_ty_ty_pos {
110 // TODO: Allow this
111 // expected-error@+1{{use of undeclared identifier 'size'}}
112 struct size_known *__sized_by(size) buf;
113 int size;
116 struct on_member_pointer_incomplete_ty_ty_pos {
117 // TODO: Allow this
118 // expected-error@+1{{use of undeclared identifier 'size'}}
119 struct size_unknown * __sized_by(size) buf;
120 int size;
123 struct on_member_pointer_const_incomplete_ty_ty_pos {
124 // TODO: Allow this
125 // expected-error@+1{{use of undeclared identifier 'size'}}
126 const struct size_unknown * __sized_by(size) buf;
127 int size;
130 struct on_member_pointer_void_ty_ty_pos {
131 // TODO: This should fail because the attribute is
132 // on a pointer with the pointee being an incomplete type.
133 // expected-error@+1{{use of undeclared identifier 'size'}}
134 void *__sized_by(size) buf;
135 int size;
138 // -
140 struct on_member_pointer_fn_ptr_ty_pos {
141 // TODO: buffer of `size` function pointers should be allowed
142 // but fails because this isn't late parsed.
143 // expected-error@+1{{use of undeclared identifier 'size'}}
144 void (** __sized_by(size) fn_ptr)(void);
145 int size;
148 struct on_member_pointer_fn_ptr_ty_ptr_ty_pos {
149 // TODO: buffer of `size` function pointers should be allowed
150 // but fails because this isn't late parsed.
151 // expected-error@+1{{use of undeclared identifier 'size'}}
152 fn_ptr_ty* __sized_by(size) fn_ptr;
153 int size;
156 struct on_member_pointer_fn_ty_ty_pos {
157 // TODO: This should fail because the attribute is
158 // on a pointer with the pointee being a function type.
159 // expected-error@+1{{use of undeclared identifier 'size'}}
160 void (* __sized_by(size) fn_ptr)(void);
161 int size;
164 struct on_member_pointer_fn_ptr_ty_ty_pos {
165 // TODO: buffer of `size` function pointers should be allowed
166 // expected-error@+1{{use of undeclared identifier 'size'}}
167 void (** __sized_by(size) fn_ptr)(void);
168 int size;
171 struct on_member_pointer_fn_ptr_ty_typedef_ty_pos {
172 // TODO: This should be allowed with sized_by.
173 // expected-error@+1{{use of undeclared identifier 'size'}}
174 fn_ptr_ty __sized_by(size) fn_ptr;
175 int size;
178 struct on_member_pointer_fn_ptr_ty_ty_pos_inner {
179 // TODO: This should be allowed with sized_by.
180 // expected-error@+1{{use of undeclared identifier 'size'}}
181 void (* __sized_by(size) * fn_ptr)(void);
182 int size;
185 struct on_member_pointer_struct_with_vla_ty_pos {
186 // TODO: This should be allowed with sized_by.
187 // expected-error@+1{{use of undeclared identifier 'size'}}
188 struct has_unannotated_vla *__sized_by(size) objects;
189 int size;
192 struct on_member_pointer_struct_with_annotated_vla_ty_pos {
193 // TODO: This should be allowed with sized_by.
194 // expected-error@+1{{use of undeclared identifier 'size'}}
195 struct has_annotated_vla* __sized_by(size) objects;
196 int size;
199 struct on_nested_pointer_inner {
200 // TODO: This should be disallowed because in the `-fbounds-safety` model
201 // `__sized_by` can only be nested when used in function parameters.
202 // expected-error@+1{{use of undeclared identifier 'size'}}
203 struct size_known *__sized_by(size) *buf;
204 int size;
207 struct on_nested_pointer_outer {
208 // TODO: Allow this
209 // expected-error@+1{{use of undeclared identifier 'size'}}
210 struct size_known **__sized_by(size) buf;
211 int size;
214 struct on_pointer_anon_buf_ty_pos {
215 struct {
216 // TODO: Support referring to parent scope
217 // expected-error@+1{{use of undeclared identifier 'size'}}
218 struct size_known * __sized_by(size) buf;
220 int size;
223 struct on_pointer_anon_count_ty_pos {
224 // TODO: Allow this
225 // expected-error@+1{{use of undeclared identifier 'size'}}
226 struct size_known *__sized_by(size) buf;
227 struct {
228 int size;
232 //==============================================================================
233 // __sized_by on struct non-pointer members
234 //==============================================================================
236 struct on_pod_ty {
237 // expected-error-re@+1{{'sized_by' only applies to pointers{{$}}}}
238 int wrong_ty __sized_by(size);
239 int size;
242 struct on_void_ty {
243 // expected-error-re@+2{{'sized_by' only applies to pointers{{$}}}}
244 // expected-error@+1{{field has incomplete type 'void'}}
245 void wrong_ty __sized_by(size);
246 int size;