]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/82275 (gfortran rejects valid & accepts invalid reference to dimension...
authorPaul Thomas <pault@gcc.gnu.org>
Sun, 20 May 2018 17:16:09 +0000 (17:16 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sun, 20 May 2018 17:16:09 +0000 (17:16 +0000)
2018-05-20  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/82275
Backport from trunk
* match.c (gfc_match_type_spec): Go through the array ref and
decrement 'rank' for every dimension that is an element.

2018-05-20  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/82275
Backport from trunk
* gfortran.dg/select_type_42.f90: New test.

From-SVN: r260423

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

index be2983527a0d64f57c6c6078ea7d36edf526b497..ebb6806a530bc1b53f79abcdc35f7a63e7cec841 100644 (file)
@@ -1,3 +1,10 @@
+2018-05-20  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/82275
+       Backport from trunk
+       * match.c (gfc_match_type_spec): Go through the array ref and
+       decrement 'rank' for every dimension that is an element.
+
 2018-05-19  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/82923
index 682f7b021b0d485c65047768089de0c9a9a0f134..89fb43dc04859465c7363573e96e257a34f2c27b 100644 (file)
@@ -2063,7 +2063,7 @@ gfc_match_type_spec (gfc_typespec *ts)
      or list item in a type-list of an OpenMP reduction clause.  Need to
      differentiate REAL([KIND]=scalar-int-initialization-expr) from
      REAL(A,[KIND]) and REAL(KIND,A).  Logically, when this code was
-     written the use of LOGICAL as a type-spec or intrinsic subprogram 
+     written the use of LOGICAL as a type-spec or intrinsic subprogram
      was overlooked.  */
 
   m = gfc_match (" %n", name);
@@ -5714,6 +5714,7 @@ copy_ts_from_selector_to_associate (gfc_expr *associate, gfc_expr *selector)
 {
   gfc_ref *ref;
   gfc_symbol *assoc_sym;
+  int rank = 0;
 
   assoc_sym = associate->symtree->n.sym;
 
@@ -5750,14 +5751,28 @@ copy_ts_from_selector_to_associate (gfc_expr *associate, gfc_expr *selector)
        selector->rank = ref->u.ar.dimen;
       else
        selector->rank = 0;
+
+      rank = selector->rank;
     }
 
-  if (selector->rank)
+  if (rank)
     {
-      assoc_sym->attr.dimension = 1;
-      assoc_sym->as = gfc_get_array_spec ();
-      assoc_sym->as->rank = selector->rank;
-      assoc_sym->as->type = AS_DEFERRED;
+      for (int i = 0; i < ref->u.ar.dimen + ref->u.ar.codimen; i++)
+       if (ref->u.ar.dimen_type[i] == DIMEN_ELEMENT
+           || (ref->u.ar.dimen_type[i] == DIMEN_UNKNOWN
+               && ref->u.ar.end[i] == NULL
+               && ref->u.ar.stride[i] == NULL))
+         rank--;
+
+      if (rank)
+       {
+         assoc_sym->attr.dimension = 1;
+         assoc_sym->as = gfc_get_array_spec ();
+         assoc_sym->as->rank = rank;
+         assoc_sym->as->type = AS_DEFERRED;
+       }
+      else
+       assoc_sym->as = NULL;
     }
   else
     assoc_sym->as = NULL;
index 8f28314fd708753b2a8c8aa34715b498a5a73841..5f7d356fac112996d477a8714ae2d4b4fad090f0 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-20  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/82275
+       Backport from trunk
+       * gfortran.dg/select_type_42.f90: New test.
+
 2018-05-19  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/82923
diff --git a/gcc/testsuite/gfortran.dg/select_type_42.f90 b/gcc/testsuite/gfortran.dg/select_type_42.f90
new file mode 100644 (file)
index 0000000..ff73e6c
--- /dev/null
@@ -0,0 +1,26 @@
+! { dg-do run }
+!
+! Tests the fix for PR82275.
+! Associating a name with a reduced-dimension section of a
+! multidimensional array precluded subsequent use of the name
+! with the appropriately reduced dimensionality and instead
+! required use of the (invalid) full set of original dimensions.
+!
+! Contributed by Damian Rouson  <damian@sourceryinstitute.org>
+!
+  type component
+   integer :: i
+  end type
+  type container
+    class(component), allocatable :: component_array(:,:)
+  end type
+  type(container) bag
+  type(component) section_copy
+  allocate(bag%component_array, source = reshape ([component(10), component (100)], [1,2]))
+  select type(associate_name=>bag%component_array(1,:))
+    type is (component)
+      section_copy = associate_name(2)  ! gfortran rejected valid
+!      section_copy = associate_name(1,1)! gfortran accepted invalid
+  end select
+  if (section_copy%i .ne. 100) stop 1
+end