gfortran seems to miscalculate the rank when trying to get a component of an array member of a derived type parameter. I think that the following program explains better than my cryptic explanations : 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) ! works do i=1,3 x = v1%coords(i) ! fails x = v2%coords(i) ! works end do end program test_vec Here is the error returned ... $ gfortran -c test.f test.f:27.9: x = v1%coords(i) ! fails 1 Error: Incompatible ranks 0 and 1 in assignment at (1) ... and the version of gfortran used : $ gfortran -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../gcc-svn/gcc/configure --enable-languages=fortran : (reconfigured) ../gcc-svn/gcc/configure --enable-languages=fortran : (reconfigured) ../gcc-svn/gcc/configure --enable-languages=fortran Thread model: posix gcc version 4.3.0 20070926 (experimental) (GCC)
It transpires that the fix that I used for use associated, derived type parameters works here too: Index: gcc/fortran/primary.c =================================================================== *** gcc/fortran/primary.c (révision 128833) --- gcc/fortran/primary.c (copie de travail) *************** gfc_match_rvalue (gfc_expr **result) *** 2148,2159 **** 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) { for (ref = e->ref; ref; ref = ref->next) if (ref->type == REF_ARRAY) --- 2148,2157 ---- if (sym->ts.is_c_interop || sym->ts.is_iso_c) break; ! /* Variable array references to derived type parameters cause ! all sorts of headaches in simplification. For this reason, ! we treat them as variable references. */ ! if (sym->value && sym->ts.type == BT_DERIVED && e->ref) { for (ref = e->ref; ref; ref = ref->next) if (ref->type == REF_ARRAY) I'll regtest and submit it. Cheers Paul.
(In reply to comment #1) This causes one regression - data_components_1.f90. I either have to check if the reference is not constant or to try to simplify the expression and see if the result is constant. Paul
(In reply to comment #2) I take that back - I had to copy the patch by hand and, inevitably, got it wrong. I'll regtest over again and then submit it. Je te remercie, Mikael! Paul
Subject: Bug number PR33566 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-09/msg02054.html
Subject: Bug 33566 Author: pault Date: Tue Oct 2 08:12:11 2007 New Revision: 128951 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128951 Log: 2007-10-02 Paul Thomas <pault@gcc.gnu.org> 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 <pault@gcc.gnu.org> PR fortran/33566 * gfortran.dg/derived_comp_array_ref_5.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/derived_comp_array_ref_5.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/primary.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk Paul