From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 3AB05385AC2D; Mon, 29 Aug 2022 15:34:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AB05385AC2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661787255; bh=ouEwgXPXsUmLBOw9kU5TPNRG0A6Xj7hbyPyrBmAwkrc=; h=From:To:Subject:Date:From; b=vfL+Dut+jMG2KCWyzTXJvWXm0Lv1MSLei8KOCAMSFd7Vh1kgk8Ev9rkuu4lHExU8L MtvVOt5evqBt6D3sz/VBDfuYLwgDVktr23CNVpGLuMwFz0XxouXl2mVNRAA50kgnT9 G5z/n1AFDjhjcvDy73SBgg3IRi3mZ1nuYrR4TKX8= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] rust-constexpr.cc: port over cxx_eval_logical_expression X-Act-Checkin: gcc X-Git-Author: Faisal Abbas <90.abbasfaisal@gmail.com> X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 30b2f58b544acfa8a90cc4f0cf5d6ae7e0956f37 X-Git-Newrev: e8e58d54db23acc03bba3bd9a89cfe35cf3c2ba3 Message-Id: <20220829153415.3AB05385AC2D@sourceware.org> Date: Mon, 29 Aug 2022 15:34:15 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e8e58d54db23acc03bba3bd9a89cfe35cf3c2ba3 commit e8e58d54db23acc03bba3bd9a89cfe35cf3c2ba3 Author: Faisal Abbas <90.abbasfaisal@gmail.com> Date: Sat Jul 30 20:28:13 2022 +0100 rust-constexpr.cc: port over cxx_eval_logical_expression Diff: --- gcc/rust/backend/rust-constexpr.cc | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index b8f62e38525..357caef6946 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -909,6 +909,32 @@ rs_eval_indirect_ref (const constexpr_ctx *ctx, tree t, bool lval, return r; } +// forked from gcc/cp/constexpr.cc cxx_eval_logical_expression + +/* Subroutine of cxx_eval_constant_expression. + Evaluate a short-circuited logical expression T in the context + of a given constexpr CALL. BAILOUT_VALUE is the value for + early return. CONTINUE_VALUE is used here purely for + sanity check purposes. */ + +static tree +eval_logical_expression (const constexpr_ctx *ctx, tree t, tree bailout_value, + tree continue_value, bool lval, bool *non_constant_p, + bool *overflow_p) +{ + tree r; + tree lhs = eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p); + VERIFY_CONSTANT (lhs); + if (tree_int_cst_equal (lhs, bailout_value)) + return lhs; + gcc_assert (tree_int_cst_equal (lhs, continue_value)); + r = eval_constant_expression (ctx, TREE_OPERAND (t, 1), lval, non_constant_p, + overflow_p); + VERIFY_CONSTANT (r); + return r; +} + static tree eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, bool *non_constant_p, bool *overflow_p, @@ -1022,6 +1048,22 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, r = eval_binary_expression (ctx, t, false, non_constant_p, overflow_p); break; + /* fold can introduce non-IF versions of these; still treat them as + short-circuiting. */ + case TRUTH_AND_EXPR: + case TRUTH_ANDIF_EXPR: + r = eval_logical_expression (ctx, t, boolean_false_node, + boolean_true_node, lval, non_constant_p, + overflow_p); + break; + + case TRUTH_OR_EXPR: + case TRUTH_ORIF_EXPR: + r = eval_logical_expression (ctx, t, boolean_true_node, + boolean_false_node, lval, non_constant_p, + overflow_p); + break; + case CALL_EXPR: r = eval_call_expression (ctx, t, false, non_constant_p, overflow_p); break;