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

            Bug ID: 116481
           Summary: Compilation error caused by -Warray-bounds and -O2
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruno at clisp dot org
  Target Milestone: ---

Created attachment 58999
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58999&action=edit
test case foo.c

The attached program, foo.c, is valid code but fails to compile when gcc is
given the arguments -Warray-bounds and -O2:

$ gcc -O2 -S foo.c
$ gcc -Warray-bounds -O1 -S foo.c
$ gcc -Warray-bounds -O2 -S foo.c
foo.c: In function ‘is_trampoline’:
foo.c:3:5: error: arrays of functions are not meaningful
    3 | int is_trampoline (void* function)
      |     ^~~~~~~~~~~~~
foo.c:7:84: warning: array subscript 0 is outside array bounds of ‘int[1]’
[-Warray-bounds=]
    7 |   return ((long *) ((char*)function - 2))[0] == ((long *)
((char*)tramp_address-2))[0];
      |                                                
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
foo.c:1:13: note: at offset -2 into object ‘tramp’ of size [0, 2147483647]
    1 | extern void tramp ();
      |             ^~~~~

Seen with several versions of gcc:

$ gcc --version
gcc (Gentoo 14.2.1_p20240817 p4) 14.2.1 20240817

$ gcc --version
gcc (Debian 13.2.0-8) 13.2.0

$ gcc --version
gcc (GCC) 13.1.0

Reply via email to