public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114826] New: Bogus -Warray-bounds warning for 32-byte array with certain march flags
@ 2024-04-23 15:45 adam at adamrosenfield dot com
  2024-04-23 15:48 ` [Bug tree-optimization/114826] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: adam at adamrosenfield dot com @ 2024-04-23 15:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114826
           Summary: Bogus -Warray-bounds warning for 32-byte array with
                    certain march flags
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adam at adamrosenfield dot com
  Target Milestone: ---

Sample code:

================== snip ==================
typedef long unsigned int size_t;
extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
       size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__
((__nonnull__ (1, 2)));
extern int memcmp (const void *__s1, const void *__s2, size_t __n)
     __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__))
__attribute__ ((__nonnull__ (1, 2)));

int foo() {
    char dest[32] = {0};
    char src[32] = {0};

    memcpy(dest, src, 32);

    char expected[32] = {0};

    return memcmp(expected, dest, 32);
}
================== snip ==================

Compile as:

gcc -c test.c -Wall -march=haswell -O3

Output:

test.c: In function ‘foo’:
test.c:9:10: warning: array subscript ‘<unnamed-unsigned:256>[0]’ is partly
outside array bounds of ‘char[2]’ [-Warray-bounds=]
    9 |     char src[32] = {0};
      |          ^~~

This warning is clearly bogus, as there is no array of size 256 or size 2 here,
and there's no subscripting going on in this array declaration.

This occurs in GCC 13.2.0 and 13.1.0, but does not occur in GCC 12.x and
earlier.

This only occurs if the array size is exactly 32; other array sizes I've tried
do not trigger this.

This occurs with various different -march flags, including haswell, broadwell,
skylake, knl, knm, and many more of the *lake arches; it does not occur with
ivybridge and earlier.

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

end of thread, other threads:[~2024-05-13 11:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23 15:45 [Bug c/114826] New: Bogus -Warray-bounds warning for 32-byte array with certain march flags adam at adamrosenfield dot com
2024-04-23 15:48 ` [Bug tree-optimization/114826] " pinskia at gcc dot gnu.org
2024-04-23 15:58 ` rguenth at gcc dot gnu.org
2024-04-23 17:35 ` [Bug tree-optimization/114826] [13 Regression] " pinskia at gcc dot gnu.org
2024-04-23 17:36 ` pinskia at gcc dot gnu.org
2024-05-13 11:27 ` rguenth at gcc dot gnu.org

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).