]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/33566 (fortran : wrong rank of derived type parameters array components)
authorPaul Thomas <pault@gcc.gnu.org>
Tue, 2 Oct 2007 08:12:11 +0000 (08:12 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Tue, 2 Oct 2007 08:12:11 +0000 (08:12 +0000)
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.

From-SVN: r128951

gcc/fortran/ChangeLog
gcc/fortran/primary.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/derived_comp_array_ref_5.f90 [new file with mode: 0644]

index 5af0989013d2e51f042944f058ba0a20f6762203..49dec96c757d5de329364e64a8a277e810ce8918 100644 (file)
@@ -1,3 +1,9 @@
+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/33554
index 575a4c7411ae287cd4b605a0eb3479910ad517e8..d5e4b64d26ed32ec1f26e96a77562d113551bc18 100644 (file)
@@ -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;
index 62187039a5dbf39c6a3c3681e8d411b47f617705..cb8dabb126cea501a91cf1692f8a80eab13e36fd 100644 (file)
@@ -1,3 +1,8 @@
+2007-10-02  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/33566
+       * gfortran.dg/derived_comp_array_ref_5.f90: New test.
+
 2007-10-02  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/33554
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 (file)
index 0000000..3b0c279
--- /dev/null
@@ -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 <mikael.morin@tele2.fr>
+!
+      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