From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8462B3857C62; Wed, 2 Sep 2020 16:50:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8462B3857C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1599065441; bh=c6oFSLCe8eo3ZZOG21aCt+dKvqTnpv7glKgqtXUJCE0=; h=From:To:Subject:Date:From; b=EtyK+zehJ6Y00sJ/s6VKSd7D2cBektu+ikvwpX1JoyoZBef32+455YPtSqIL6fDyR bEToVGDUIWfBpiCVIdKfLvFiU0Ugdxs49FZLnF0dMI+x185f+Rntuju5pgeTJVyN47 2lhjojejd3/Tz2Q+evbsKJWS+hVD4knaqnGSuc5w= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/96900] New: bogus -Warray-bounds on strlen with valid pointer obtained from just-past-the-end Date: Wed, 02 Sep 2020 16:50:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Sep 2020 16:50:41 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96900 Bug ID: 96900 Summary: bogus -Warray-bounds on strlen with valid pointer obtained from just-past-the-end Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- When a valid pointer into an array that has been derived from a past-the-end pointer to a member array of an initialized constant struct is used in a ca= ll to a string built-in like strlen GCC issues a bogus -Warray-bounds warning indicating that the offset into the array is out of its bounds. $ cat q.c && gcc -S -Wall q.c struct S { char n, a[3]; }; const char a[3] =3D { 2, 1, 0 }; const struct S s =3D { 3, { 2, 1, 0 } }; int f (void) { const char *p =3D &a[sizeof a]; return __builtin_strlen (p - sizeof a); // no warning (good) } int g (void) { const char *p =3D &s.a[sizeof s.a]; return __builtin_strlen (p - sizeof s.a); // bogus -Warray-bounds } q.c: In function =E2=80=98g=E2=80=99: q.c:15:10: warning: offset =E2=80=981=E2=80=99 outside bounds of constant s= tring [-Warray-bounds] 15 | return __builtin_strlen (p - sizeof s.a); // bogus -Warray-bou= nds | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ q.c:4:16: note: =E2=80=98s=E2=80=99 declared here 4 | const struct S s =3D { 3, { 2, 1, 0 } }; | ^=