This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH to reduce use of [cd]tor_label


ctor_label is obsolete in the V3 ABI, as it was used to control the special
return semantics of constructors, which they no longer have.

dtor_label is still useful, but now that we have DECL_DESTRUCTOR_P, not the
preferred way of determining whether the current function is a destructor.

Tested i686-pc-linux-gnu.

2001-12-12  Jason Merrill  <jason@redhat.com>

	* cp-tree.h (struct cp_language_function): Remove x_ctor_label.
	(ctor_label): Remove.
	* semantics.c (finish_return_stmt): Lose ctor_label support.
	* decl.c (finish_constructor_body, mark_lang_function): Likewise.
	* typeck.c (check_return_expr): Check DECL_DESTRUCTOR_P, not 
	dtor_label.

	* call.c (build_new_method_call): Let resolves_to_fixed_type_p
	check for [cd]tors.
	* class.c (fixed_type_or_null, case INDIRECT_REF): Fix.

*** call.c.~1~	Wed Dec 12 17:03:01 2001
--- call.c	Wed Dec 12 16:32:54 2001
*************** build_new_method_call (instance, name, a
*** 4660,4667 ****
      }
  
    if (DECL_VINDEX (cand->fn) && ! (flags & LOOKUP_NONVIRTUAL)
!       && ((instance == current_class_ref && (dtor_label || ctor_label))
! 	  || resolves_to_fixed_type_p (instance, 0)))
      flags |= LOOKUP_NONVIRTUAL;
  
    if (TREE_CODE (TREE_TYPE (cand->fn)) == METHOD_TYPE)
--- 4660,4666 ----
      }
  
    if (DECL_VINDEX (cand->fn) && ! (flags & LOOKUP_NONVIRTUAL)
!       && resolves_to_fixed_type_p (instance, 0))
      flags |= LOOKUP_NONVIRTUAL;
  
    if (TREE_CODE (TREE_TYPE (cand->fn)) == METHOD_TYPE)
*** class.c.~1~	Wed Dec 12 17:03:01 2001
--- class.c	Wed Dec 12 16:27:24 2001
*************** fixed_type_or_null (instance, nonnull, c
*** 5287,5297 ****
    switch (TREE_CODE (instance))
      {
      case INDIRECT_REF:
!       /* Check that we are not going through a cast of some sort.  */
!       if (TREE_TYPE (instance)
! 	  == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0))))
! 	instance = TREE_OPERAND (instance, 0);
!       /* fall through...  */
      case CALL_EXPR:
        /* This is a call to a constructor, hence it's never zero.  */
        if (TREE_HAS_CONSTRUCTOR (instance))
--- 5287,5298 ----
    switch (TREE_CODE (instance))
      {
      case INDIRECT_REF:
!       if (POINTER_TYPE_P (instance))
! 	return NULL_TREE;
!       else
! 	return fixed_type_or_null (TREE_OPERAND (instance, 0),
! 				   nonnull, cdtorp);
! 
      case CALL_EXPR:
        /* This is a call to a constructor, hence it's never zero.  */
        if (TREE_HAS_CONSTRUCTOR (instance))
*** cp-tree.h.~1~	Wed Dec 12 17:03:01 2001
--- cp-tree.h	Wed Dec 12 16:32:57 2001
*************** struct cp_language_function
*** 801,807 ****
  {
    struct language_function base;
  
-   tree x_ctor_label;
    tree x_dtor_label;
    tree x_current_class_ptr;
    tree x_current_class_ref;
--- 801,806 ----
*************** struct cp_language_function
*** 836,846 ****
  
  #define dtor_label cp_function_chain->x_dtor_label
  
- /* In a constructor, the point at which we are ready to return
-    the pointer to the initialized object.  */
- 
- #define ctor_label cp_function_chain->x_ctor_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'.  */
--- 835,840 ----
*** decl.c.~1~	Wed Dec 12 17:03:01 2001
--- decl.c	Wed Dec 12 16:32:58 2001
*************** save_function_data (decl)
*** 13912,13927 ****
  static void
  finish_constructor_body ()
  {
-   /* Any return from a constructor will end up here.  */
-   if (ctor_label)
-     add_stmt (build_stmt (LABEL_STMT, ctor_label));
- 
-   /* Clear CTOR_LABEL so that finish_return_stmt knows to really
-      generate the return, rather than a goto to CTOR_LABEL.  */
-   ctor_label = NULL_TREE;
-   /* In check_return_expr we translate an empty return from a
-      constructor to a return of `this'.  */
-   finish_return_stmt (NULL_TREE);
    /* Mark the end of the constructor.  */
    add_stmt (build_stmt (CTOR_STMT));
  }
--- 13903,13908 ----
*************** mark_lang_function (p)
*** 14552,14558 ****
  
    mark_c_language_function (&p->base);
  
-   ggc_mark_tree (p->x_ctor_label);
    ggc_mark_tree (p->x_dtor_label);
    ggc_mark_tree (p->x_current_class_ptr);
    ggc_mark_tree (p->x_current_class_ref);
--- 14533,14538 ----
*** semantics.c.~1~	Wed Dec 12 17:03:01 2001
--- semantics.c	Wed Dec 12 19:03:50 2001
*************** finish_return_stmt (expr)
*** 390,406 ****
      expr = check_return_expr (expr);
    if (!processing_template_decl)
      {
!       if (DECL_CONSTRUCTOR_P (current_function_decl) && ctor_label)
! 	{
! 	  /* Even returns without a value in a constructor must return
! 	     `this'.  We accomplish this by sending all returns in a
! 	     constructor to the CTOR_LABEL; finish_function emits code to
! 	     return a value there.  When we finally generate the real
! 	     return statement, CTOR_LABEL is no longer set, and we fall
! 	     through into the normal return-processing code below.  */
! 	  return finish_goto_stmt (ctor_label);
! 	}
!       else if (DECL_DESTRUCTOR_P (current_function_decl))
  	{
  	  /* Similarly, all destructors must run destructors for
  	     base-classes before returning.  So, all returns in a
--- 390,396 ----
      expr = check_return_expr (expr);
    if (!processing_template_decl)
      {
!       if (DECL_DESTRUCTOR_P (current_function_decl))
  	{
  	  /* Similarly, all destructors must run destructors for
  	     base-classes before returning.  So, all returns in a
*** typeck.c.~1~	Fri Nov 30 14:06:03 2001
--- typeck.c	Wed Dec 12 17:17:00 2001
*************** check_return_expr (retval)
*** 6585,6591 ****
      warning ("function declared `noreturn' has a `return' statement");
  
    /* Check for various simple errors.  */
!   if (dtor_label)
      {
        if (retval)
  	error ("returning a value from a destructor");
--- 6585,6591 ----
      warning ("function declared `noreturn' has a `return' statement");
  
    /* Check for various simple errors.  */
!   if (DECL_DESTRUCTOR_P (current_function_decl))
      {
        if (retval)
  	error ("returning a value from a destructor");

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]