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] Fix 20040317-1.c



20040317-1.c looks like:

int String2Array(int len, char strarr[][len])
{
  strarr[0];
}

[ This testcase is representative of 3-4 compile-time aborts/segfaults when
  using the tree-ssa compiler to build FC2.  In case anyone is wondering,
  we're just above a 95% build-pass rate for FC2 using tree-ssa after fixing
  many packages to avoid deprecated GCC extensions. ]



Note how we have a VLA as a parameter and the length of the VLA is also
a parameter.

So we end up creating a SAVE_EXPR for "len".  When we gimplify that we
create a new temporary, "len.0" which is initialized to "len" and use the
new temporary instead.

All fine and good except for the fact that the SAVE_EXPR is on the
PENDING_SIZES list.  Meaning that the tree-ssa analyzers and optimizers
never see the uses of "len.0".

So the first change is to note walk the PENDING_SIZES list looking for
objects which have hidden uses and mark them as such.  Note that retrieving
the PENDING_SIZE list clears the PENDING_SIZES list.  Egad.  So after
retrieving it, we need to make sure to restore the PENDING_SIZES list.  Ugh.

That was an improvement, but we still get aborts/segfaults with the testcase.
Why?  Because we expand the PENDING_SIZES list _before_ we expand the 
variables used by the current function.  Opps.  So we need to switch
the calls to expand_function_start and expand_vars.  Fine.  All the 
aborts/segfaults are gone.

While looking at this I realized that the copy renaming pass needs to
ignore copies/PHIs where the LHS has a hidden use.  That ensures that
the statement

len.0_XXX = len_YYY;

Is not turned into

len_XXX = len_YYY

And ultimately deleted.


Bootstrapped and regression tested on i686-pc-linux-gnu.

	* tree-dfa.c (find_hidden_use_vars): Also look inside the
	PENDING_SIZES list for hidden uses.
	* tree-optimize.c (tree_rest_of_compilation): Expand used variables
	before setting up parameters.
	* tree-ssa-copyrename.c (rename_ssa_copies): Do nothing for copies
	where the LHS has a hidden use.

Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.221
diff -c -p -r1.1.4.221 tree-dfa.c
*** tree-dfa.c	16 Mar 2004 22:31:55 -0000	1.1.4.221
--- tree-dfa.c	19 Mar 2004 17:16:32 -0000
*************** get_virtual_var (tree var)
*** 1000,1006 ****
  static void
  find_hidden_use_vars (tree block)
  {
!   tree sub, decl;
  
    /* Check all the arrays declared in the block for VLAs.
  
--- 1000,1006 ----
  static void
  find_hidden_use_vars (tree block)
  {
!   tree sub, decl, tem;
  
    /* Check all the arrays declared in the block for VLAs.
  
*************** find_hidden_use_vars (tree block)
*** 1015,1020 ****
--- 1015,1035 ----
    /* Now repeat the search in any sub-blocks.  */
    for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
      find_hidden_use_vars (sub);
+ 
+   /* A VLA parameter may use a variable which as set from another
+      parameter to declare the size of the VLA.  We need to mark the
+      variable as having a hidden use since it is used to declare the
+      VLA parameter and that declaration is not seen by the SSA code. 
+ 
+      Note get_pending_sizes clears the PENDING_SIZES chain, so we
+      must restore it. */
+   tem = get_pending_sizes ();
+   put_pending_sizes (tem);
+   for (; tem; tem = TREE_CHAIN (tem))
+     {
+       int inside_vla = 1;
+       walk_tree (&TREE_VALUE (tem), find_hidden_use_vars_r, &inside_vla, 
NULL);
+     }
  }
  
  /* Callback for walk_tree used by find_hidden_use_vars to analyze each 
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 1.1.4.133
diff -c -p -r1.1.4.133 tree-optimize.c
*** tree-optimize.c	12 Mar 2004 04:19:06 -0000	1.1.4.133
--- tree-optimize.c	19 Mar 2004 15:21:17 -0000
*************** tree_rest_of_compilation (tree fndecl, b
*** 534,544 ****
      walk_tree (&TREE_TYPE (fndecl), set_save_expr_context, fndecl,
  	       NULL);
  
    /* Set up parameters and prepare for return, for the function.  */
    expand_function_start (fndecl, 0);
- 
-   /* Expand the variables recorded during gimple lowering.  */
-   expand_used_vars ();
  
    /* Allow language dialects to perform special processing.  */
    (*lang_hooks.rtl_expand.start) ();
--- 534,547 ----
      walk_tree (&TREE_TYPE (fndecl), set_save_expr_context, fndecl,
  	       NULL);
  
+   /* Expand the variables recorded during gimple lowering.  This must
+      occur before the call to expand_function_start to ensure that
+      all used variables are expanded before we expand anything on the
+      PENDING_SIZES list.  */
+   expand_used_vars ();
+ 
    /* Set up parameters and prepare for return, for the function.  */
    expand_function_start (fndecl, 0);
  
    /* Allow language dialects to perform special processing.  */
    (*lang_hooks.rtl_expand.start) ();
Index: tree-ssa-copyrename.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-copyrename.c,v
retrieving revision 1.1.2.3
diff -c -p -r1.1.2.3 tree-ssa-copyrename.c
*** tree-ssa-copyrename.c	12 Mar 2004 04:19:06 -0000	1.1.2.3
--- tree-ssa-copyrename.c	19 Mar 2004 15:21:17 -0000
*************** rename_ssa_copies (void)
*** 274,282 ****
          {
            int i;
  	  tree res = PHI_RESULT (phi);
! 	  /* Dont process virtual SSA_NAMES.  */
! 	  if (!is_gimple_reg (SSA_NAME_VAR (res)))
  	    continue;
            for (i = 0; i < PHI_NUM_ARGS (phi); i++)
              {
                tree arg = PHI_ARG_DEF (phi, i);
--- 274,286 ----
          {
            int i;
  	  tree res = PHI_RESULT (phi);
! 
! 	  /* Do not process virtual SSA_NAMES or variables which have
! 	     hidden uses.  */
! 	  if (!is_gimple_reg (SSA_NAME_VAR (res))
! 	      || has_hidden_use (SSA_NAME_VAR (res)))
  	    continue;
+ 
            for (i = 0; i < PHI_NUM_ARGS (phi); i++)
              {
                tree arg = PHI_ARG_DEF (phi, i);
*************** rename_ssa_copies (void)
*** 294,300 ****
  	      tree lhs = TREE_OPERAND (stmt, 0);
  	      tree rhs = TREE_OPERAND (stmt, 1);
  
!               if (TREE_CODE (lhs) == SSA_NAME && TREE_CODE (rhs) == SSA_NAME)
  		copy_rename_partition_coalesce (map, lhs, rhs, debug);
  	    }
  	}
--- 298,306 ----
  	      tree lhs = TREE_OPERAND (stmt, 0);
  	      tree rhs = TREE_OPERAND (stmt, 1);
  
!               if (TREE_CODE (lhs) == SSA_NAME
! 		  && !has_hidden_use (SSA_NAME_VAR (lhs))
! 		  && TREE_CODE (rhs) == SSA_NAME)
  		copy_rename_partition_coalesce (map, lhs, rhs, debug);
  	    }
  	}



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