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

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
A simpler test case is this (which is analogous to what the loop is transformed
into):

$ cat x.c && gcc -O2 -S -Wall x.c
  unsigned left[1];
  unsigned long right[1];

  void f (unsigned i)
  {
    if (i)
      left[i] = right[i - 1];
  }

x.c: In function ‘f’:
x.c:7:11: warning: array subscript [0, 0] is outside array bounds of ‘unsigned
int[1]’ [-Warray-bounds]
       left[i] = right[i - 1];
       ~~~~^~~

Here it's even more obvious that the warning is wrong.

It seems to me that the whole if statement could either be eliminated or its
body replaced by a trap because the assignment in it is undefined.  That would
eliminate the loop (and with it also the warning).

Reply via email to