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

            Bug ID: 95635
           Summary: -Warray-bounds falsely claims out-of-bounds access
           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: ---

Created attachment 48716
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48716&action=edit
Bug demo

Hi. I'm running gcc-10 from Debian:

  dima@shorty:~$ gcc-10 --version
  gcc-10 (Debian 10.1.0-3) 10.1.0

I'm building the attached source like this:

  gcc-10 -Warray-bounds -O2 -c -o /dev/null tst.c

And I get this:

tst.c: In function 'a':
tst.c:12:27: warning: array subscript <unknown> is outside array bounds of
'int[0]' [-Warray-bounds]
   12 |         if(L[i] > 0 && arr[L[i]] )
      |                        ~~~^~~~~~
tst.c:8:9: note: while referencing 'arr'
    8 |     int arr[0];
      |         ^~~
tst.c:12:27: warning: array subscript <unknown> is outside array bounds of
'int[0]' [-Warray-bounds]
   12 |         if(L[i] > 0 && arr[L[i]] )
      |                        ~~~^~~~~~
tst.c:8:9: note: while referencing 'arr'
    8 |     int arr[0];


The array arr[] has 0 elements, and gcc is telling me I'm accessing outside of
those bounds. But L[i]>0 is always false, so we'll never actually look at
arr[anything]. gcc knows this most of the time. If I remove the -O2 or the b()
call or lots of little unrelated-looking things, the issue goes away. Thanks.

Reply via email to