From af3da717d627fbd4b6658ea72d443bd0f29f08ee Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Sat, 9 Feb 2019 11:11:33 +0000 Subject: [PATCH] re PR fortran/89200 (Erroneous copying of a derived type with a deferred-length character array component) 2019-02-09 Paul Thomas PR fortran/89200 * trans-array.c (gfc_trans_create_temp_array): Set the 'span' field for derived types. 2019-02-09 Paul Thomas PR fortran/89200 * gfortran.dg/array_reference_2.f90 : New test. From-SVN: r268721 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-array.c | 9 +++++++++ gcc/testsuite/ChangeLog | 5 +++++ .../gfortran.dg/array_reference_2.f90 | 20 +++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/array_reference_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 03278652e11..96cb70e51a9 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-02-09 Paul Thomas + + PR fortran/89200 + * trans-array.c (gfc_trans_create_temp_array): Set the 'span' + field for derived types. + 2019-02-04 Harald Anlauf PR fortran/89077 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 2527950aacb..f15d3a37937 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -1293,6 +1293,15 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, gfc_ss * ss, tmp = gfc_conv_descriptor_dtype (desc); gfc_add_modify (pre, tmp, gfc_get_dtype (TREE_TYPE (desc))); + /* Also set the span for derived types, since they can be used in + component references to arrays of this type. */ + if (TREE_CODE (eltype) == RECORD_TYPE) + { + tmp = TYPE_SIZE_UNIT (eltype); + tmp = fold_convert (gfc_array_index_type, tmp); + gfc_conv_descriptor_span_set (pre, desc, tmp); + } + /* Fill in the bounds and stride. This is a packed array, so: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dd887d35378..d9b9ccbfcce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-02-09 Paul Thomas + + PR fortran/89200 + * gfortran.dg/array_reference_2.f90 : New test. + 2019-02-09 Jakub Jelinek PR middle-end/89246 diff --git a/gcc/testsuite/gfortran.dg/array_reference_2.f90 b/gcc/testsuite/gfortran.dg/array_reference_2.f90 new file mode 100644 index 00000000000..6ec65ebb541 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_reference_2.f90 @@ -0,0 +1,20 @@ +! { dg-do run } +! +! Test the fix for PR89200, in which the indexing did not work in +! the write statement below. +! +! Contributed by Damian Rouson +! + type foo + character(len=:), allocatable :: string + end type + type foo_list + type(foo), allocatable :: entry(:) + end type + type(foo_list) list + character(4) :: buffer + list = foo_list([foo('12'), foo('34')]) + write(buffer, '(2a2)') list%entry(1)%string, list%entry(2)%string + if (buffer .ne. '1234') stop 1 + deallocate (list%entry) +end -- 2.30.2