[Bug tree-optimization/82608] New: missing -Warray-bounds on an out-of-bounds VLA index

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Oct 18 17:11:00 GMT 2017


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

            Bug ID: 82608
           Summary: missing -Warray-bounds on an out-of-bounds VLA index
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC doesn't diagnose out-of-bounds indices into VLAs even in cases where it
could.  For instance, in the program below the upper bound of the VLA is at
most 32 while the index is greater.  This information is available in the VRP
pass and so it should be possible to detect this bug.

$ cat a.c && gcc -O2 -S -Wall -Warray-bounds -Wextra a.c
void sink (void*);

int f (unsigned n)
{
  if (n < 1 || n > 32)
    n = 32;

  char vla[n];

  sink (vla);

  return vla[97];   // missing -Warray-bounds
}


More information about the Gcc-bugs mailing list