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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
     Ever confirmed|0                           |1
          Component|c++                         |tree-optimization
      Known to fail|                            |10.2.0, 11.0, 7.3.0, 8.3.0,
                   |                            |9.2.0
                 CC|                            |msebor at gcc dot gnu.org
   Last reconfirmed|                            |2021-03-14
             Blocks|                            |56456
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed.  The warning first appeared with r238761 AKA "Teach VRP to register
assertions along default switch labels (PR18046)."

A simplified test case is below:

$ cat pr99580.C && -O2 -S -Wall -fdump-tree-vrp1-details pr99580.C
struct vec
{
  int operator[] (int i)
  {
    switch (i) {
    default:
    case 0: return x;
    case 1: return y;
    case 2: return z;
    }
  }

  int x, y, z;
};

vec v[3];

int f ()
{
  int max_el = v[0][1];
  int max_j = 1;

  for (int i = 0; i < 3; i++)
    for (int j = i + 1; j < 3; j++)
      if (v[i][j] > max_el)
        max_j = j;

  return v[max_j][max_j];
}
pr99580.C: In function ‘int f()’:
pr99580.C:28:17: warning: array subscript 3 is above array bounds of ‘vec [3]’
[-Warray-bounds]
   28 |   return v[max_j][max_j];
      |          ~~~~~~~^
pr99580.C:16:5: note: while referencing ‘v’
   16 | vec v[3];
      |     ^

$ grep warning pr99580.C.110t.vrp1 
Array bound warning for MEM <struct vec[3]> [(struct vec *)&v][max_j_27]

And:

Simulating block 14

extract_range_from_stmt visiting:
max_j_27 = ASSERT_EXPR <max_j_21, (unsigned int) max_j_21 + 4294967295 > 1>;
Intersecting
  int ~[1, 2]  EQUIVALENCES: { max_j_21 } (1 elements)
and
  int [1, 2147483646]
to
  int [3, 2147483646]  EQUIVALENCES: { max_j_21 } (1 elements)
Intersecting
  int [3, 2147483646]  EQUIVALENCES: { max_j_21 } (1 elements)
and
  int VARYING
to
  int [3, 2147483646]  EQUIVALENCES: { max_j_21 } (1 elements)
Found new range for max_j_27: int [3, 2147483646]  EQUIVALENCES: { } (0
elements)
Adding destination of edge (14 -> 17) to worklist


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56456
[Bug 56456] [meta-bug] bogus/missing -Warray-bounds

Reply via email to