PATCH: Exceptions vs. sibling calls

Mark Mitchell mark@codesourcery.com
Wed May 24 14:42:00 GMT 2000


Here's the patch for the problem Nathan reported.  It's essentially
the same fix that went in a while back for sibling calls, but applied
to tail calls as well.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-05-24  Mark Mitchell  <mark@codesourcery.com>

	* calls.c (expand_call): Handle cleanups in tail-recursion
	arguments analagously to cleanups in sibling calls.

Index: testsuite/g++.old-deja/g++.eh/crash4.C
===================================================================
RCS file: crash4.C
diff -N crash4.C
*** /dev/null	Tue May  5 13:32:27 1998
--- crash4.C	Wed May 24 14:40:15 2000
***************
*** 0 ****
--- 1,14 ----
+ // Build don't link:
+ // Origin: Nathan Sidwell <nathan@codesourcery.com>
+ // Special g++ Options: -O2
+ 
+ struct A
+ {
+   A (int) { }
+   ~A () { }
+   int get () const { return 0; }
+ };
+ 
+ void f (const A &s) {
+   f (s.get ());
+ }
Index: calls.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/calls.c,v
retrieving revision 1.135
diff -c -p -r1.135 calls.c
*** calls.c	2000/05/15 19:12:54	1.135
--- calls.c	2000/05/24 21:40:20
*************** expand_call (exp, target, ignore)
*** 2400,2406 ****
  	    break;
  
  	  case 1: /* Mildly unsafe.  */
! 	      args[i].tree_value = unsave_expr (args[i].tree_value);
  	    break;
  
  	  case 2: /* Wildly unsafe.  */
--- 2400,2406 ----
  	    break;
  
  	  case 1: /* Mildly unsafe.  */
! 	    args[i].tree_value = unsave_expr (args[i].tree_value);
  	    break;
  
  	  case 2: /* Wildly unsafe.  */
*************** expand_call (exp, target, ignore)
*** 2444,2452 ****
  	 made until after RTL generation for the entire function is
  	 complete.  */
        start_sequence ();
! 
        if (optimize_tail_recursion (actparms, get_last_insn ()))
!         tail_recursion_insns = get_insns ();
        end_sequence ();
  
        /* Restore the original pending stack adjustment for the sibling and
--- 2444,2463 ----
  	 made until after RTL generation for the entire function is
  	 complete.  */
        start_sequence ();
!       /* If expanding any of the arguments creates cleanups, we can't
! 	 do a tailcall.  So, we'll need to pop the pending cleanups
! 	 list.  If, however, all goes well, and there are no cleanups
! 	 then the call to expand_start_target_temps will have no
! 	 effect.  */
!       expand_start_target_temps ();
        if (optimize_tail_recursion (actparms, get_last_insn ()))
! 	{
! 	  if (any_pending_cleanups (1))
! 	    try_tail_call = try_tail_recursion = 0;
! 	  else
! 	    tail_recursion_insns = get_insns ();
! 	}
!       expand_end_target_temps ();
        end_sequence ();
  
        /* Restore the original pending stack adjustment for the sibling and


More information about the Gcc-patches mailing list