From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 819033835C3B; Mon, 12 Jul 2021 09:58:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 819033835C3B From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/101419] [9/10/11/12 Regression] collapsing memset() calls can break __builtin_object_size() Date: Mon, 12 Jul 2021 09:58:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub 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.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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: Mon, 12 Jul 2021 09:58:09 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101419 --- Comment #4 from Jakub Jelinek --- --- gcc/tree-object-size.c.jj 2021-01-04 10:25:39.911221618 +0100 +++ gcc/tree-object-size.c 2021-07-12 11:28:51.328120222 +0200 @@ -1393,6 +1393,11 @@ pass_object_sizes::execute (function *fu { tree tem =3D make_ssa_name (type); gimple_call_set_lhs (call, tem); + if (object_size_type =3D=3D 1) + { + ost =3D build_zero_cst (TREE_TYPE (ost)); + gimple_call_set_arg (call, 1, ost); + } enum tree_code code =3D object_size_type =3D=3D 1 ? MIN_EXPR : MAX_= EXPR; tree cst =3D build_int_cstu (type, bytes); works, but unfortunately only for __builtin_object_size (, 1). When I did that also for 3 (to turn it into 2), it breaks several gcc.dg/builtin-object-size*.c tests. 0 is defined as an upper bound of the object size, subobjects not taken into account 1 is defined similarly, but subobjects are taken into account 2 is defined as a lower bound of the object size, subobjects not taken into account 3 is 2 with subobjects -D_FORTIFY_SOURCE=3D{1,2} typically only uses 0 and 1 modes, 2 and 3 are ra= re, and are useful e.g. when somebody wants to find out if the object size is e= xact or not (for exact case the upper and lower bounds are equal).=