[Bug middle-end/92936] New: missing warning on a past-the-end store to a PHI

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Dec 13 23:06:00 GMT 2019


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

            Bug ID: 92936
           Summary: missing warning on a past-the-end store to a PHI
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Out of bounds stores to destinations that are the results of conditionals like
the one in g() below are not diagnosed.  They should be both by -Warray-bounds
and by -Wstringop-overflow (without duplicates) but they're not because PHI
expressions aren't handled.

$ cat b.c && gcc -O2 -S -Wall b.c
void sink (void*);

void f (int n)
{
  char a3[3], a5[5], *p;

  if (n <= 3)
    {
      n = 3;
      p = a3;
      p[n] = 0;   // -Warray-bounds
    }
  else
    {
      n = 5;
      p = a5;
      p[n] = 0;   // -Warray-bounds
    }

  sink (p);
}

void g (int n)
{
  char a3[3], a5[5], *p;

  if (n <= 3)
    {
      n = 3;
      p = a3;
    }
  else
    {
      n = 5;
      p = a5;
    }

  p[n] = 0;       // missing warning
  p[n + 1] = 1;   // missing warning
  p[n + 9] = 2;   // missing warning
  p[12345] = 3;   // missing warning

  sink (p);
}

b.c: In function ‘f’:
b.c:17:8: warning: array subscript 5 is outside array bounds of ‘char[5]’
[-Warray-bounds]
   17 |       p[n] = 0;   // -Warray-bounds
      |       ~^~~
b.c:5:15: note: while referencing ‘a5’
    5 |   char a3[3], a5[5], *p;
      |               ^~
b.c:11:8: warning: array subscript 3 is outside array bounds of ‘char[3]’
[-Warray-bounds]
   11 |       p[n] = 0;   // -Warray-bounds
      |       ~^~~
b.c:5:8: note: while referencing ‘a3’
    5 |   char a3[3], a5[5], *p;
      |        ^~


More information about the Gcc-bugs mailing list