https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35587
John Levon <levon at movementarian dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |levon at movementarian dot org
--- Comment #10 from John Levon <levon at movementarian dot org> ---
This is such a pain because of -faggressive-loop-optimizations. Here's a
salient example courtesy of bcantrill:
#define NULL ((void *)0)
static char *arr[2] = { "nasal", "demons" };
long
func()
{
int i;
for (i = 0; i <= 2; i++) {
if (arr[i] == NULL && i == 0)
return (0xbad);
}
return (0xfad);
}
Obviously, the index past the array bounds is undefined behaviour, but GCC
compiling this down to just "return (0xbad)" as it does is not very helpful.
But what's *really* not helpful is that -Warray-bounds=2 can't report on this.
(As per #78678, --fsanitize=object-size does enable detection of this. I'm not
clear if implementation-wise that's the only way to get this reported.)