From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 74D6E3851C0B; Sat, 20 Jun 2020 23:19:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74D6E3851C0B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592695186; bh=C0qe64NiX4hfHovfPqhPy2OdcDYNzJylPPmeVTAMdac=; h=From:To:Subject:Date:From; b=fKog0/FYrBv4TnuhsVS7rgCuv7exynq3HFyVgO6EDjWrelCfkEKvMQFJYtTsrHUpd ghqNmMAZMk+CZrpoqIRGTCOwvmrAbRiZL3kjFc5O6AU9HXngbuW6SCNos3nM9tM+SZ x+e8vXhRwSEOGgl0gjQY321DkMtF0ZmX/5krhX9c= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/95794] New: strnlen of a constant string plus variable offset not folded when bound exceeds size Date: Sat, 20 Jun 2020 23:19:46 +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: 10.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: Sat, 20 Jun 2020 23:19:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95794 Bug ID: 95794 Summary: strnlen of a constant string plus variable offset not folded when bound exceeds size Product: gcc Version: 10.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: --- GCC folds comparisons of the results of calls to strlen with constant strin= gs and variable offsets but it doesn't do the same for the equivalent strnlen = with a bound in excess of the string size (strnlen with a bound greater than the string length are equivalent to strlen with the same argument). $ cat z.c && gcc -O2 -S -Wall -fdump-tree-optimized=3D/dev/stdout z.c const char a[] =3D "12345"; void f (int i) { if (__builtin_strlen (&a[i]) > 5) // folded to false __builtin_abort (); } void g (int i) { if (__builtin_strnlen (&a[i], 7) > 5) // not folded __builtin_abort (); } ;; Function f (f, funcdef_no=3D0, decl_uid=3D1931, cgraph_uid=3D1, symbol_o= rder=3D1) f (int i) { [local count: 1073741824]: return; } ;; Function g (g, funcdef_no=3D1, decl_uid=3D1934, cgraph_uid=3D2, symbol_o= rder=3D2) g (int i) { const char * _1; long unsigned int _2; sizetype _6; [local count: 1073741824]: _6 =3D (sizetype) i_3(D); _1 =3D &a + _6; _2 =3D __builtin_strnlen (_1, 7); if (_2 > 5) goto ; [0.00%] else goto ; [100.00%] [count: 0]: __builtin_abort (); [local count: 1073741824]: return; }=