public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/115005] New: [gcc-13] bogus -Warray-bounds warning
@ 2024-05-09 10:10 sezeroz at gmail dot com
  2024-05-09 10:17 ` [Bug c/115005] " sezeroz at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: sezeroz at gmail dot com @ 2024-05-09 10:10 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-09 23:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-09 10:10 [Bug c/115005] New: [gcc-13] bogus -Warray-bounds warning sezeroz at gmail dot com
2024-05-09 10:17 ` [Bug c/115005] " sezeroz at gmail dot com
2024-05-09 16:29 ` [Bug tree-optimization/115005] " pinskia at gcc dot gnu.org
2024-05-09 17:33 ` sezeroz at gmail dot com
2024-05-09 23:02 ` sezeroz at gmail dot com
2024-05-09 23:03 ` sezeroz at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).