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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2019-05-06
          Component|c++                         |middle-end
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=87072
     Ever confirmed|0                           |1

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
This looks very similar to bug 87072.  The C test case below is diagnosed by
GCC 9, 8, and 7.

$ cat a.c && gcc -O3 -S -Wall -Wextra -fdump-tree-vrp=/dev/stdout a.c
struct a {
  int b;
  unsigned c;
};

int f (struct a *p) { return p->b && p->c; }

struct d { };
void e (struct d*);

struct a j[1];

struct a g (struct d *h)
{
  for (unsigned i = 0; ; i++)
    for (; i; )
      if (f (&j[i]))
        e (h);
}

a.c: In function ‘g’:
a.c:17:16: warning: array subscript 1 is above array bounds of ‘struct a[1]’
[-Warray-bounds]
   17 |       if (f (&j[i]))
      |               ~^~~
a.c:17:16: warning: array subscript 1 is above array bounds of ‘struct a[1]’
[-Warray-bounds]
...
g (struct d * h)
{
  unsigned int i;
  int _7;
  unsigned int _10;

  <bb 2> [local count: 11811]:
  goto <bb 7>; [100.00%]

  <bb 3> [local count: 118111601]:
  _7 = MEM[(struct a *)&j][1].b;
  if (_7 != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 6>; [50.00%]

  <bb 4> [local count: 59055800]:
  _10 = MEM[(struct a *)&j][1].c;
  if (_10 != 0)
    goto <bb 5>; [50.00%]
  else
    goto <bb 6>; [50.00%]

  <bb 5> [local count: 29527900]:
  e (h_8(D));

  <bb 6> [local count: 118111601]:

  <bb 7> [local count: 118111600]:
  # i_4 = PHI <1(6), 0(2)>
  if (i_4 != 0)
    goto <bb 3>; [3.00%]
  else
    goto <bb 8>; [97.00%]

  <bb 8> [local count: 955630224]:
  goto <bb 3>; [100.00%]

}

Reply via email to