https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115005
Bug ID: 115005 Summary: [gcc-13] bogus -Warray-bounds warning Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: sezeroz at gmail dot com Target Milestone: --- Created attachment 58144 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58144&action=edit reduced C source exhibiting the issue The attached C source emits bogus -Warray-bounds warnings at -O2 and -O3 (tested on i686 and x86_64): $ gcc13 -c -O2 -Wall mmcmp-small.c In function 'block_unpack_8bit', inlined from 'decrunch_mmcmp' at mmcmp-small.c:231:4: mmcmp-small.c:155:35: warning: array subscript 4294967295 is above array bounds of 'const uint32[8]' {aka 'const unsigned int[8]'} [-Warray-bounds=] 155 | if (d >= cmd_8bits[numbits]) { | ~~~~~~~~~^~~~~~~~~ mmcmp-small.c: In function 'decrunch_mmcmp': mmcmp-small.c:39:21: note: while referencing 'cmd_8bits' 39 | extern const uint32 cmd_8bits[8]; | ^~~~~~~~~ In function 'block_unpack_16bit', inlined from 'decrunch_mmcmp' at mmcmp-small.c:229:4: mmcmp-small.c:90:35: warning: array subscript 4294967295 is above array bounds of 'const uint32[16]' {aka 'const unsigned int[16]'} [-Warray-bounds=] 90 | if (d >= cmd_16bit[numbits]) { | ~~~~~~~~~^~~~~~~~~ mmcmp-small.c: In function 'decrunch_mmcmp': mmcmp-small.c:41:21: note: while referencing 'cmd_16bit' 41 | extern const uint32 cmd_16bit[16]; | ^~~~~~~~~ The original file in question is at https://github.com/libxmp/libxmp/blob/master/src/depackers/mmcmp.c I removed as much clutter as I could, but you guys would most probably reduce it more. The issue was originally discussed at libxmp: https://github.com/libxmp/libxmp/issues/667 Notes particularly at https://github.com/libxmp/libxmp/issues/667#issuecomment-1712584590 The warnings go away if numbits is changed from uint32 to uint8 or uint16: We had changed it to uint8 as a solution.