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

            Bug ID: 97261
           Summary: gcc-10 produces invalid -Warray-bounds warning
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gccbugs at dima dot secretsauce.net
  Target Milestone: ---

Hi. I'm seeing gcc-10 flag a warning that I'm pretty sure is incorrect. gcc-9
and older did not warn about this (although that's probably because they
weren't looking for these kinds of problems).

Recipe:

1. save the attached as tst.c

2. gcc-10 -Wall -Wextra -Wno-unused-variable -fPIC -O3 -c -o tst.o tst.c

I see this:



tst.c: In function 'f':
tst.c:21:17: warning: array subscript -1 is outside array bounds of 'double[1]'
[-Warray-bounds]
   21 |     const ab_t* ab = (ab_t*)(pb - 1);
      |                 ^~
tst.c:16:13: note: while referencing 'b'
   16 |     double  b  = 4.;
      |             ^



I believe this is false. Inside g(), ab->a is indeed out-of-bounds, but ab->b
is not. And I only use ab->b. Taking away -fPIC or -O3 makes the warning go
away. Making g() static makes it go away also.

I'm using gcc-10 from Debian. Package version 10.1.0-5.

Thanks!

Reply via email to