[Bug tree-optimization/84051] [7/8/9 Regression] missing -Warray-bounds on an out-of-bounds access via an array pointer

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Dec 20 16:51:00 GMT 2018


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

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
I see GCC warns for this case with -Warray-bounds=2 and it's being tested in
gcc.dg/Warray-bounds-11.c.

I think it would make sense to warn on the pointer to array case even at level
1.  It seems quite unlikely for a pointer to an array of a known bound to be
set to point to a larger array and used to access elements beyond that bound.

Separately, I also wonder if it would make sense to warn for out-of-bounds
accesses to trailing arrays with more than 1 element.  Those too seem unlikely,
and the recommendation is to use either flexible array members or zero-length
arrays for such things.

By warning on these cases GCC would help detect more bugs and encourage working
code to migrate to the recommended solutions.

Perhaps for GCC 10.


More information about the Gcc-bugs mailing list