[Bug middle-end/58101] Wrong out-of-bounds warning under -Os

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Dec 23 06:36:57 GMT 2021


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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Further reduced:
int a [1];

void foo (int n)
{
   if (n <= 1) return;
   int i = 1;
   a [i] = a [i - 1];
}

This is one of these false positives warning where we should maybe not warn but
instead just change the code to be a trap.

Note in the original testcase, GCC is able to remove the loop and just change
it to one statement. That is part of the reason for the warning even.

clang does not warn about the above because they only warn for the literal a[1]
case.


More information about the Gcc-bugs mailing list