[Bug middle-end/101836] __builtin_object_size(P->M, 1) where M is an array and the last member of a struct fails
qinzhao at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jun 8 14:09:50 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836
--- Comment #12 from qinzhao at gcc dot gnu.org ---
In the current tree-object-size.cc, "addr_object_size", it's clearly state the
following:
607 /* For &X->fld, compute object size only if fld isn't the
last
608 field, as struct { int i; char c[1]; } is often used
instead
609 of flexible array member. */
and these part of codes were added back to 2009 with commit
eb9ed98a951531f7fc40c69883b3285d58b168b2.
it's reasonable to add a new option -fstrict-flex-arrays to remove the
"trailing array is a flex array" assumptions in current GCC.
and the following utility routine that is added in tree.[h|cc] in 2020 can be
used to identify whether a trailing array member reference is a flexible array
or not:
/* Describes a "special" array member due to which component_ref_size
returns null. */
enum struct special_array_member
{
none, /* Not a special array member. */
int_0, /* Interior array member with size zero. */
trail_0, /* Trailing array member with size zero. */
trail_1 /* Trailing array member with one element. */
};
/* Determines the size of the member referenced by the COMPONENT_REF
REF, using its initializer expression if necessary in order to
determine the size of an initialized flexible array member.
If non-null, set *ARK when REF refers to an interior zero-length
array or a trailing one-element array.
Returns the size as sizetype (which might be zero for an object
with an uninitialized flexible array member) or null if the size
cannot be determined. */
tree
component_ref_size (tree ref, special_array_member *sam /* = NULL */)
More information about the Gcc-bugs
mailing list