From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4A5C13857C63; Thu, 3 Sep 2020 23:37:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A5C13857C63 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1599176225; bh=ruAy4z6k1k3hTfhu12a7L0zabQmYuYjpGFfdQ6Gobqw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VFCdWbz9anMKPmOnBdOKSp/daa8DhmayoPzZLvGQ5BhBs5LHH+WvL7Q4Na78VWjA5 LGuepkW6UGeChcVo9k9yh7kcwgElKp7+sWUGXLBou4ElAG3LdXIe9wkMZ6NEaEYJrm Wz/MRE0FTxzPQIdMDdasca4kvPUqzOBhrc6Hpmo0= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/96900] [9/10/11 Regression] bogus -Warray-bounds on strlen with valid pointer obtained from just-past-the-end Date: Thu, 03 Sep 2020 23:37:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: diagnostic, missed-optimization 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: 9.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: keywords Message-ID: In-Reply-To: References: 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: Thu, 03 Sep 2020 23:37:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96900 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization --- Comment #3 from Martin Sebor --- This is also a missed optimization opportunity. Another test case that sho= ws both the bogus warning and the suboptimal codegen is the following. Because there is no explicit initializer for a.b, fold_nonarray_ctor_reference() returns a scalar zero, which again triggers the warning and prevents the st= rlen call from being folded. The optimization never worked in this case so that part is not a regression. $ cat z.c && gcc -O2 -S -Wall -fdump-tree-optimized=3D/dev/stdout z.c struct A { char n, a[4], b[4]; }; const struct A a =3D { }; int f (void) { const char *p =3D &a.b[2]; return __builtin_strlen (p - 2); } z.c: In function =E2=80=98f=E2=80=99: z.c:7:10: warning: offset =E2=80=985=E2=80=99 outside bounds of constant st= ring [-Warray-bounds] 7 | return __builtin_strlen (p - 2); | ^~~~~~~~~~~~~~~~~~~~~~~~ z.c:2:16: note: =E2=80=98a=E2=80=99 declared here 2 | const struct A a =3D { }; | ^ ;; Function f (f, funcdef_no=3D0, decl_uid=3D1935, cgraph_uid=3D1, symbol_o= rder=3D1) f () { long unsigned int _1; int _3; [local count: 1073741824]: _1 =3D __builtin_strlen (&MEM [(void *)&a + 5B]); _3 =3D (int) _1; return _3; }=