[PATCH, middle-end] A less inrusive patch to fix PR 37861 (Bogus array bounds warning)

Martin Jambor mjambor@suse.cz
Tue Dec 2 14:33:00 GMT 2008


On Mon, Nov 10, 2008 at 10:57:30AM +0100, Martin Jambor wrote:
> Hi,
> 
> my previous patch to fix this issue
> (http://gcc.gnu.org/ml/gcc-patches/2008-11/msg00156.html) resulted in
> a regression on m32c-unknown-elf reported in
> http://gcc.gnu.org/ml/gcc/2008-11/msg00058.html.
> 
> Because we are quite late in  the development cycle and because my fix
> might have been a bit too  pessimistic as it was, this a revised, less
> restrictive patch that undoes my  previous one and then puts a bailout
> at a different place, this time only when a char array is indexed by a
> result of multiplication, which I assume is in fact a higher-dimension
> indexing.  Not a very systematic approach but I could not come up with
> anything better that would not break either PR 37861, PR 31982 and the
> m32c problem reported by DJ.
> 
> I have bootstraped and tested it on x86_64-suse-linux, (rev. 141686)
> OK for trunk?
> 
> Thanks,
> 
> Martin
> 
> 2008-11-10  Martin Jambor  <mjambor@suse.cz>
> 
> 	* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Do not check
> 	for INDIRECT_REFs.
> 	(forward_propagate_addr_into_variable_array_index): Check that the
> 	offset is not computed from a MULT_EXPR, use is_gimple_assign rather
> 	than the gimple code directly.
> 	

Committed as revision 142355.

Thanks,

Martin


> 
> Index: gcc/tree-ssa-forwprop.c
> ===================================================================
> --- gcc/tree-ssa-forwprop.c	(revision 141673)
> +++ gcc/tree-ssa-forwprop.c	(working copy)
> @@ -613,19 +613,27 @@ forward_propagate_addr_into_variable_arr
>    tree index;
>    gimple offset_def, use_stmt = gsi_stmt (*use_stmt_gsi);
>  
> -  /* Try to find an expression for a proper index.  This is either
> -     a multiplication expression by the element size or just the
> -     ssa name we came along in case the element size is one.  */
> +  /* Get the offset's defining statement.  */
> +  offset_def = SSA_NAME_DEF_STMT (offset);
> +
> +  /* Try to find an expression for a proper index.  This is either a
> +     multiplication expression by the element size or just the ssa name we came
> +     along in case the element size is one. In that case, however, we do not
> +     allow multiplications because they can be computing index to a higher
> +     level dimension (PR 37861). */
>    if (integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (def_rhs)))))
> -    index = offset;
> -  else
>      {
> -      /* Get the offset's defining statement.  */
> -      offset_def = SSA_NAME_DEF_STMT (offset);
> +      if (is_gimple_assign (offset_def)
> +	  && gimple_assign_rhs_code (offset_def) == MULT_EXPR)
> +	return false;
>  
> +      index = offset;
> +    }
> +  else
> +    {
>        /* The statement which defines OFFSET before type conversion
>           must be a simple GIMPLE_ASSIGN.  */
> -      if (gimple_code (offset_def) != GIMPLE_ASSIGN)
> +      if (!is_gimple_assign (offset_def))
>  	return false;
>  
>        /* The RHS of the statement which defines OFFSET must be a
> @@ -802,9 +810,6 @@ forward_propagate_addr_expr_1 (tree name
>    array_ref = TREE_OPERAND (def_rhs, 0);
>    if (TREE_CODE (array_ref) != ARRAY_REF
>        || TREE_CODE (TREE_TYPE (TREE_OPERAND (array_ref, 0))) != ARRAY_TYPE
> -      /* Avoid accessing hidden multidimensional arrays in this way or VRP
> -	 might give out bogus warnings (see PR 37861) */
> -      || TREE_CODE (TREE_OPERAND (array_ref, 0)) == INDIRECT_REF
>        || !integer_zerop (TREE_OPERAND (array_ref, 1)))
>      return false;
>  



More information about the Gcc-patches mailing list