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]

Re: [patch] fix semantics for walk_stmt_tree()


On Tue, 27 Feb 2001, Mark Mitchell wrote:

> I agree with your analysis.
> 
> I think we should fix prune_unused_decls.
> 
Thanks. This patch fixes both walk_stmt_tree and prune_unused_decls. 
I'm not particularly fond of returning '(tree) 1' to stop the
traversal, but I couldn't think of anything better. The return
value is not used for anything else, but it still looks ugly.

Bootstrapped on x86 on mainline. Should this go in the 3.0
branch?

2001-02-27  Diego Novillo  <dnovillo@redhat.com>

	* c-common.c (walk_stmt_tree): Visit the chain of the current tree
	even if walk_subtrees is 0.
	* c-semantics.c (prune_unused_decls): Return a non-null value to
	stop traversing the tree chain.

Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.227
diff -d -c -p -r1.227 c-common.c
*** c-common.c	2001/02/16 13:08:44	1.227
--- c-common.c	2001/02/27 16:39:25
*************** walk_stmt_tree (tp, func, data)
*** 3797,3821 ****
    if (result)
      return result;
  
-   /* Even if we didn't, FUNC may have decided that there was nothing
-      interesting below this point in the tree.  */
-   if (!walk_subtrees)
-     return NULL_TREE;
- 
    /* FUNC may have modified the tree, recheck that we're looking at a
       statement node.  */
    code = TREE_CODE (*tp);
    if (!statement_code_p (code))
      return NULL_TREE;
  
!   /* Walk over all the sub-trees of this operand.  Statement nodes never
!      contain RTL, and we needn't worry about TARGET_EXPRs.  */
!   len = TREE_CODE_LENGTH (code);
  
!   /* Go through the subtrees.  We need to do this in forward order so
!      that the scope of a FOR_EXPR is handled properly.  */
!   for (i = 0; i < len; ++i)
!     WALK_SUBTREE (TREE_OPERAND (*tp, i));
  
    /* Finally visit the chain.  This can be tail-recursion optimized if
       we write it this way.  */
--- 3797,3821 ----
    if (result)
      return result;
  
    /* FUNC may have modified the tree, recheck that we're looking at a
       statement node.  */
    code = TREE_CODE (*tp);
    if (!statement_code_p (code))
      return NULL_TREE;
  
!   /* Visit the subtrees unless FUNC decided that there was nothing
!      interesting below this point in the tree.  */
!   if (walk_subtrees)
!     {
!       /* Walk over all the sub-trees of this operand.  Statement nodes
! 	 never contain RTL, and we needn't worry about TARGET_EXPRs.  */
!       len = TREE_CODE_LENGTH (code);
  
!       /* Go through the subtrees.  We need to do this in forward order so
! 	 that the scope of a FOR_EXPR is handled properly.  */
!       for (i = 0; i < len; ++i)
! 	WALK_SUBTREE (TREE_OPERAND (*tp, i));
!     }
  
    /* Finally visit the chain.  This can be tail-recursion optimized if
       we write it this way.  */
Index: c-semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-semantics.c,v
retrieving revision 1.17
diff -d -c -p -r1.17 c-semantics.c
*** c-semantics.c	2001/01/02 23:49:43	1.17
--- c-semantics.c	2001/02/27 16:39:26
*************** prune_unused_decls (tp, walk_subtrees, d
*** 151,160 ****
    tree t = *tp;
  
    if (t == NULL_TREE)
!     {
!       *walk_subtrees = 0;
!       return NULL_TREE;
!     }
  
    if (TREE_CODE (t) == DECL_STMT)
      {
--- 151,157 ----
    tree t = *tp;
  
    if (t == NULL_TREE)
!     return (tree) 1;
  
    if (TREE_CODE (t) == DECL_STMT)
      {


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