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.

Reply via email to