C++ PATCH: destructions and tail-call stuff

Mark Mitchell mark@codesourcery.com
Tue Mar 21 12:13:00 GMT 2000


The tail-call machinery exposed a latent bug in the C++ front-end's
ability to unsave TARGET_EXPRs.  Here's a fix.

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

2000-03-21  Mark Mitchell  <mark@codesourcery.com>

	* tree.c (mark_local_for_remap_p): Mark variables declared in
	TARGET_EXPRs as well.

Index: testsuite/g++.old-deja/g++.other/dtor7.C
===================================================================
RCS file: dtor7.C
diff -N dtor7.C
*** /dev/null	Tue May  5 13:32:27 1998
--- dtor7.C	Tue Mar 21 12:07:50 2000
***************
*** 0 ****
--- 1,42 ----
+ // Origin: Mark Mitchell <mitchell@codesourcery.com>
+ // Special g++ Options: -O2
+ 
+ int i;
+ int j;
+ 
+ struct A
+ {
+   A ();
+   A (const A&);
+   ~A ();
+ };
+ 
+ A::A ()
+ {
+   ++i;
+ }
+ 
+ A::A (const A&)
+ {
+   ++i;
+ }
+ 
+ A::~A () 
+ {
+   --i;
+ }
+ 
+ A f () 
+ {
+   return A ();
+ }
+ 
+ void g (const A&)
+ {
+ }
+ 
+ int main ()
+ {
+   g (f ());
+   return i;
+ }
Index: tree.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/tree.c,v
retrieving revision 1.186
diff -c -p -r1.186 tree.c
*** tree.c	2000/03/21 18:10:45	1.186
--- tree.c	2000/03/21 19:52:24
*************** mark_local_for_remap_r (tp, walk_subtree
*** 2317,2334 ****
  {
    tree t = *tp;
    splay_tree st = (splay_tree) data;
  
!   if ((TREE_CODE (t) == DECL_STMT
!        && nonstatic_local_decl_p (DECL_STMT_DECL (t)))
!       || TREE_CODE (t) == LABEL_STMT)
      {
-       tree decl;
        tree copy;
  
-       /* Figure out what's being declared.  */
-       decl = (TREE_CODE (t) == DECL_STMT
- 	      ? DECL_STMT_DECL (t) : LABEL_STMT_LABEL (t));
-       
        /* Make a copy.  */
        copy = copy_decl_for_inlining (decl, 
  				     DECL_CONTEXT (decl), 
--- 2317,2340 ----
  {
    tree t = *tp;
    splay_tree st = (splay_tree) data;
+   tree decl;
  
!   
!   if (TREE_CODE (t) == DECL_STMT
!       && nonstatic_local_decl_p (DECL_STMT_DECL (t)))
!     decl = DECL_STMT_DECL (t);
!   else if (TREE_CODE (t) == LABEL_STMT)
!     decl = LABEL_STMT_LABEL (t);
!   else if (TREE_CODE (t) == TARGET_EXPR
! 	   && nonstatic_local_decl_p (TREE_OPERAND (t, 0)))
!     decl = TREE_OPERAND (t, 0);
!   else
!     decl = NULL_TREE;
! 
!   if (decl)
      {
        tree copy;
  
        /* Make a copy.  */
        copy = copy_decl_for_inlining (decl, 
  				     DECL_CONTEXT (decl), 
*************** mark_local_for_remap_r (tp, walk_subtree
*** 2344,2350 ****
  }
  
  /* Called via walk_tree when an expression is unsaved.  Using the
!    splay_tree pointed to by ST (which is really a `splay_tree *'),
     remaps all local declarations to appropriate replacements.  */
  
  static tree
--- 2350,2356 ----
  }
  
  /* Called via walk_tree when an expression is unsaved.  Using the
!    splay_tree pointed to by ST (which is really a `splay_tree'),
     remaps all local declarations to appropriate replacements.  */
  
  static tree


More information about the Gcc-patches mailing list