[tree-ssa] Two minor bugfixes

law@redhat.com law@redhat.com
Fri Feb 27 20:30:00 GMT 2004


My fold-const.c changes from yesterday had a couple bugs.  First they
failed to handle aliased symbols.  Opps.  Second, if either symbol is
extern, then we may not be able to get to their attributes and thus
do not know if it is aliased (and thus we must assume that it could
be aliased).

The second change is a variation of a patch Jan sent in December.
Basically the inliner can create non-gimple expressions.  We haven't
seen a failure due to this, but I'd rather fix the bug now than wait
for someone to trip over it.

Bootstrapped and regression tests i686-pc-linux-gnu.

	* fold-const.c (fold): Tighten test for optimizing an equality
	comparison of the address of two variables.

	* tree-inline.c (setup_one_parameter): Improve test for when we
	need to gimplify the initialization statements.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.73
diff -c -p -r1.213.2.73 fold-const.c
*** fold-const.c	26 Feb 2004 19:15:21 -0000	1.213.2.73
--- fold-const.c	27 Feb 2004 18:37:34 -0000
*************** fold (tree expr)
*** 7181,7195 ****
  	    return integer_one_node;
  	}
  
!       /* If this is an equality comparison of the address of two non-weak
! 	 symbols, then we know the result.  */
        if ((code == EQ_EXPR || code == NE_EXPR)
  	  && TREE_CODE (arg0) == ADDR_EXPR
  	  && DECL_P (TREE_OPERAND (arg0, 0))
  	  && ! DECL_WEAK (TREE_OPERAND (arg0, 0))
  	  && TREE_CODE (arg1) == ADDR_EXPR
  	  && DECL_P (TREE_OPERAND (arg1, 0))
! 	  && ! DECL_WEAK (TREE_OPERAND (arg1, 0)))
  	{
  	  if (code == EQ_EXPR)
  	    return (operand_equal_p (arg0, arg1, 0)
--- 7181,7202 ----
  	    return integer_one_node;
  	}
  
!       /* If this is an equality comparison of the address of two non-weak,
! 	 unaliased symbols neither of which are extern (since we do not
! 	 have access to attributes for externs), then we know the result.  */
        if ((code == EQ_EXPR || code == NE_EXPR)
  	  && TREE_CODE (arg0) == ADDR_EXPR
  	  && DECL_P (TREE_OPERAND (arg0, 0))
  	  && ! DECL_WEAK (TREE_OPERAND (arg0, 0))
+ 	  && ! lookup_attribute ("alias",
+ 				 DECL_ATTRIBUTES (TREE_OPERAND (arg0, 0)))
+ 	  && DECL_EXTERNAL (TREE_OPERAND (arg0, 0))
  	  && TREE_CODE (arg1) == ADDR_EXPR
  	  && DECL_P (TREE_OPERAND (arg1, 0))
! 	  && ! DECL_WEAK (TREE_OPERAND (arg1, 0))
! 	  && ! lookup_attribute ("alias",
! 				 DECL_ATTRIBUTES (TREE_OPERAND (arg1, 0)))
! 	  && DECL_EXTERNAL (TREE_OPERAND (arg1, 0)))
  	{
  	  if (code == EQ_EXPR)
  	    return (operand_equal_p (arg0, arg1, 0)
Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.26.2.85
diff -c -p -r1.26.2.85 tree-inline.c
*** tree-inline.c	16 Feb 2004 15:29:55 -0000	1.26.2.85
--- tree-inline.c	27 Feb 2004 18:37:46 -0000
*************** setup_one_parameter (inline_data *id, tr
*** 788,797 ****
        init_stmt = build (MODIFY_EXPR, TREE_TYPE (var), var, rhs);
        append_to_statement_list (init_stmt, init_stmts);
  
!       /* If the conversion needed to assign VALUE to VAR is not a
! 	 GIMPLE expression, flag that we will need to gimplify
! 	 INIT_STMTS at the end.  */
!       if (!is_gimple_rhs (rhs))
  	*gimplify_init_stmts_p = true;
      }
  }
--- 788,801 ----
        init_stmt = build (MODIFY_EXPR, TREE_TYPE (var), var, rhs);
        append_to_statement_list (init_stmt, init_stmts);
  
!       /* If we did not create a gimple value and we did not create a gimple
! 	 cast of a gimple value, then we will need to gimplify INIT_STMTS
! 	 at the end.  Note that is_gimple_cast only checks the outer
! 	 tree code, not its operand.  Thus the explicit check that it's
! 	 operand is a gimple value.  */
!       if (!is_gimple_val (rhs)
! 	  && (!is_gimple_cast (rhs)
! 	      || !is_gimple_val (TREE_OPERAND (rhs, 0))))
  	*gimplify_init_stmts_p = true;
      }
  }







More information about the Gcc-patches mailing list