public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] rust-constexpr.cc: add few more cases to eval_constant_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:6b440d46f16e3f93dd979852a1aab55f88add75f

commit 6b440d46f16e3f93dd979852a1aab55f88add75f
Author: Faisal Abbas <90.abbasfaisal@gmail.com>
Date:   Sat Aug 6 16:24:30 2022 +0100

    rust-constexpr.cc: add few more cases to eval_constant_expression()

Diff:
---
 gcc/rust/backend/rust-constexpr.cc | 60 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc
index 14c2969dcba..6f645beba45 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))
 	{

^ 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: add few more cases to eval_constant_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).