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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
A simplified test case:

$ cat t.c && gcc -O3 -S -Wall t.c
int a[10];

void f (unsigned n)
{
  for (unsigned j = 0; j < n; j++) {
     for (unsigned k = 0; k < j; k++)
        a[j] += k;
     a[j] += j;
  }
}
t.c: In function ‘f’:
t.c:7:14: warning: array subscript is above array bounds [-Warray-bounds]
         a[j] += k;
         ~~~~~^~~~

The VRP dump shows the out-of-bounds index:

  if (j_16 == 10)
    goto <bb 22>; [85.00%]
  else
    goto <bb 4>; [15.00%]

  <bb 22> [3.00%]:
  _95 = _44 + 45;
  _96 = (int) _95;
  a[10] = _96;               <<<
  goto <bb 4>; [100.00%]

  <bb 23> [2.65%]:
  return;
}

Reply via email to