From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 8431F385AE5F; Mon, 29 Aug 2022 15:34:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8431F385AE5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661787275; bh=WMxJt2fjA48p8W5Q2TJjXLT8GdSGbl/DDLCtEE29egk=; h=From:To:Subject:Date:From; b=jf04isqkihOxbvEChklyX5/37JPE5+gruMaH9Jx1FXr21x4IOD4wLrmPjE+s9r9Sj tGgheIDTOvsrMhLF1GLb/y3az+TwT6SSurCPt/6Rq94+o3iqADCfXIUfaaLtslI4F0 xSVh8nha0wRJh/zY7KvwNYPi1LgcdWg8VZqHJKaY= 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: add few more cases to eval_constant_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: 3e6dfca3166f8137deff833bcea7827e38b28fb4 X-Git-Newrev: 6b440d46f16e3f93dd979852a1aab55f88add75f Message-Id: <20220829153435.8431F385AE5F@sourceware.org> Date: Mon, 29 Aug 2022 15:34:35 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6b440d46f16e3f93dd979852a1aab55f88add75f commit 6b440d46f16e3f93dd979852a1aab55f88add75f Author: Faisal Abbas <90.abbasfaisal@gmail.com> Date: Sat Aug 6 16:24:30 2022 +0100 rust-constexpr.cc: add few more cases to eval_constant_expression() Diff: --- gcc/rust/backend/rust-constexpr.cc | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index 14c2969dcba..6f645beba45 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -1730,6 +1730,31 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, break; } + case COMPOUND_EXPR: { + /* check_return_expr sometimes wraps a TARGET_EXPR in a + COMPOUND_EXPR; don't get confused. Also handle EMPTY_CLASS_EXPR + introduced by build_call_a. */ + tree op0 = TREE_OPERAND (t, 0); + tree op1 = TREE_OPERAND (t, 1); + STRIP_NOPS (op1); + if ((TREE_CODE (op0) == TARGET_EXPR && op1 == TARGET_EXPR_SLOT (op0)) + || TREE_CODE (op1) == EMPTY_CLASS_EXPR) + r = eval_constant_expression (ctx, op0, lval, non_constant_p, + overflow_p, jump_target); + else + { + /* Check that the LHS is constant and then discard it. */ + eval_constant_expression (ctx, op0, true, non_constant_p, + overflow_p, jump_target); + if (*non_constant_p) + return t; + op1 = TREE_OPERAND (t, 1); + r = eval_constant_expression (ctx, op1, lval, non_constant_p, + overflow_p, jump_target); + } + } + break; + case REALPART_EXPR: case IMAGPART_EXPR: if (lval) @@ -1817,6 +1842,41 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, overflow_p); break; + case TRY_CATCH_EXPR: + if (TREE_OPERAND (t, 0) == NULL_TREE) + { + r = void_node; + break; + } + r = eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p, jump_target); + break; + + case CLEANUP_POINT_EXPR: { + auto_vec cleanups; + vec *prev_cleanups = ctx->global->cleanups; + ctx->global->cleanups = &cleanups; + r = eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p, jump_target); + ctx->global->cleanups = prev_cleanups; + unsigned int i; + tree cleanup; + /* Evaluate the cleanups. */ + FOR_EACH_VEC_ELT_REVERSE (cleanups, i, cleanup) + eval_constant_expression (ctx, cleanup, false, non_constant_p, + overflow_p); + } + break; + + case TRY_FINALLY_EXPR: + r = eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p, jump_target); + if (!*non_constant_p) + /* Also evaluate the cleanup. */ + eval_constant_expression (ctx, TREE_OPERAND (t, 1), true, + non_constant_p, overflow_p); + break; + case CONSTRUCTOR: if (TREE_CONSTANT (t) && reduced_constant_expression_p (t)) {