From 927171bfea8858306c990c51a61dd413006141d2 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Tue, 2 Oct 2007 08:12:11 +0000 Subject: [PATCH] re PR fortran/33566 (fortran : wrong rank of derived type parameters array components) 2007-10-02 Paul Thomas PR fortran/33566 * primary.c (gfc_match_rvalue): Make all expressions with array references to structure parameters into variable expressions. 2007-10-02 Paul Thomas PR fortran/33566 * gfortran.dg/derived_comp_array_ref_5.f90: New test. From-SVN: r128951 --- gcc/fortran/ChangeLog | 6 ++++ gcc/fortran/primary.c | 13 ++++---- gcc/testsuite/ChangeLog | 5 +++ .../gfortran.dg/derived_comp_array_ref_5.f90 | 36 ++++++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/derived_comp_array_ref_5.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 5af0989..49dec96 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,5 +1,11 @@ 2007-10-02 Paul Thomas + PR fortran/33566 + * primary.c (gfc_match_rvalue): Make all expressions with array + references to structure parameters into variable expressions. + +2007-10-02 Paul Thomas + PR fortran/33554 * trans-decl.c (init_intent_out_dt): New function. (gfc_trans_deferred_vars): Remove the code for default diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index 575a4c7..d5e4b64 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2148,18 +2148,17 @@ gfc_match_rvalue (gfc_expr **result) if (sym->ts.is_c_interop || sym->ts.is_iso_c) break; - /* Variable array references to use associated derived type - parameters cause all sorts of headaches in simplification. - For this reason, we write the parameter to the module and - treat them as variable references. */ - if (sym->value && sym->ts.type == BT_DERIVED - && sym->attr.use_assoc && e->ref) + /* Variable array references to derived type parameters cause + all sorts of headaches in simplification. Treating such + expressions as variable works just fine for all array + references. */ + if (sym->value && sym->ts.type == BT_DERIVED && e->ref) { for (ref = e->ref; ref; ref = ref->next) if (ref->type == REF_ARRAY) break; - if (ref == NULL) + if (ref == NULL || ref->u.ar.type == AR_FULL) break; ref = e->ref; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6218703..cb8dabb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2007-10-02 Paul Thomas + PR fortran/33566 + * gfortran.dg/derived_comp_array_ref_5.f90: New test. + +2007-10-02 Paul Thomas + PR fortran/33554 * gfortran.dg/intent_out_2.f90: New test. diff --git a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_5.f90 b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_5.f90 new file mode 100644 index 0000000..3b0c279 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_5.f90 @@ -0,0 +1,36 @@ +! { dg-do compile } +! Tests the fix for PR33566, in which the first variable array ref +! to v1 would cause an incompatible ranks error and the second an ICE. +! +! Contributed by Mikael Morin +! + program test_vec + + implicit none + + + integer :: i + real :: x + + type vec3 + real, dimension(3) :: coords + end type vec3 + + type(vec3),parameter :: v1 = vec3((/ 1.0, 2.0, 3.0 /)) + type(vec3) :: v2 + + v2 = vec3((/ 1.0, 2.0, 3.0 /)) + + + x = v1%coords(1) + + do i=1,3 + x = v1%coords(i) ! used to fail + x = v2%coords(i) + end do + + i = 2 + + v2 = vec3 (v1%coords ((/i+1, i, i-1/))) ! also broken + + end program test_vec -- 2.7.4