[C++ PATCH 3/3] Add TARGET_EXPR_DIRECT_INIT_P sanity check.

Jason Merrill jason@redhat.com
Wed Jan 8 20:25:00 GMT 2020


The previous patch fixes an instance of directly expanding a TARGET_EXPR that
has TARGET_EXPR_DIRECT_INIT_P set, which should never happen.  So let's check
for any other instances.

Tested x86_64-pc-linux-gnu, applying to trunk.

	* cp-gimplify.c (cp_gimplify_expr) [TARGET_EXPR]: Check
	TARGET_EXPR_DIRECT_INIT_P.
	* constexpr.c (cxx_eval_constant_expression): Likewise.
---
 gcc/cp/constexpr.c   | 1 +
 gcc/cp/cp-gimplify.c | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 5fe6d0277b6..9306a7dce4a 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -5312,6 +5312,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
 	  *non_constant_p = true;
 	  break;
 	}
+      gcc_checking_assert (!TARGET_EXPR_DIRECT_INIT_P (t));
       /* Avoid evaluating a TARGET_EXPR more than once.  */
       if (tree *p = ctx->global->values.get (TARGET_EXPR_SLOT (t)))
 	{
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 1d2a77d2c0a..827d240d11a 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -925,6 +925,13 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
 	}
       break;
 
+    case TARGET_EXPR:
+      /* A TARGET_EXPR that expresses direct-initialization should have been
+	 elided by cp_gimplify_init_expr.  */
+      gcc_checking_assert (!TARGET_EXPR_DIRECT_INIT_P (*expr_p));
+      ret = GS_UNHANDLED;
+      break;
+
     case RETURN_EXPR:
       if (TREE_OPERAND (*expr_p, 0)
 	  && (TREE_CODE (TREE_OPERAND (*expr_p, 0)) == INIT_EXPR
-- 
2.18.1



More information about the Gcc-patches mailing list