[Bug tree-optimization/126975] __bos/__bdos(&p->inner, 1) collapses into type 0 when subobject inner ends in a FAM

gustavo at embeddedor dot com gcc-bugzilla@gcc.gnu.org
Sat Sep 5 06:46:53 GMT 2026


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126975

--- Comment #8 from Gustavo A. R. Silva <gustavo at embeddedor dot com> ---
I submitted v2 for this patch:

https://gcc.gnu.org/pipermail/gcc-patches/2026-September/729904.html

The fix now applies under -fstrict-flex-arrays=3 only.

(I personally think it should apply unconditionally, but it's fine to be
conservative in this case, as the Linux kernel is built under
-fstrict-flex-arrays=3 as well.)

So, considering:

struct flex {
  size_t count;
  char fam[];
};                    /* sizeof(struct flex) == 8  */

struct outer {
  int hdr;
  struct flex inner;
};

struct outer *p = __builtin_malloc (sizeof (*p) + 48); /* 64-byte object */

See below for a comparison of v2 vs unpatched trunk for
__builtin_object_size/__builtin_dynamic_object_size(&p->inner, 1) across
-fstrict-flex-arrays levels:

-fstrict-flex-arrays=   v2    Unpatched    Effect
---------------------   --    ---------    ------
default (0)/1/2         56       56        Unchanged (type-1 size == type-0
size)
     3                   8       56        Fix fires (measures the subobject)

Thanks :)


More information about the Gcc-bugs mailing list