aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-constexpr.cc
diff options
context:
space:
mode:
authorFaisal Abbas <90.abbasfaisal@gmail.com>2022-07-29 05:53:09 +0100
committerPhilip Herron <philip.herron@embecosm.com>2022-08-25 12:40:25 +0100
commit23bde7d7c663302c803f0a7e4324630eae825008 (patch)
tree245f661371c5540967f078cfa153721450e62773 /gcc/rust/backend/rust-constexpr.cc
parente991065fdbee901d4bfe3af89e0d497e74dcc7d3 (diff)
downloadgcc-23bde7d7c663302c803f0a7e4324630eae825008.zip
gcc-23bde7d7c663302c803f0a7e4324630eae825008.tar.gz
gcc-23bde7d7c663302c803f0a7e4324630eae825008.tar.bz2
rust-constexpr.cc: port over cxx_eval_unary_expression
Diffstat (limited to 'gcc/rust/backend/rust-constexpr.cc')
-rw-r--r--gcc/rust/backend/rust-constexpr.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc
index 127451e..6ef601d 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -501,6 +501,10 @@ static tree
eval_switch_expr (const constexpr_ctx *ctx, tree t, bool *non_constant_p,
bool *overflow_p, tree *jump_target);
+static tree
+eval_unary_expression (const constexpr_ctx *ctx, tree t, bool /*lval*/,
+ bool *non_constant_p, bool *overflow_p);
+
/* Variables and functions to manage constexpr call expansion context.
These do not need to be marked for PCH or GC. */
@@ -739,6 +743,33 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval,
}
break;
+ case REALPART_EXPR:
+ case IMAGPART_EXPR:
+ if (lval)
+ {
+ r = eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval,
+ non_constant_p, overflow_p);
+ if (r == error_mark_node)
+ ;
+ else if (r == TREE_OPERAND (t, 0))
+ r = t;
+ else
+ r = fold_build1 (TREE_CODE (t), TREE_TYPE (t), r);
+ break;
+ }
+ /* FALLTHRU */
+ case CONJ_EXPR:
+ case FIX_TRUNC_EXPR:
+ case FLOAT_EXPR:
+ case NEGATE_EXPR:
+ case ABS_EXPR:
+ case ABSU_EXPR:
+ case BIT_NOT_EXPR:
+ case TRUTH_NOT_EXPR:
+ case FIXED_CONVERT_EXPR:
+ r = eval_unary_expression (ctx, t, lval, non_constant_p, overflow_p);
+ break;
+
case LOOP_EXPR:
case WHILE_STMT:
case FOR_STMT:
@@ -2970,6 +3001,37 @@ eval_switch_expr (const constexpr_ctx *ctx, tree t, bool *non_constant_p,
return NULL_TREE;
}
+// forked from gcc/cp/constexpr.cc eval_unary_expression
+
+/* Subroutine of cxx_eval_constant_expression.
+ Attempt to reduce the unary expression tree T to a compile time value.
+ If successful, return the value. Otherwise issue a diagnostic
+ and return error_mark_node. */
+
+static tree
+eval_unary_expression (const constexpr_ctx *ctx, tree t, bool /*lval*/,
+ bool *non_constant_p, bool *overflow_p)
+{
+ tree r;
+ tree orig_arg = TREE_OPERAND (t, 0);
+ tree arg = eval_constant_expression (ctx, orig_arg, /*lval*/ false,
+ non_constant_p, overflow_p);
+ VERIFY_CONSTANT (arg);
+ location_t loc = EXPR_LOCATION (t);
+ enum tree_code code = TREE_CODE (t);
+ tree type = TREE_TYPE (t);
+ r = fold_unary_loc (loc, code, type, arg);
+ if (r == NULL_TREE)
+ {
+ if (arg == orig_arg)
+ r = t;
+ else
+ r = build1_loc (loc, code, type, arg);
+ }
+ VERIFY_CONSTANT (r);
+ return r;
+}
+
// #include "gt-rust-rust-constexpr.h"
} // namespace Compile