From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id EB3AC385737B; Mon, 29 Aug 2022 15:33:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB3AC385737B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661787234; bh=wmK6O53cLsftDNeLGSXPpf02b6IXoWLV5Iy8GbZ8NtE=; h=From:To:Subject:Date:From; b=UL2Sh5fPnzBY9cCbnKJw8bkQILrfF+VlG1htqxjRBrZYV6ddMm8xFusFeZVctpuLd 5WrppAMoBHdMg4kkqirQKksPI+QW+SC0Tz/GTDz+OBD0WI4iLXsjRAWcvsoNLsFPEU zfjdVeydotLn7/eIvo2U4AY2xu7o70BnG3OeK1YQ= 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_unary_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: e991065fdbee901d4bfe3af89e0d497e74dcc7d3 X-Git-Newrev: 23bde7d7c663302c803f0a7e4324630eae825008 Message-Id: <20220829153354.EB3AC385737B@sourceware.org> Date: Mon, 29 Aug 2022 15:33:54 +0000 (GMT) List-Id: https://gcc.gnu.org/g:23bde7d7c663302c803f0a7e4324630eae825008 commit 23bde7d7c663302c803f0a7e4324630eae825008 Author: Faisal Abbas <90.abbasfaisal@gmail.com> Date: Fri Jul 29 05:53:09 2022 +0100 rust-constexpr.cc: port over cxx_eval_unary_expression Diff: --- gcc/rust/backend/rust-constexpr.cc | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index 127451e5966..6ef601d66c2 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -501,6 +501,10 @@ static tree eval_switch_expr (const constexpr_ctx *ctx, tree t, bool *non_constant_p, bool *overflow_p, tree *jump_target); +static tree +eval_unary_expression (const constexpr_ctx *ctx, tree t, bool /*lval*/, + bool *non_constant_p, bool *overflow_p); + /* Variables and functions to manage constexpr call expansion context. These do not need to be marked for PCH or GC. */ @@ -739,6 +743,33 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, } break; + case REALPART_EXPR: + case IMAGPART_EXPR: + if (lval) + { + r = eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p); + if (r == error_mark_node) + ; + else if (r == TREE_OPERAND (t, 0)) + r = t; + else + r = fold_build1 (TREE_CODE (t), TREE_TYPE (t), r); + break; + } + /* FALLTHRU */ + case CONJ_EXPR: + case FIX_TRUNC_EXPR: + case FLOAT_EXPR: + case NEGATE_EXPR: + case ABS_EXPR: + case ABSU_EXPR: + case BIT_NOT_EXPR: + case TRUTH_NOT_EXPR: + case FIXED_CONVERT_EXPR: + r = eval_unary_expression (ctx, t, lval, non_constant_p, overflow_p); + break; + case LOOP_EXPR: case WHILE_STMT: case FOR_STMT: @@ -2970,6 +3001,37 @@ eval_switch_expr (const constexpr_ctx *ctx, tree t, bool *non_constant_p, return NULL_TREE; } +// forked from gcc/cp/constexpr.cc eval_unary_expression + +/* Subroutine of cxx_eval_constant_expression. + Attempt to reduce the unary expression tree T to a compile time value. + If successful, return the value. Otherwise issue a diagnostic + and return error_mark_node. */ + +static tree +eval_unary_expression (const constexpr_ctx *ctx, tree t, bool /*lval*/, + bool *non_constant_p, bool *overflow_p) +{ + tree r; + tree orig_arg = TREE_OPERAND (t, 0); + tree arg = eval_constant_expression (ctx, orig_arg, /*lval*/ false, + non_constant_p, overflow_p); + VERIFY_CONSTANT (arg); + location_t loc = EXPR_LOCATION (t); + enum tree_code code = TREE_CODE (t); + tree type = TREE_TYPE (t); + r = fold_unary_loc (loc, code, type, arg); + if (r == NULL_TREE) + { + if (arg == orig_arg) + r = t; + else + r = build1_loc (loc, code, type, arg); + } + VERIFY_CONSTANT (r); + return r; +} + // #include "gt-rust-rust-constexpr.h" } // namespace Compile