From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AD89A3858C53; Mon, 27 Mar 2023 12:59:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD89A3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679921977; bh=oLp+orffEItCbKZNq+7p1fnvL8u23i61/ymUGyTsThc=; h=From:To:Subject:Date:From; b=aOSRnRCX+Y7zrdO9CvJBsGPZ2jEI6+c3xO/Jr9q7KrQqcUrXnqrQJmMEsxWTRhJFD kNjj8Exvpmt+RHEUDSStYzc6bLYBR2ynrMGAuRnJdhl9qYL/3XQlb3jJ97dvb429sS nmw28GU0+8og86c/1U8zaC9gLZR1zcGZOWJcsO3E= From: "ubizjak at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyBjLzEwOTI5OF0gTmV3OiB3YXJuaW5nOiBhcnJheSBzdWJz?= =?UTF-8?B?Y3JpcHQg4oCYLi4u4oCZIGlzIHBhcnRseSBvdXRzaWRlIGFycmF5IGJvdW5k?= =?UTF-8?B?cyBvZiDigJguLi7igJk=?= Date: Mon, 27 Mar 2023 12:59:37 +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.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ubizjak at gmail 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=3D109298 Bug ID: 109298 Summary: warning: array subscript =E2=80=98...=E2=80=99 is partl= y outside array bounds of =E2=80=98...=E2=80=99 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ubizjak at gmail dot com Target Milestone: --- This warning/error is actually emitted when compiling drivers/infiniband/core/user_mad.c linux source file. The testcase: --cut here-- enum { IB_MGMT_RMPP_HDR =3D 36, IB_MGMT_RMPP_DATA =3D 220, }; struct ib_umad_packet { int hdr; unsigned char data[]; }; struct ib_rmpp_mad { int class; unsigned char data[IB_MGMT_RMPP_DATA]; }; int foo (const unsigned char *buf) { struct ib_umad_packet *packet; struct ib_rmpp_mad *rmpp_mad; packet =3D __builtin_malloc (sizeof *packet + IB_MGMT_RMPP_HDR); __builtin_memcpy (&packet->data, buf, IB_MGMT_RMPP_HDR); rmpp_mad =3D (struct ib_rmpp_mad *) packet->data; return rmpp_mad->class; } --cut here-- -O2 -Wall test.c: In function =E2=80=98foo=E2=80=99: test.c:27:18: warning: array subscript =E2=80=98struct ib_rmpp_mad[0]=E2=80= =99 is partly outside array bounds of =E2=80=98unsigned char[40]=E2=80=99 [-Warray-bounds= =3D] 27 | return rmpp_mad->class; | ^~ test.c:21:12: note: at offset 4 into object of size 40 allocated by =E2=80=98__builtin_malloc=E2=80=99 21 | packet =3D __builtin_malloc (sizeof *packet + IB_MGMT_RMPP_HDR); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Adding -fno-strict-aliasing to compile flags does not help.=