[PATCH] adjust "partly out of bounds" warning (PR 98503)

Martin Sebor msebor@gmail.com
Thu Jan 28 23:03:51 GMT 2021


The GCC 11 -Warray-bounds enhancement to diagnose accesses whose
leading offset is in bounds but whose trailing offset is not has
been causing some confusion.  When the warning is issued for
an access to an in-bounds member via a pointer to a struct that's
larger than the pointed-to object, phrasing this strictly invalid
access in terms of array subscripts can be misleading, especially
when the source code doesn't involve any arrays or indexing.

Since the problem boils down to an aliasing violation much more
so than an actual out-of-bounds access, the attached patch adjusts
the code to issue a -Wstrict-aliasing warning in these cases instead
of -Warray-bounds.  In addition, since the aliasing assumptions in
GCC can be disabled by -fno-strict-aliasing, the patch also makes
these instances of the warning conditional on -fstrict-aliasing
being in effect.

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-98503.diff
Type: text/x-patch
Size: 23655 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210128/c32a7bbc/attachment.bin>


More information about the Gcc-patches mailing list