On 1/30/21 12:36 AM, Eric Gallager wrote:
On Thu, Jan 28, 2021 at 6:04 PM Martin Sebor via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
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
-Wstrict-aliasing is a warning with numerical levels; can you clarify
which of them this is active at?
It runs at the default level 3.
(also I have always found it confusing how -Wstrict-aliasing's
numerical levels are in reverse order from most other warnings with
numerical levels; i.e., how higher numbers supposedly mean fewer
warnings for it (according to documentation) rather than more, as is
the case with most other warnings with numerical levels)
The description does seem a little counter-intuitive. The warning
runs in the front ends and the analysis functions it calls at level
3 have the same complexity as at level 1 so I'm not sure I understand
the point of the levels. I'd be surprised if anyone used anything
but the default.
Martin