From b7030583668444ba31166a983aaee65c5ba34c10 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Thu, 9 Dec 2010 14:30:59 +0100 Subject: [PATCH] re PR fortran/45081 (ICE in gfc_conv_array_initializer, at fortran/trans-array.c:4208) 2010-12-09 Paul Thomas PR fortran/45081 * simplify.c (is_constant_array_expr): Allow structure array elements as well as constants. (gfc_simplify_reshape): Copy the derived type of source to the result. 2010-12-09 Paul Thomas PR fortran/45081 * gfortran.dg/derived_array_intrinsics_1.f90 : New test. From-SVN: r167637 --- gcc/fortran/ChangeLog | 8 +++++ gcc/fortran/simplify.c | 8 ++++- gcc/testsuite/ChangeLog | 11 +++++-- .../derived_array_intrinisics_1.f90 | 33 +++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/derived_array_intrinisics_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 8d20a58dd5ec..4e1f70bae227 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2010-12-09 Paul Thomas + + PR fortran/45081 + * simplify.c (is_constant_array_expr): Allow structure array + elements as well as constants. + (gfc_simplify_reshape): Copy the derived type of source to + the result. + 2010-05-22 Release Manager * GCC 4.3.5 released. diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index ac43b392415b..40b3aec15a54 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -3257,7 +3257,8 @@ is_constant_array_expr (gfc_expr *e) return false; for (c = e->value.constructor; c; c = c->next) - if (c->expr->expr_type != EXPR_CONSTANT) + if (c->expr->expr_type != EXPR_CONSTANT + && c->expr->expr_type != EXPR_STRUCTURE) return false; return true; @@ -3486,6 +3487,11 @@ inc: e->ts = source->ts; e->rank = rank; + if (source->ts.type == BT_CHARACTER) + e->ts.cl = source->ts.cl; + else if (source->ts.type == BT_DERIVED) + e->ts.derived = source->ts.derived; + return e; bad_reshape: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0c7afc6cc8b5..4f35e3d72c91 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-12-09 Paul Thomas + + PR fortran/45081 + * gfortran.dg/derived_array_intrinsics_1.f90: New test. + 2010-12-02 Richard Guenther Ira Rosen @@ -61,9 +66,9 @@ 2010-04-27 Richard Guenther - Backport from mainline: - 2010-03-19 Michael Matz - + Backport from mainline: + 2010-03-19 Michael Matz + PR c++/43116 * g++.dg/other/pr43116.C: New testcase. diff --git a/gcc/testsuite/gfortran.dg/derived_array_intrinisics_1.f90 b/gcc/testsuite/gfortran.dg/derived_array_intrinisics_1.f90 new file mode 100644 index 000000000000..7d8bbce3f0b0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/derived_array_intrinisics_1.f90 @@ -0,0 +1,33 @@ +! { 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 +! +! Modified for GCC 4.4, which does not support (UN)PACK, TRANSPOSE or SPEAD +! as initialization expressions. + + 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 = a !transpose (a) + type(t), dimension(4), parameter :: c = reshape ( b, [ 4 ] ) + type(t), dimension(2), parameter :: d = c([2,4]) !pack ( c, [.false.,.true.,.false.,.true.]) + type(t), dimension(4), parameter :: e = c !unpack (d, [.false.,.true.,.false.,.true.], t2) + type(t), dimension(4,2), parameter :: f = reshape([c,c],[4,2]) !spread (e, 2, 2) + type(t), dimension(8), parameter :: g = reshape ( f, [ 8 ] ) + integer, parameter :: total = g(3)%i + end module m + + use m + integer :: j + j = total + end +! { dg-final { scan-tree-dump-times "j = 3" 1 "original" } } -- 2.47.2