From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 183873858C39; Thu, 8 Sep 2022 09:56:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 183873858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662630999; bh=eQCfm8Qa5TftQJF8rZkXTfLCee9qtp+lWJnIKX/w+5s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FLm111aB4Ek5L878k1VAUYtQlBGPucHzNmN9MCzjO21znOlbXJ+aCYzP+iEfZvmuk tT9YRVJTUPs+wEbt5NjJD0AJ/5svS+pzwQPSUoD2DHBciYJ0xBf8A11HzdLepu91Dq Gxk1dUL1x9oiHSN38A3BF4+Gb2t6XLGDhHB5owyw= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/106885] -(a-b) is folded to b-a before the UBSAN pass is run Date: Thu, 08 Sep 2022 09:56:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW 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: everconfirmed cf_reconfirmed_on bug_status 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106885 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed| |2022-09-08 Status|UNCONFIRMED |NEW --- Comment #1 from Richard Biener --- We have ugly TYPE_OVERFLOW_SANITIZED checks in folding but it would be much better if the sanitizing would happen before any folding is invoked ... #0 fold_unary_loc (loc=3D258791, code=3DNEGATE_EXPR,=20 type=3D, op0=3D) at /home/rguenther/src/trunk/gcc/fold-const.cc:9275 #1 0x0000000000f5d084 in fold (expr=3D) at /home/rguenther/src/trunk/gcc/fold-const.cc:13421 #2 0x0000000000beca8c in c_fully_fold_internal ( expr=3D, in_init=3Dfalse,=20 maybe_const_operands=3D0x7fffffffd5ab, maybe_const_itself=3D0x7fffffffd= 5aa,=20 for_int_const=3Dfalse, lval=3Dfalse) at /home/rguenther/src/trunk/gcc/c/c-fold.cc:494 #3 0x0000000000beab7e in c_fully_fold (expr=3D= ,=20 in_init=3Dfalse, maybe_const=3D0x7fffffffd5ab, lval=3Dfalse) at /home/rguenther/src/trunk/gcc/c/c-fold.cc:125 #4 0x0000000000b7a840 in c_finish_return (loc=3D258791,=20 retval=3D, origtype=3D) at /home/rguenther/src/trunk/gcc/c/c-typeck.cc:10927 and match.pd exempts itself: /* -(A - B) -> B - A. */ (simplify (negate (minus @0 @1)) (if ((ANY_INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_SANITIZED (type)) || (FLOAT_TYPE_P (type) && !HONOR_SIGN_DEPENDENT_ROUNDING (type) && !HONOR_SIGNED_ZEROS (type))) (minus @1 @0))) but fold_negate_expr_1 does not: 638 case MINUS_EXPR: 639 /* - (A - B) -> B - A */ 640 if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) 641 && !HONOR_SIGNED_ZEROS (type)) 642 return fold_build2_loc (loc, MINUS_EXPR, type, 643 TREE_OPERAND (t, 1), TREE_OPERAND (= t, 0)); 644 break;=