public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] rust-constexpr.cc: port over cxx_eval_vector_conditional_expression Date: Mon, 29 Aug 2022 15:34:30 +0000 (GMT) [thread overview] Message-ID: <20220829153430.75E58385609B@sourceware.org> (raw) 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)) {
reply other threads:[~2022-08-29 15:34 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220829153430.75E58385609B@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).