diff mbox series

[pushed] c++: Remove cdtor_label

Message ID 20220504135349.2638068-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: Remove cdtor_label | expand

Commit Message

Jason Merrill May 4, 2022, 1:53 p.m. UTC
Jakub pointed out that cdtor_label is unnecessary, we should get all the
desired semantics with a normal return.

Tested x86_64-pc-linux-gnu and arm-eabi//arm-sim, applying to trunk.

gcc/cp/ChangeLog:

	* cp-tree.h (struct language_function): Remove x_cdtor_label.
	(cdtor_label, LABEL_DECL_CDTOR): Remove.
	* constexpr.cc (returns): Don't check LABEL_DECL_CDTOR.
	(cxx_eval_constant_expression): Don't call returns.
	* decl.cc (check_goto): Don't check cdtor_label.
	(start_preparsed_function): And don't set it.
	(finish_constructor_body, finish_destructor_body): Remove.
	(finish_function_body): Don't call them.
	* typeck.cc (check_return_expr): Handle cdtor_returns_this here.
	* semantics.cc (finish_return_stmt): Not here.
---
 gcc/cp/cp-tree.h    | 14 --------------
 gcc/cp/constexpr.cc |  8 ++------
 gcc/cp/decl.cc      | 20 --------------------
 gcc/cp/semantics.cc | 11 -----------
 gcc/cp/typeck.cc    | 12 ++++++++++--
 5 files changed, 12 insertions(+), 53 deletions(-)


base-commit: 8afcd148103b0467126483151b6fb5ac68920e72
diff mbox series

Patch

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 8d7cf240b68..663fe7a20fc 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -543,7 +543,6 @@  extern GTY(()) tree cp_global_trees[CPTI_MAX];
       DECL_CONSTRAINT_VAR_P (in a PARM_DECL)
       TEMPLATE_DECL_COMPLEX_ALIAS_P (in TEMPLATE_DECL)
       DECL_INSTANTIATING_NSDMI_P (in a FIELD_DECL)
-      LABEL_DECL_CDTOR (in LABEL_DECL)
       USING_DECL_UNRELATED_P (in USING_DECL)
    3: DECL_IN_AGGR_P.
    4: DECL_C_BIT_FIELD (in a FIELD_DECL)
