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]

[tree-ssa] PATCH for c++/13865


This bug was another example of the strange nesting behavior in the C/C++
frontend trees.  A cleanup in the FOR_INIT_STMT actually wraps the loop.
This patch changes the C gimplifier to reorganize the trees to express that
better.

Tested on athlon-pc-linux-gnu, applied to tree-ssa.
Test in g++.dg/init/for1.C

2004-01-29  Jason Merrill  <jason@redhat.com>

	PR c++/13865
	* c-simplify.c (gimplify_for_stmt): Reorganize to fix cleanups.

*** c-simplify.c.~1~	2003-12-18 16:15:41.000000000 -0500
--- c-simplify.c	2004-01-29 11:00:33.000000000 -0500
*************** c_gimplify_stmt (tree *stmt_p)
*** 213,219 ****
  	  break;
  
  	case FOR_STMT:
! 	  ret = gimplify_for_stmt (&stmt, &pre);
  	  break;
  
  	case WHILE_STMT:
--- 213,219 ----
  	  break;
  
  	case FOR_STMT:
! 	  ret = gimplify_for_stmt (&stmt, &next);
  	  break;
  
  	case WHILE_STMT:
*************** gimplify_c_loop (tree cond, tree body, t
*** 703,718 ****
     prequeue and hand off to gimplify_c_loop.  */
  
  static enum gimplify_status
! gimplify_for_stmt (tree *stmt_p, tree *pre_p)
  {
    tree stmt = *stmt_p;
- 
    tree init = FOR_INIT_STMT (stmt);
-   c_gimplify_stmt (&init);
-   append_to_statement_list (init, pre_p);
  
!   *stmt_p = gimplify_c_loop (FOR_COND (stmt), FOR_BODY (stmt),
! 			     FOR_EXPR (stmt), 1);
  
    return GS_ALL_DONE;
  }
--- 703,728 ----
     prequeue and hand off to gimplify_c_loop.  */
  
  static enum gimplify_status
! gimplify_for_stmt (tree *stmt_p, tree *next_p)
  {
    tree stmt = *stmt_p;
    tree init = FOR_INIT_STMT (stmt);
  
!   if (init)
!     {
!       /* Reorganize the statements so that we do the right thing with a
! 	 CLEANUP_STMT.  We want the FOR_STMT and nothing else to be in the
! 	 scope of the cleanup, so play with pointers to accomplish that. */
!       FOR_INIT_STMT (stmt) = NULL_TREE;
!       chainon (init, stmt);
!       *stmt_p = init;
!       *next_p = TREE_CHAIN (stmt);
!       TREE_CHAIN (stmt) = NULL_TREE;
!       c_gimplify_stmt (stmt_p);
!     }
!   else
!     *stmt_p = gimplify_c_loop (FOR_COND (stmt), FOR_BODY (stmt),
! 			       FOR_EXPR (stmt), 1);
  
    return GS_ALL_DONE;
  }

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