Patchwork [fortran] PR45081 - [4.3/4.4/4.5/4.6 Regression] ICE in gfc_conv_array_initializer, at fortran/trans-array.c:4208

login
register
mail settings
Submitter Paul Richard Thomas
Date Sept. 20, 2010, 6:40 a.m.
Message ID <AANLkTikF-n__AOxCOmh-ARSNX9fPs2dRvA952jnoCCZF@mail.gmail.com>
Download mbox | patch
Permalink /patch/65182/
State New
Headers show

Comments

Paul Richard Thomas - Sept. 20, 2010, 6:40 a.m.
Dear All,

This patch is quite straightforward and, together with the ChangeLogs,
is self-explanatory.  The testcase now simplifies all the intrinsic
expressions and evaluates the result to be 50.  That it compiles at
all is already test enough but, in addition, the correct result is
tested for.

Bootstrapped and regtested on FC9/x86_64 - OK for trunk?  How far back
to I fix the regression?

Cheers

Paul

2010-09-20  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/45081
	* simplify.c (is_constant_array_expr): Allow structure array
	elements as well as constants.
	(gfc_simplify_pack, gfc_simplify_reshape, gfc_simplify_spread,
	gfc_simplify_transpose, gfc_simplify_unpack): Copy the derived
	type of source to the result.

2010-09-20  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/45081
	* gfortran.dg/derived_array_intrinsics_1.f90 : New test.
Mikael Morin - Sept. 20, 2010, 9:15 a.m.
On Monday 20 September 2010 08:40:09 Paul Richard Thomas wrote:
> Dear All,
> 
> This patch is quite straightforward and, together with the ChangeLogs,
> is self-explanatory.  The testcase now simplifies all the intrinsic
> expressions and evaluates the result to be 50.  That it compiles at
> all is already test enough but, in addition, the correct result is
> tested for.
> 
> Bootstrapped and regtested on FC9/x86_64 - OK for trunk? 
OK.

> How far back
> to I fix the regression?
If it is a 4.3/4.4/4.5/4.6 regression, I would say fix on all branches. 
But if you don't have the courage/feel it's not worth it, you can stop on 4.4 
or 4.5. 
From my point of view having the fix on:
 - 4.5 is mandatory (PR has target milestone 4.5.2), 
 - 4.4 is nice to have, 
 - 4.3 is optional.

> 
> Cheers
> 
> Paul
> 
Thanks.

Mikael

Patch

Index: gcc/fortran/simplify.c
===================================================================
*** gcc/fortran/simplify.c	(revision 164288)
--- gcc/fortran/simplify.c	(working copy)
*************** is_constant_array_expr (gfc_expr *e)
*** 235,241 ****
  
    for (c = gfc_constructor_first (e->value.constructor);
         c; c = gfc_constructor_next (c))
!     if (c->expr->expr_type != EXPR_CONSTANT)
        return false;
  
    return true;
--- 235,242 ----
  
    for (c = gfc_constructor_first (e->value.constructor);
         c; c = gfc_constructor_next (c))
!     if (c->expr->expr_type != EXPR_CONSTANT
! 	  && c->expr->expr_type != EXPR_STRUCTURE)
        return false;
  
    return true;
*************** gfc_simplify_pack (gfc_expr *array, gfc_
*** 4550,4555 ****
--- 4551,4558 ----
      return NULL;
  
    result = gfc_get_array_expr (array->ts.type, array->ts.kind, &array->where);
+   if (array->ts.type == BT_DERIVED)
+     result->ts.u.derived = array->ts.u.derived;
  
    array_ctor = gfc_constructor_first (array->value.constructor);
    vector_ctor = vector
*************** gfc_simplify_reshape (gfc_expr *source, 
*** 4982,4987 ****
--- 4985,4992 ----
  
    result = gfc_get_array_expr (source->ts.type, source->ts.kind,
  			       &source->where);
+   if (source->ts.type == BT_DERIVED)
+     result->ts.u.derived = source->ts.u.derived;
    result->rank = rank;
    result->shape = gfc_get_shape (rank);
    for (i = 0; i < rank; i++)
*************** gfc_simplify_spread (gfc_expr *source, g
*** 5732,5737 ****
--- 5737,5744 ----
  
        result = gfc_get_array_expr (source->ts.type, source->ts.kind,
  				   &source->where);
+       if (source->ts.type == BT_DERIVED)
+ 	result->ts.u.derived = source->ts.u.derived;
        result->rank = 1;
        result->shape = gfc_get_shape (result->rank);
        mpz_init_set_si (result->shape[0], ncopies);
*************** gfc_simplify_spread (gfc_expr *source, g
*** 5750,5755 ****
--- 5757,5764 ----
  
        result = gfc_get_array_expr (source->ts.type, source->ts.kind,
  				   &source->where);
+       if (source->ts.type == BT_DERIVED)
+ 	result->ts.u.derived = source->ts.u.derived;
        result->rank = source->rank + 1;
        result->shape = gfc_get_shape (result->rank);
  
*************** gfc_simplify_transpose (gfc_expr *matrix
*** 6038,6043 ****
--- 6047,6054 ----
  
    if (matrix->ts.type == BT_CHARACTER)
      result->ts.u.cl = matrix->ts.u.cl;
+   else if (matrix->ts.type == BT_DERIVED)
+     result->ts.u.derived = matrix->ts.u.derived;
  
    matrix_rows = mpz_get_si (matrix->shape[0]);
    matrix_cols = mpz_get_si (matrix->shape[1]);
*************** gfc_simplify_unpack (gfc_expr *vector, g
*** 6341,6346 ****
--- 6352,6359 ----
  
    result = gfc_get_array_expr (vector->ts.type, vector->ts.kind,
  			       &vector->where);
+   if (vector->ts.type == BT_DERIVED)
+     result->ts.u.derived = vector->ts.u.derived;
    result->rank = mask->rank;
    result->shape = gfc_copy_shape (mask->shape, mask->rank);
  
Index: gcc/testsuite/gfortran.dg/derived_array_intrinisics_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/derived_array_intrinisics_1.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/derived_array_intrinisics_1.f90	(revision 0)
***************
*** 0 ****
--- 1,30 ----
+ ! { dg-do compile }
+ ! { dg-options "-fdump-tree-original" }
+ ! Test the fix for PR45081 in which derived type array valued intrinsics failed
+ ! to simplify, which caused an ICE in trans-array.c
+ !
+ ! Contributed by Thorsten Ohl <ohl@physik.uni-wuerzburg.de>
+ ! 
+   module m
+     implicit none
+     integer :: i
+     type t
+       integer :: i
+     end type t
+     type(t), dimension(4), parameter :: t1  = [( t(i), i = 1, 4)]
+     type(t), dimension(4), parameter :: t2  = [( t(i), i = 8, 11)]
+     type(t), dimension(2,2), parameter :: a = reshape ( t1, [ 2, 2 ] )
+     type(t), dimension(2,2), parameter :: b = transpose (a)
+     type(t), dimension(4), parameter :: c = reshape ( b, [ 4 ] )
+     type(t), dimension(2), parameter :: d = pack ( c, [.false.,.true.,.false.,.true.])
+     type(t), dimension(4), parameter :: e = unpack (d, [.false.,.true.,.false.,.true.], t2)
+     type(t), dimension(4,2), parameter :: f = spread (e, 2, 2)
+     type(t), dimension(8), parameter :: g = reshape ( f, [ 8 ] )
+     integer, parameter :: total = sum(g%i)
+   end module m
+ 
+     use m
+     integer :: j
+     j = total
+   end
+ ! { dg-final { scan-tree-dump-times "j = 50" 1 "original" } }