@@ -2057,7 +2056,6 @@  struct named_label_hash : ggc_remove <named_label_entry *>
 struct GTY(()) language_function {
   struct c_language_function base;
 
-  tree x_cdtor_label;
   tree x_current_class_ptr;
   tree x_current_class_ref;
   tree x_eh_spec_block;
@@ -2091,13 +2089,6 @@  struct GTY(()) language_function {
 
 #define cp_function_chain (cfun->language)
 
-/* In a constructor destructor, the point at which all derived class
-   destroying/construction has been done.  I.e., just before a
-   constructor returns, or before any base class destroying will be done
-   in a destructor.  */
-
-#define cdtor_label cp_function_chain->x_cdtor_label
-
 /* When we're processing a member function, current_class_ptr is the
    PARM_DECL for the `this' pointer.  The current_class_ref is an
    expression for `*this'.  */
@@ -4278,11 +4269,6 @@  get_vec_init_expr (tree t)
 #define DECL_LOCAL_DECL_ALIAS(NODE)			\
   DECL_ACCESS ((gcc_checking_assert (DECL_LOCAL_DECL_P (NODE)), NODE))
 
-/* Nonzero if NODE is the target for genericization of 'return' stmts
-   in constructors/destructors of targetm.cxx.cdtor_returns_this targets.  */
-#define LABEL_DECL_CDTOR(NODE) \
-  DECL_LANG_FLAG_2 (LABEL_DECL_CHECK (NODE))
-
 /* True if NODE was declared with auto in its return type, but it has
    started compilation and so the return type might have been changed by
    return type deduction; its declared return type should be found in
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index c40efa6cc4e..9b1e71857fc 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -6060,9 +6060,7 @@  static bool
 returns (tree *jump_target)
 {
   return *jump_target
-    && (TREE_CODE (*jump_target) == RETURN_EXPR
-	|| (TREE_CODE (*jump_target) == LABEL_DECL
-	    && LABEL_DECL_CDTOR (*jump_target)));
+    && TREE_CODE (*jump_target) == RETURN_EXPR;
 }
 
 static bool
@@ -7473,9 +7471,7 @@  cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
 
     case GOTO_EXPR:
       if (breaks (&TREE_OPERAND (t, 0))
-	  || continues (&TREE_OPERAND (t, 0))
-	  /* Allow for jumping to a cdtor_label.  */
-	  || returns (&TREE_OPERAND (t, 0)))
+	  || continues (&TREE_OPERAND (t, 0)))
 	*jump_target = TREE_OPERAND (t, 0);
       else
 	{
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 324498f399d..c9110db796a 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -3613,11 +3613,6 @@  check_goto (tree decl)
   if (TREE_CODE (decl) != LABEL_DECL)
     return;
 
-  /* We didn't record any information about this label when we created it,
-     and there's not much point since it's trivial to analyze as a return.  */
-  if (decl == cdtor_label)
-    return;
-
   hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
   named_label_entry **slot
     = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
@@ -17325,14 +17320,6 @@  start_preparsed_function (tree decl1, tree attrs, int flags)
 
   ++function_depth;
 
-  if (DECL_DESTRUCTOR_P (decl1)
-      || (DECL_CONSTRUCTOR_P (decl1)
-	  && targetm.cxx.cdtor_returns_this ()))
-    {
-      cdtor_label = create_artificial_label (input_location);
-      LABEL_DECL_CDTOR (cdtor_label) = true;
-    }
-
   start_fname_decls ();
 
   store_parm_decls (current_function_parms);
@@ -17503,9 +17490,6 @@  finish_constructor_body (void)
 
   if (targetm.cxx.cdtor_returns_this ())
     {
-      /* Any return from a constructor will end up here.  */
-      add_stmt (build_stmt (input_location, LABEL_EXPR, cdtor_label));
-
       val = DECL_ARGUMENTS (current_function_decl);
       suppress_warning (val, OPT_Wuse_after_free);
       val = build2 (MODIFY_EXPR, TREE_TYPE (val),
@@ -17592,10 +17576,6 @@  finish_destructor_body (void)
 {
   tree exprstmt;
 
-  /* Any return from a destructor will end up here; that way all base
-     and member cleanups will be run when the function returns.  */
-  add_stmt (build_stmt (input_location, LABEL_EXPR, cdtor_label));
-
   if (targetm.cxx.cdtor_returns_this ())
     {
       tree val;
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index bfb737f665b..10478d1afeb 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -1238,17 +1238,6 @@  finish_return_stmt (tree expr)
     {
       if (warn_sequence_point)
 	verify_sequence_points (expr);
-
-      if (DECL_DESTRUCTOR_P (current_function_decl)
-	  || (DECL_CONSTRUCTOR_P (current_function_decl)
-	      && targetm.cxx.cdtor_returns_this ()))
-	{
-	  /* Similarly, all destructors must run destructors for
-	     base-classes before returning.  So, all returns in a
-	     destructor get sent to the DTOR_LABEL; finish_function emits
-	     code to return a value there.  */
-	  return finish_goto_stmt (cdtor_label);
-	}
     }
 
   r = build_stmt (input_location, RETURN_EXPR, expr);
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 0da6f2485d0..57e55ed48d1 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -10447,7 +10447,11 @@  check_return_expr (tree retval, bool *no_warning)
     {
       if (retval)
 	error_at (loc, "returning a value from a destructor");
-      return NULL_TREE;
+
+      if (targetm.cxx.cdtor_returns_this ())
+	retval = current_class_ptr;
+      else
+	return NULL_TREE;
     }
   else if (DECL_CONSTRUCTOR_P (current_function_decl))
     {
@@ -10458,7 +10462,11 @@  check_return_expr (tree retval, bool *no_warning)
       else if (retval)
 	/* You can't return a value from a constructor.  */
 	error_at (loc, "returning a value from a constructor");
-      return NULL_TREE;
+
+      if (targetm.cxx.cdtor_returns_this ())
+	retval = current_class_ptr;
+      else
+	return NULL_TREE;
     }
 
   const tree saved_retval = retval;