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

            Bug ID: 86972
           Summary: Incorrect array-bounds warning with -O2 when creating
                    pointer from array
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aes368 at cornell dot edu
  Target Milestone: ---

int *p;

int main() {
  int a[1];
  p = a - 1;
}

The above code raises the warning:

warning: array subscript -1 is below array bounds of ‘int [1]’ [-Warray-bounds]
   p = a - 1;
       ~~^~~

when compiled with

gcc -O2 -Wall

I see this both on 7.3.0 and 8.2.0.

The subscript detected seems to always be the term added to a, though it does
not raise a warning with 0 or +1.

Reply via email to