From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BE0613854551; Fri, 18 Nov 2022 21:19:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE0613854551 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668806390; bh=G7Q6fpz8cE73iIh0CQy5sR5ykLJv72M0DUREyaPxHis=; h=From:To:Subject:Date:From; b=YObFMpBXs4pVwbAr/6n4F5+90+LsmHwMBJM/7gV9qkdmONyhotsDVV4jkvfwsI4yC ZyNR10s/QOJN2XSJNes0+hxhrwPm9DvTc18qu8L83gc3rRNA08/hi1FEttHA8+wyh1 YN8dq8CmVqCLfpQ8PUGDPKE7FBmeT1vj9HjL7zqo= From: "nightstrike at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107754] New: Confusing -Warray-bounds warning with strcpy Date: Fri, 18 Nov 2022 21:19:50 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nightstrike 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=3D107754 Bug ID: 107754 Summary: Confusing -Warray-bounds warning with strcpy Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: nightstrike at gmail dot com Target Milestone: --- Metabug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3Dwarray-bounds // Compile with GCC 12.2.0 with -O2: // warning: =E2=80=98strcpy=E2=80=99 offset 0 is out of the bounds [0, 0= ] [-Warray-bounds] // no warning without -O2 struct Inst; struct Class { int offset; }; static struct Class * classFoo; // No problem without static here struct Foo { unsigned int a; // no problem if commented out char bar[1024]; }; void setFoo(struct Inst * this, const char * value) { struct Foo * ptr =3D (struct Foo *)(this ? (((char *)this) + classFoo->o= ffset) : 0); __builtin_strcpy(ptr->bar, value); } $ gcc-12 -c -O2 -Warray-bounds a.c -o /dev/null a.c: In function 'setFoo': a.c:19:4: warning: '__builtin_strcpy' offset 0 is out of the bounds [0, 0] [-Warray-bounds] 19 | __builtin_strcpy(ptr->bar, value); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=