diff options
author | Faisal Abbas <90.abbasfaisal@gmail.com> | 2022-08-06 16:24:30 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-08-25 12:40:27 +0100 |
commit | 6b440d46f16e3f93dd979852a1aab55f88add75f (patch) | |
tree | 655e7f6d6fdeda5dac901f669b6c04fd3606c63b /gcc/rust/backend/rust-constexpr.cc | |
parent | 3e6dfca3166f8137deff833bcea7827e38b28fb4 (diff) | |
download | gcc-6b440d46f16e3f93dd979852a1aab55f88add75f.zip gcc-6b440d46f16e3f93dd979852a1aab55f88add75f.tar.gz gcc-6b440d46f16e3f93dd979852a1aab55f88add75f.tar.bz2 |
rust-constexpr.cc: add few more cases to eval_constant_expression()
Diffstat (limited to 'gcc/rust/backend/rust-constexpr.cc')
-rw-r--r-- | gcc/rust/backend/rust-constexpr.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index 14c2969..6f645be 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -1730,6 +1730,31 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, break; } + case COMPOUND_EXPR: { + /* check_return_expr sometimes wraps a TARGET_EXPR in a + COMPOUND_EXPR; don't get confused. Also handle EMPTY_CLASS_EXPR + introduced by build_call_a. */ + tree op0 = TREE_OPERAND (t, 0); + tree op1 = TREE_OPERAND (t, 1); + STRIP_NOPS (op1); + if ((TREE_CODE (op0) == TARGET_EXPR && op1 == TARGET_EXPR_SLOT (op0)) + || TREE_CODE (op1) == EMPTY_CLASS_EXPR) + r = eval_constant_expression (ctx, op0, lval, non_constant_p, + overflow_p, jump_target); + else + { + /* Check that the LHS is constant and then discard it. */ + eval_constant_expression (ctx, op0, true, non_constant_p, + overflow_p, jump_target); + if (*non_constant_p) + return t; + op1 = TREE_OPERAND (t, 1); + r = eval_constant_expression (ctx, op1, lval, non_constant_p, + overflow_p, jump_target); + } + } + break; + case REALPART_EXPR: case IMAGPART_EXPR: if (lval) @@ -1817,6 +1842,41 @@ eval_constant_expression (const constexpr_ctx *ctx, tree t, bool lval, overflow_p); break; + case TRY_CATCH_EXPR: + if (TREE_OPERAND (t, 0) == NULL_TREE) + { + r = void_node; + break; + } + r = eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p, jump_target); + break; + + case CLEANUP_POINT_EXPR: { + auto_vec<tree, 2> cleanups; + vec<tree> *prev_cleanups = ctx->global->cleanups; + ctx->global->cleanups = &cleanups; + r = eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p, jump_target); + ctx->global->cleanups = prev_cleanups; + unsigned int i; + tree cleanup; + /* Evaluate the cleanups. */ + FOR_EACH_VEC_ELT_REVERSE (cleanups, i, cleanup) + eval_constant_expression (ctx, cleanup, false, non_constant_p, + overflow_p); + } + break; + + case TRY_FINALLY_EXPR: + r = eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p, jump_target); + if (!*non_constant_p) + /* Also evaluate the cleanup. */ + eval_constant_expression (ctx, TREE_OPERAND (t, 1), true, + non_constant_p, overflow_p); + break; + case CONSTRUCTOR: if (TREE_CONSTANT (t) && reduced_constant_expression_p (t)) { |