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 clean up function start/end code


Since the functions-as-trees conversion, parm cleanups are represented
using standard cleanups, which are handled with the same code as other
cleanups, and stored in the binding level for the parms.  So we don't need
to mess with cleanup_label and all that nonsense; the cleanups will be
generated after return_label without any special intervention.

Of course, the ABI says that cleanups for value parms should be handled in
the caller instead...I'll look at that shortly.

Tested i686-pc-linux-gnu.

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

	* decl.c (store_parm_decls): Remove parms_have_cleanups cruft.
	* semantics.c (genrtl_start_function): Don't pass
	parms_have_cleanups or push an extra binding level.
	(genrtl_finish_function): Lose cleanup_label cruft.

*** decl.c.~1~	Wed Dec 12 17:03:01 2001
--- decl.c	Wed Dec 12 16:32:58 2001
*************** store_parm_decls (current_function_parms
*** 13771,13777 ****
  {
    register tree fndecl = current_function_decl;
    register tree parm;
-   int parms_have_cleanups = 0;
    tree cleanups = NULL_TREE;
  
    /* This is a chain of any other decls that came in among the parm
--- 13768,13773 ----
*************** store_parm_decls (current_function_parms
*** 13852,13862 ****
        cleanups = TREE_CHAIN (cleanups);
      }
  
-   /* Create a binding contour which can be used to catch
-      cleanup-generated temporaries.  */
-   if (parms_have_cleanups)
-     pushlevel (0);
- 
    /* Do the starting of the exception specifications, if we have any.  */
    if (flag_exceptions && !processing_template_decl
        && flag_enforce_eh_specs
--- 13848,13853 ----
*** semantics.c.~1~	Wed Dec 12 17:03:01 2001
--- semantics.c	Wed Dec 12 19:03:50 2001
*************** genrtl_start_function (fn)
*** 2618,2640 ****
  
    /* Create a binding level for the parameters.  */
    expand_start_bindings (2);
!   /* Go through the PARM_DECLs for this function to see if any need
!      cleanups.  */
!   for (parm = DECL_ARGUMENTS (fn); parm; parm = TREE_CHAIN (parm))
!     if (TREE_TYPE (parm) != error_mark_node
! 	&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (parm)))
!       {
! 	expand_function_start (fn, /*parms_have_cleanups=*/1);
! 	break;
!       }
!   if (!parm)
!     expand_function_start (fn, /*parms_have_cleanups=*/0);
    /* If this function is `main'.  */
    if (DECL_MAIN_P (fn))
      expand_main_function ();
-   /* Create a binding contour which can be used to catch
-      cleanup-generated temporaries.  */
-   expand_start_bindings (2);
  
    /* Give our named return value the same RTL as our RESULT_DECL.  */
    if (current_function_return_value)
--- 2610,2619 ----
  
    /* Create a binding level for the parameters.  */
    expand_start_bindings (2);
!   expand_function_start (fn, /*parms_have_cleanups=*/0);
    /* If this function is `main'.  */
    if (DECL_MAIN_P (fn))
      expand_main_function ();
  
    /* Give our named return value the same RTL as our RESULT_DECL.  */
    if (current_function_return_value)
*************** static void
*** 2647,2653 ****
  genrtl_finish_function (fn)
       tree fn;
  {
-   tree no_return_label = NULL_TREE;
    tree t;
  
  #if 0
--- 2626,2631 ----
*************** genrtl_finish_function (fn)
*** 2676,2734 ****
    /* Clean house because we will need to reorder insns here.  */
    do_pending_stack_adjust ();
  
!   if (!dtor_label && !DECL_CONSTRUCTOR_P (fn)
!       && return_label != NULL_RTX
!       && ! DECL_NAME (DECL_RESULT (current_function_decl)))
!     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
! 
!   /* If this function is supposed to return a value, ensure that
!      we do not fall into the cleanups by mistake.  The end of our
!      function will look like this:
! 
!      user code (may have return stmt somewhere)
!      goto no_return_label
!      cleanup_label:
!      cleanups
!      goto return_label
!      no_return_label:
!      NOTE_INSN_FUNCTION_END
!      return_label:
!      things for return
! 
!      If the user omits a return stmt in the USER CODE section, we
!      will have a control path which reaches NOTE_INSN_FUNCTION_END.
!      Otherwise, we won't.  */
!   if (no_return_label)
!     {
!       DECL_CONTEXT (no_return_label) = fn;
!       DECL_INITIAL (no_return_label) = error_mark_node;
!       DECL_SOURCE_FILE (no_return_label) = input_filename;
!       DECL_SOURCE_LINE (no_return_label) = lineno;
!       expand_goto (no_return_label);
!     }
! 
!   if (cleanup_label)
!     {
!       /* Remove the binding contour which is used to catch
! 	 cleanup-generated temporaries.  */
!       expand_end_bindings (0, 0, 0);
!       poplevel (0, 0, 0);
! 
!       /* Emit label at beginning of cleanup code for parameters.  */
!       emit_label (cleanup_label);
!     }
! 
!   /* Finish building code that will trigger warnings if users forget
!      to make their functions return values.  */
!   if (return_label)
      emit_jump (return_label);
-   if (no_return_label)
-     {
-       /* We don't need to call `expand_*_return' here because we don't
- 	 need any cleanups here--this path of code is only for error
- 	 checking purposes.  */
-       expand_label (no_return_label);
-     }
  
    /* We hard-wired immediate_size_expand to zero in start_function.
       Expand_function_end will decrement this variable.  So, we set the
--- 2654,2663 ----
    /* Clean house because we will need to reorder insns here.  */
    do_pending_stack_adjust ();
  
!   /* If we have a named return value, we need to force a return so that
!      the return register is USEd.  */
!   if (DECL_NAME (DECL_RESULT (fn)))
      emit_jump (return_label);
  
    /* We hard-wired immediate_size_expand to zero in start_function.
       Expand_function_end will decrement this variable.  So, we set the

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