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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2019-11-03
   Target Milestone|---                         |10.0
     Ever confirmed|0                           |1

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning was enhanced in GCC 9.1 (r262893) to detect this bug, except that
due to my own oversight it doesn't handle the PARAM_DECL case.  It's trivial to
add it.  Let me take care of it for GCC 10.0.

$ cat pr82612.c && gcc -O2 -S -Wall pr82612.c
int i;
int f0 (void)
{ 
  int *p = &i;
  return p[2];   // -Warray-bounds (good)
}

int f1 (void)
{
  int i;
  int *p = &i;
  return p[2];   // -Warray-bounds (good)
}

int f2 (int i)
{
  int *p = &i;
  return p[2];   // missing -Warray-bounds
}
pr82612.c: In function ‘f0’:
pr82612.c:5:11: warning: array subscript 2 is outside array bounds of ‘int[1]’
[-Warray-bounds]
    5 |   return p[2];   // -Warray-bounds (good)
      |          ~^~~
pr82612.c:1:5: note: while referencing ‘i’
    1 | int i;
      |     ^
pr82612.c: In function ‘f1’:
pr82612.c:12:11: warning: array subscript 2 is outside array bounds of ‘int[1]’
[-Warray-bounds]
   12 |   return p[2];   // -Warray-bounds (good)
      |          ~^~~
pr82612.c:10:7: note: while referencing ‘i’
   10 |   int i;
      |       ^

Reply via email to