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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |10.0
         Resolution|---                         |FIXED
             Blocks|                            |56456
             Status|NEW                         |RESOLVED

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
For the slightly modified test case GCC 10 issues the expected warnings in the
expected cases (i.e., unless the code is removed as unused, etc.)  So I think
this can be resolved as fixed.  (There are plenty of other cases that still
aren't diagnosed; please open new bugs for those if they aren't already being
tracked under pr56456).

$ cat pr81172.c && gcc -O2 -S -Wall pr81172.c

int a[] = {1,2,3,4};

int* f (void)
{
  int *p = a + 5;
  return p;
}

const char s[] = "aaa", t[] = "bbbbb";

const char* g (void)
{
  const char *p = s + __builtin_strlen (t);
  return p;
}

const char* h (void)
{
  return s + 'c';
}
pr81172.c: In function ‘f’:
pr81172.c:5:8: warning: array subscript 5 is outside array bounds of ‘int[4]’
[-Warray-bounds]
    5 |   int *p = a + 5;
      |        ^
pr81172.c:1:5: note: while referencing ‘a’
    1 | int a[] = {1,2,3,4};
      |     ^
pr81172.c: In function ‘g’:
pr81172.c:13:15: warning: array subscript 5 is outside array bounds of ‘const
char[4]’ [-Warray-bounds]
   13 |   const char *p = s + __builtin_strlen (t);
      |               ^
pr81172.c:9:12: note: while referencing ‘s’
    9 | const char s[] = "aaa", t[] = "bbbbb";
      |            ^
pr81172.c: In function ‘h’:
pr81172.c:19:12: warning: array subscript 99 is outside array bounds of ‘const
char[4]’ [-Warray-bounds]
   19 |   return s + 'c';
      |          ~~^~~~~
pr81172.c:9:12: note: while referencing ‘s’
    9 | const char s[] = "aaa", t[] = "bbbbb";
      |            ^


Referenced Bugs:

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

Reply via email to