You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Bounds-Safety] restrict sized_by for types w/o size unless incomplete
Emit an error when sized_by or sized_by_or_null is used on sizeless
types, function pointers and pointers to structs with flexible array
members. Although we *could* track their size, it is not useful and
indexing would not work.
// 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}}
51
52
void (*fn_ptr)(void) __sized_by(size);
52
53
intsize;
53
54
};
54
55
55
56
structon_member_pointer_fn_ptr_ty_ty {
56
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}}
57
59
fn_ptr_tyfn_ptr__sized_by(size);
58
60
intsize;
59
61
};
@@ -64,6 +66,7 @@ struct has_unannotated_vla {
64
66
};
65
67
66
68
structon_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}}
// 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}}
// expected-error@+1{{'sized_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'fn_ty' (aka 'void (int)') is a function type}}
// buffer of function(s) with size `size` is allowed
51
+
// expected-error@+1{{'sized_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
51
52
void (*fn_ptr)(void) __sized_by_or_null(size);
52
53
intsize;
53
54
};
54
55
55
56
structon_member_pointer_fn_ptr_ty_ty {
56
57
// buffer of function(s) with size `size` is allowed
58
+
// expected-error@+1{{'sized_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
57
59
fn_ptr_tyfn_ptr__sized_by_or_null(size);
58
60
intsize;
59
61
};
@@ -64,6 +66,7 @@ struct has_unannotated_vla {
64
66
};
65
67
66
68
structon_member_pointer_struct_with_vla {
69
+
// expected-error@+1{{'sized_by_or_null' 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}}
// expected-error@+1{{'sized_by_or_null' 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}}
// buffer of functions with size `size` is allowed
52
+
// expected-error@+1{{'sized_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
52
53
void (*fn_ptr)(void) __sized_by_or_null(size);
53
54
};
54
55
55
56
structon_member_pointer_fn_ptr_ty_ty {
56
57
intsize;
57
58
// buffer of functions with size `size` is allowed
59
+
// expected-error@+1{{'sized_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
58
60
fn_ptr_tyfn_ptr__sized_by_or_null(size);
59
61
};
60
62
@@ -66,6 +68,7 @@ struct has_unannotated_vla {
66
68
structon_member_pointer_struct_with_vla {
67
69
intsize;
68
70
// we know the size so this is fine for tracking size, however indexing would be an issue
71
+
// expected-error@+1{{'sized_by_or_null' 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}}
// we know the size so this is fine for tracking size, however indexing would be an issue
83
+
// expected-error@+1{{'sized_by_or_null' 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}}
// expected-error@+1{{'sized_by_or_null' 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}}
// expected-error@+1{{'sized_by_or_null' 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}}
// buffer of functions with size `size` is allowed
52
+
// expected-error@+1{{'sized_by' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
52
53
void (*fn_ptr)(void) __sized_by(size);
53
54
};
54
55
55
56
structon_member_pointer_fn_ptr_ty_ty {
56
57
intsize;
57
58
// buffer of functions with size `size` is allowed
59
+
// expected-error@+1{{'sized_by' cannot be applied to a pointer with pointee of unknown size because 'void (void)' is a function type}}
58
60
fn_ptr_tyfn_ptr__sized_by(size);
59
61
};
60
62
@@ -66,6 +68,7 @@ struct has_unannotated_vla {
66
68
structon_member_pointer_struct_with_vla {
67
69
intsize;
68
70
// we know the size so this is fine for tracking size, however indexing would be an issue
71
+
// 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}}
// we know the size so this is fine for tracking size, however indexing would be an issue
83
+
// 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}}
// 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}}
// 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}}
0 commit comments