provide "element_count" attribute to give more context to __builtin_dynamic_object_size() and -fsanitize=bounds #60928
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
Frequently a structure containing a flexible array member will also contain a member where the count of array elements is stored. For example:
While
__builtin_dynamic_object_size(p->data, 1)
will know the size withinallocate_foo()
due tomalloc
's__alloc_size
hinting, this information is immediately lost on return. However, the information is still available inp->count
, but the compiler has no way to know about it.Please provide a struct member attribute
element_count
that can be used to associate the size of a flexible array to another struct member. For example:Now any later examination of the size of
data
can be calculated. For example, this equality will hold true:and
-fsanitize-bounds
can examine this as well, to trap:The text was updated successfully, but these errors were encountered: