diff mbox

PR tree-optimization/45598 (build_int_cst_wide ICE)

Message ID 20100908230602.GA21068@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka Sept. 8, 2010, 11:06 p.m. UTC
Hi,
this patch fix ICE when we try to fold array_ref of string where result itself
is array of size 1.
We might actually fold this into one element constructor, but we seem to be
folding this well the other way around - first folding the nested array
references and then fold into the actual value.

Bootstrapped/regtested x86_64-linux, OK?

Honza

	PR tree-optimize/45598
	* tree-ssa-ccp.c (fold_const_aggregate_ref): Check that result of
	string folding is of integral type.
	* fortran.fortran-torture/compile/pr45598.f90: New test.

Comments

Richard Biener Sept. 9, 2010, 8:30 a.m. UTC | #1
On Thu, 9 Sep 2010, Jan Hubicka wrote:

> Hi,
> this patch fix ICE when we try to fold array_ref of string where result itself
> is array of size 1.
> We might actually fold this into one element constructor, but we seem to be
> folding this well the other way around - first folding the nested array
> references and then fold into the actual value.
> 
> Bootstrapped/regtested x86_64-linux, OK?

Ok.

Thanks,
Richard.

> Honza
> 
> 	PR tree-optimize/45598
> 	* tree-ssa-ccp.c (fold_const_aggregate_ref): Check that result of
> 	string folding is of integral type.
> 	* fortran.fortran-torture/compile/pr45598.f90: New test.
> 
> Index: testsuite/gfortran.fortran-torture/compile/pr45598.f90
> ===================================================================
> --- testsuite/gfortran.fortran-torture/compile/pr45598.f90	(revision 0)
> +++ testsuite/gfortran.fortran-torture/compile/pr45598.f90	(revision 0)
> @@ -0,0 +1,13 @@
> +program main
> +implicit none
> +character(len=10) :: digit_string = '123456789'
> +character :: digit_arr(10)
> +call copy(digit_string, digit_arr)
> +print '(1x, a1)',digit_arr(1:9)
> +contains
> +  subroutine copy(in, out)
> +    character, dimension(10) :: in, out
> +    out(1:10) = in(1:10)
> +  end subroutine copy
> +end program main
> +
> Index: tree-ssa-ccp.c
> ===================================================================
> --- tree-ssa-ccp.c	(revision 164002)
> +++ tree-ssa-ccp.c	(working copy)
> @@ -1398,8 +1397,7 @@ fold_const_aggregate_ref (tree t)
>  	}
>  
>        /* Fold read from constant string.  */
> -      if (TREE_CODE (ctor) == STRING_CST
> -	  && TREE_CODE (idx) == INTEGER_CST)
> +      if (TREE_CODE (ctor) == STRING_CST)
>  	{
>  	  tree low_bound = array_ref_low_bound (t);
>  	  double_int low_bound_cst;
> @@ -1407,7 +1405,9 @@ fold_const_aggregate_ref (tree t)
>  	  double_int length_cst;
>  	  bool signed_p = TYPE_UNSIGNED (TREE_TYPE (idx));
>  
> -	  if (TREE_CODE (low_bound) != INTEGER_CST)
> +	  if (TREE_CODE (idx) != INTEGER_CST
> +	      || !INTEGRAL_TYPE_P (TREE_TYPE (t))
> +	      || TREE_CODE (low_bound) != INTEGER_CST)
>  	    return NULL_TREE;
>  	  low_bound_cst = tree_to_double_int (low_bound);
>  	  index_cst = tree_to_double_int (idx);
> 
>
diff mbox

Patch

Index: testsuite/gfortran.fortran-torture/compile/pr45598.f90
===================================================================
--- testsuite/gfortran.fortran-torture/compile/pr45598.f90	(revision 0)
+++ testsuite/gfortran.fortran-torture/compile/pr45598.f90	(revision 0)
@@ -0,0 +1,13 @@ 
+program main
+implicit none
+character(len=10) :: digit_string = '123456789'
+character :: digit_arr(10)
+call copy(digit_string, digit_arr)
+print '(1x, a1)',digit_arr(1:9)
+contains
+  subroutine copy(in, out)
+    character, dimension(10) :: in, out
+    out(1:10) = in(1:10)
+  end subroutine copy
+end program main
+
Index: tree-ssa-ccp.c
===================================================================
--- tree-ssa-ccp.c	(revision 164002)
+++ tree-ssa-ccp.c	(working copy)
@@ -1398,8 +1397,7 @@  fold_const_aggregate_ref (tree t)
 	}
 
       /* Fold read from constant string.  */
-      if (TREE_CODE (ctor) == STRING_CST
-	  && TREE_CODE (idx) == INTEGER_CST)
+      if (TREE_CODE (ctor) == STRING_CST)
 	{
 	  tree low_bound = array_ref_low_bound (t);
 	  double_int low_bound_cst;
@@ -1407,7 +1405,9 @@  fold_const_aggregate_ref (tree t)
 	  double_int length_cst;
 	  bool signed_p = TYPE_UNSIGNED (TREE_TYPE (idx));
 
-	  if (TREE_CODE (low_bound) != INTEGER_CST)
+	  if (TREE_CODE (idx) != INTEGER_CST
+	      || !INTEGRAL_TYPE_P (TREE_TYPE (t))
+	      || TREE_CODE (low_bound) != INTEGER_CST)
 	    return NULL_TREE;
 	  low_bound_cst = tree_to_double_int (low_bound);
 	  index_cst = tree_to_double_int (idx);