From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id A8E573856961; Mon, 29 Aug 2022 15:34:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8E573856961 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661787285; bh=afb6VeM1vkOOVGtTmUSz4CPEjFCPL8xfMrIzuuBt2Cs=; h=From:To:Subject:Date:From; b=RLDaulDYor82c2JJ87ArTbCD1QxJwRi4kswfHgN3dttOH4TnfgQtoC1uc9CxJRPcW Xy4LHHip+3OfvmSMZFjA+9V8PGRIZzk92ro8oOVMUpNNxcTtfH4Xgmkds1+ZADOGb5 UxGLdPhZZJ+neLMMNkKrTXX5ZkA1kKo2OMdyDO5M= 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 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: d780f02a54ff9cb0b5fd181eb21ae9afe2fd7d1c X-Git-Newrev: a38ad0b614ff5d601e5425824ad760235710eee5 Message-Id: <20220829153445.A8E573856961@sourceware.org> Date: Mon, 29 Aug 2022 15:34:45 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a38ad0b614ff5d601e5425824ad760235710eee5 commit a38ad0b614ff5d601e5425824ad760235710eee5 Author: Faisal Abbas <90.abbasfaisal@gmail.com> Date: Sat Aug 6 21:32:41 2022 +0100 rust-constexpr.cc: port over more cases to eval_constant_expression Diff: --- gcc/rust/backend/rust-constexpr.cc | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index 276bfe94e6f..340960e0ab6 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -1398,6 +1398,32 @@ eval_bare_aggregate (const constexpr_ctx *ctx, tree t, bool lval, return t; } +/* Subroutine of cxx_eval_constant_expression. + Like cxx_eval_unary_expression, except for trinary expressions. */ + +static tree +cxx_eval_trinary_expression (const constexpr_ctx *ctx, tree t, bool lval, + bool *non_constant_p, bool *overflow_p) +{ + int i; + tree args[3]; + tree val; + + for (i = 0; i < 3; i++) + { + args[i] = eval_constant_expression (ctx, TREE_OPERAND (t, i), lval, + non_constant_p, overflow_p); + VERIFY_CONSTANT (args[i]); + } + + val = fold_ternary_loc (EXPR_LOCATION (t), TREE_CODE (t), TREE_TYPE (t), + args[0], args[1], args[2]); + if (val == NULL_TREE) + return t; + VERIFY_CONSTANT (val); + return val; +} + /* Return true if T is a valid constant initializer. If a CONSTRUCTOR initializes all the members, the CONSTRUCTOR_NO_CLEARING flag will be cleared. @@ -1649,6 +1675,11 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, r = rs_eval_indirect_ref (ctx, t, lval, non_constant_p, overflow_p); break; + case VEC_PERM_EXPR: + r = cxx_eval_trinary_expression (ctx, t, lval, non_constant_p, + overflow_p); + break; + case PAREN_EXPR: gcc_assert (!REF_PARENTHESIZED_P (t)); /* A PAREN_EXPR resulting from __builtin_assoc_barrier has no effect in @@ -1680,6 +1711,21 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, return eval_constant_expression (ctx, BIND_EXPR_BODY (t), lval, non_constant_p, overflow_p, jump_target); + case OBJ_TYPE_REF: + /* Virtual function lookup. We don't need to do anything fancy. */ + return eval_constant_expression (ctx, OBJ_TYPE_REF_EXPR (t), lval, + non_constant_p, overflow_p); + + case EXIT_EXPR: { + tree cond = TREE_OPERAND (t, 0); + cond = eval_constant_expression (ctx, cond, /*lval*/ false, + non_constant_p, overflow_p); + VERIFY_CONSTANT (cond); + if (integer_nonzerop (cond)) + *jump_target = t; + } + break; + case RESULT_DECL: if (lval) return t;