From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 589E4385C40B; Tue, 30 Nov 2021 21:05:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 589E4385C40B MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5638] c++: don't fold away 'if' with constant condition X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: 91c26004037db689954318d3d1c801eea18d45f4 X-Git-Newrev: a3e75c1491cd2d501081210925a89a65b1c1e5e5 Message-Id: <20211130210532.589E4385C40B@sourceware.org> Date: Tue, 30 Nov 2021 21:05:32 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Nov 2021 21:05:32 -0000 https://gcc.gnu.org/g:a3e75c1491cd2d501081210925a89a65b1c1e5e5 commit r12-5638-ga3e75c1491cd2d501081210925a89a65b1c1e5e5 Author: Jason Merrill Date: Thu Nov 25 10:50:59 2021 -0500 c++: don't fold away 'if' with constant condition richi's recent unreachable code warning experiments had trouble with the C++ front end folding away an 'if' with a constant condition. Let's do less folding at the statement level. gcc/cp/ChangeLog: * cp-gimplify.c (genericize_if_stmt): Always build a COND_EXPR. Diff: --- gcc/cp/cp-gimplify.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 0988655eeba..0a002db14e7 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -166,11 +166,8 @@ genericize_if_stmt (tree *stmt_p) can contain unfolded immediate function calls, we have to discard the then_ block regardless of whether else_ has side-effects or not. */ if (IF_STMT_CONSTEVAL_P (stmt)) - stmt = else_; - else if (integer_nonzerop (cond) && !TREE_SIDE_EFFECTS (else_)) - stmt = then_; - else if (integer_zerop (cond) && !TREE_SIDE_EFFECTS (then_)) - stmt = else_; + stmt = build3 (COND_EXPR, void_type_node, boolean_false_node, + void_node, else_); else stmt = build3 (COND_EXPR, void_type_node, cond, then_, else_); protected_set_expr_location_if_unset (stmt, locus);