https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119070
Bug ID: 119070 Summary: gcc15 incorrectly reporting negative array-bounds errors Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: taylor.hutt at broadcom dot com Target Milestone: --- The code in 'cit.c' has been extracted from a production audio driver present in widely used virtualization products. The code has not been meaningfully changed in many years. The gcc version banner is: x86_64-vmw-linux-gnu-gcc (crosstool-NG 1.26.0.127_1c395b2) 15.0.1 20250227 (experimental) Copyright (C) 2025 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. The code was checked out using crosstool-ng at the top of the 'master' branch on the day of the build. The script 'citi' (with modifications to produce a path to gcc15) will reproduce the errors. The errors are as follows: /tmp/gcc15/cit.c: In function 'function_1': /tmp/gcc15/cit.c:27:19: error: array subscript -227 is outside array bounds of 'struct_2[1]' [-Werror=array-bounds=] 27 | unsigned char *v3 = v2 - 0x2000; | ^~ /tmp/gcc15/cit.c:16:17: note: at offset -8192 into object 'global_0' of size 36 16 | extern struct_2 global_0; | ^~~~~~~~ /tmp/gcc15/cit.c:27:19: error: array subscript -227 is outside array bounds of 'struct_2[1]' [-Werror=array-bounds=] 27 | unsigned char *v3 = v2 - 0x2000; | ^~ /tmp/gcc15/cit.c:16:17: note: at offset -8192 into object 'global_0' of size 36 16 | extern struct_2 global_0; | ^~~~~~~~ /tmp/gcc15/cit.c:27:19: error: array subscript -227 is outside array bounds of 'struct_2[1]' [-Werror=array-bounds=] 27 | unsigned char *v3 = v2 - 0x2000; | ^~ /tmp/gcc15/cit.c:16:17: note: at offset -8192 into object 'global_0' of size 36 16 | extern struct_2 global_0; | ^~~~~~~~ cc1: all warnings being treated as errors I find, using https://godbolt.org/, that the regression was introduced in gcc10. The code compiles without issue with gcc9.