From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 75E58385609B; Mon, 29 Aug 2022 15:34:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75E58385609B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661787270; bh=rJO4Wfz6SkScZPO6frCdh+XAR6c7lSz5S1jNvZHrlqU=; h=From:To:Subject:Date:From; b=nyigK20YFxvxi2oSE2ECRy1Q3xuxKLw62zsyjFGq38eSheKwC5tOw6gnNFbMzuiWy ChdNnmUmC509ybz0xa/aP3Yz4LCo7WNVfSCmVFD/+ReBK4/jMWJtzaGOXGuJoeMyC2 KZ9fyIa9ZKB6OSChrTc2U6A/Whkq9VtyyeSK6DPQ= 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_vector_conditional_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: bbc514d024a232dacfe218706dd07dcf01a51314 X-Git-Newrev: 3e6dfca3166f8137deff833bcea7827e38b28fb4 Message-Id: <20220829153430.75E58385609B@sourceware.org> Date: Mon, 29 Aug 2022 15:34:30 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3e6dfca3166f8137deff833bcea7827e38b28fb4 commit 3e6dfca3166f8137deff833bcea7827e38b28fb4 Author: Faisal Abbas <90.abbasfaisal@gmail.com> Date: Sat Aug 6 13:11:05 2022 +0100 rust-constexpr.cc: port over cxx_eval_vector_conditional_expression Diff: --- gcc/rust/backend/rust-constexpr.cc | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index c26b1afcf66..14c2969dcba 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -1233,6 +1233,46 @@ get_or_insert_ctor_field (tree ctor, tree index, int pos_hint = -1) } } +// forked from gcc/cp/constexpr.cc cxx_eval_vector_conditional_expression + +/* Subroutine of cxx_eval_constant_expression. + Attempt to evaluate vector condition expressions. Unlike + cxx_eval_conditional_expression, VEC_COND_EXPR acts like a normal + ternary arithmetics operation, where all 3 arguments have to be + evaluated as constants and then folding computes the result from + them. */ + +static tree +eval_vector_conditional_expression (const constexpr_ctx *ctx, tree t, + bool *non_constant_p, bool *overflow_p) +{ + tree arg1 + = eval_constant_expression (ctx, TREE_OPERAND (t, 0), + /*lval*/ false, non_constant_p, overflow_p); + VERIFY_CONSTANT (arg1); + tree arg2 + = eval_constant_expression (ctx, TREE_OPERAND (t, 1), + /*lval*/ false, non_constant_p, overflow_p); + VERIFY_CONSTANT (arg2); + tree arg3 + = eval_constant_expression (ctx, TREE_OPERAND (t, 2), + /*lval*/ false, non_constant_p, overflow_p); + VERIFY_CONSTANT (arg3); + location_t loc = EXPR_LOCATION (t); + tree type = TREE_TYPE (t); + tree r = fold_ternary_loc (loc, VEC_COND_EXPR, type, arg1, arg2, arg3); + if (r == NULL_TREE) + { + if (arg1 == TREE_OPERAND (t, 0) && arg2 == TREE_OPERAND (t, 1) + && arg3 == TREE_OPERAND (t, 2)) + r = t; + else + r = build3_loc (loc, VEC_COND_EXPR, type, arg1, arg2, arg3); + } + VERIFY_CONSTANT (r); + return r; +} + // forked from gcc/cp/constexpr.cc cxx_eval_bare_aggregate /* Subroutine of cxx_eval_constant_expression. @@ -1772,6 +1812,11 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, jump_target); break; + case VEC_COND_EXPR: + r = eval_vector_conditional_expression (ctx, t, non_constant_p, + overflow_p); + break; + case CONSTRUCTOR: if (TREE_CONSTANT (t) && reduced_constant_expression_p (t)) {