On 7/27/2021 2:45 PM, Martin Sebor via Gcc-patches wrote:
When mentioning the type of the accessed object -Warray-bounds
treats singleton objects as arrays of one element for simplicity.
But because the code doesn't distinguish between function and
object pointers, a warning for an out-of-bounds index into
a singleton function pointer object attempts to create an array
of one function.  Since arrays of functions are invalid,
the helper function the code calls fails with an error issued
to the user.

To avoid this the attached patch avoids this singleton-to-array
shortcut for function pointers.  Tested on x86_64-linux.

Martin


gcc-101601.diff

PR middle-end/101601 - [12 Regression] -Warray-bounds triggers error: arrays of 
functions are not meaningful

        PR middle-end/101601

gcc/ChangeLog:

        * gimple-array-bounds.cc (array_bounds_checker::check_mem_ref): Remove
        a pointless test.
        Handle pointers to functions.

gcc/testsuite/ChangeLog:

        * g++.dg/warn/Warray-bounds-25.C: New test.
        * gcc.dg/Warray-bounds-85.c: New test.
OK
jeff

Reply via email to