[Bug tree-optimization/105684] Bogus `-Warray-bounds` in partially allocated struct

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon May 23 07:03:09 GMT 2022


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |56456

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is that 'result->data0.a' is (*result).data0.a, and so to GCC you are
accessing an object of type 'obj' for which there isn't enough allocated space.

Now - I think the array bound diagnostic could be improved to better highlight
this.

A workaround might be to declare 'obj' as

struct obj {
        unsigned long long kind;
        unsigned long long data[];
};

if in your case all data is really uniform 'unsigned long long'.  There's
no way to union several different typed flexarrays though.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds


More information about the Gcc-bugs mailing list