public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] rust-constexpr.cc: port over cxx_eval_vector_conditional_expression
@ 2022-08-29 15:34 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-08-29 15:34 UTC (permalink / raw)
To: gcc-cvs
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))
{
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-29 15:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29 15:34 [gcc/devel/rust/master] rust-constexpr.cc: port over cxx_eval_vector_conditional_expression Thomas Schwinge
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).