1 // RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s
3 #define __sized_by(f) __attribute__((sized_by(f)))
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
);
21 struct on_member_pointer_incomplete_ty
{
22 struct size_unknown
* buf
__sized_by(size
);
26 struct on_member_pointer_const_incomplete_ty
{
27 const struct size_unknown
* buf
__sized_by(size
);
31 struct on_member_pointer_void_ty
{
32 void* buf
__sized_by(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
);
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
);
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
);
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
);
63 struct has_unannotated_vla
{
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
);
74 struct has_annotated_vla
{
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
);
86 struct on_pointer_anon_buf
{
87 // TODO: Support referring to parent scope
89 // expected-error@+1{{use of undeclared identifier 'size'}}
90 struct size_known
*buf
__sized_by(size
);
95 struct on_pointer_anon_count
{
96 struct size_known
*buf
__sized_by(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
{
111 // expected-error@+1{{use of undeclared identifier 'size'}}
112 struct size_known
*__sized_by(size
) buf
;
116 struct on_member_pointer_incomplete_ty_ty_pos
{
118 // expected-error@+1{{use of undeclared identifier 'size'}}
119 struct size_unknown
* __sized_by(size
) buf
;
123 struct on_member_pointer_const_incomplete_ty_ty_pos
{
125 // expected-error@+1{{use of undeclared identifier 'size'}}
126 const struct size_unknown
* __sized_by(size
) buf
;
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
;
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);
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
;
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);
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);
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
;
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);
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
;
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
;
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
;
207 struct on_nested_pointer_outer
{
209 // expected-error@+1{{use of undeclared identifier 'size'}}
210 struct size_known
**__sized_by(size
) buf
;
214 struct on_pointer_anon_buf_ty_pos
{
216 // TODO: Support referring to parent scope
217 // expected-error@+1{{use of undeclared identifier 'size'}}
218 struct size_known
* __sized_by(size
) buf
;
223 struct on_pointer_anon_count_ty_pos
{
225 // expected-error@+1{{use of undeclared identifier 'size'}}
226 struct size_known
*__sized_by(size
) buf
;
232 //==============================================================================
233 // __sized_by on struct non-pointer members
234 //==============================================================================
237 // expected-error-re@+1{{'sized_by' only applies to pointers{{$}}}}
238 int wrong_ty
__sized_by(size
);
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
);