From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 48A50384AB65; Tue, 23 Apr 2024 15:45:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48A50384AB65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713887106; bh=CE3yEm4c9CuDKpPXTxrx1QyAjaBAZAEDFIPXkxPwOrE=; h=From:To:Subject:Date:From; b=dKdIkYEoHNthXMJsajEYu1+K5BjzPdDbq87+dzTLPB4Bpbd72kJIw968oqFyLXozO x5OQK5bgJGqrdW8bhLdrUCLk+LklnQbgOtRTQ/zrZnS95aZ9hPkPrjTihVMwFIKxIq XWb9TgJ4/oOrVS1Ve3T0m6z/Bs/FK+8vIhAatyUE= From: "adam at adamrosenfield dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114826] New: Bogus -Warray-bounds warning for 32-byte array with certain march flags Date: Tue, 23 Apr 2024 15:45:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: adam at adamrosenfield dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114826 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: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D snip =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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] =3D {0}; char src[32] =3D {0}; memcpy(dest, src, 32); char expected[32] =3D {0}; return memcmp(expected, dest, 32); } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D snip =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Compile as: gcc -c test.c -Wall -march=3Dhaswell -O3 Output: test.c: In function =E2=80=98foo=E2=80=99: test.c:9:10: warning: array subscript =E2=80=98[0]=E2= =80=99 is partly outside array bounds of =E2=80=98char[2]=E2=80=99 [-Warray-bounds=3D] 9 | char src[32] =3D {0}; | ^~~ This warning is clearly bogus, as there is no array of size 256 or size 2 h= ere, 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 tr= ied do not trigger this. This occurs with various different -march flags, including haswell, broadwe= ll, skylake, knl, knm, and many more of the *lake arches; it does not occur with ivybridge and earlier.=