]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: ICE equivalence with an element of an array PR94030
authorMark Eggleston <markeggleston@gcc.gnu.org>
Thu, 2 Apr 2020 07:26:34 +0000 (08:26 +0100)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Thu, 2 Apr 2020 07:26:34 +0000 (08:26 +0100)
Deferred size arrays can not be used in equivalance statements.

gcc/fortran/ChangeLog:

Backport from master
2020-04-02  Mark Eggleston <markeggleston@gcc.gnu.org>

PR fortran/94030
* resolve.c (resolve_equivalence): Correct formatting
around the label "identical_types".  Instead of using
gfc_resolve_array_spec use is_non_constants_shape_array
to determine whether the array can be used in a in an
equivalence statement.

gcc/testsuite/ChangeLog:

Backport from master
2020-04-02  Mark Eggleston <markeggleston@gcc.gnu.org>

PR fortran/94030
* gfortran.dg/pr94030_1.f90
* gfortran.dg/pr94030_2.f90

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr94030_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr94030_2.f90 [new file with mode: 0644]

index 99106cc39a08fa0c635016953067b71e3f991dfa..42b184e8864b8165f8b7d33b31702b58a31995ae 100644 (file)
@@ -1,3 +1,15 @@
+2020-04-02  Mark Eggleston <markeggleston@gcc.gnu.org>
+
+       Backport from master
+       2020-04-02  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/94030
+       * resolve.c (resolve_equivalence): Correct formatting
+       around the label "identical_types".  Instead of using
+       gfc_resolve_array_spec use is_non_constants_shape_array
+       to determine whether the array can be used in a in an
+       equivalence statement.
+
 2020-03-28  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline
index a4ad26efffc5ef4ba6613b42081dc136f0811bc2..a3df534180c6c8638d593a50b863ea3f4d69277e 100644 (file)
@@ -16510,7 +16510,8 @@ resolve_equivalence (gfc_equiv *eq)
          && !gfc_notify_std (GFC_STD_GNU, msg, sym->name, &e->where))
                continue;
 
-  identical_types:
+identical_types:
+
       last_ts =&sym->ts;
       last_where = &e->where;
 
@@ -16518,8 +16519,7 @@ resolve_equivalence (gfc_equiv *eq)
        continue;
 
       /* Shall not be an automatic array.  */
-      if (e->ref->type == REF_ARRAY
-         && !gfc_resolve_array_spec (e->ref->u.ar.as, 1))
+      if (e->ref->type == REF_ARRAY && is_non_constant_shape_array (sym))
        {
          gfc_error ("Array %qs at %L with non-constant bounds cannot be "
                     "an EQUIVALENCE object", sym->name, &e->where);
index fbf07ceb56ac2cb006d0f5f21c38658e25047ab8..93cb052ca9f5d0bac5d6508cc28e056d524d8f0f 100644 (file)
@@ -1,3 +1,13 @@
+2020-04-02  Mark Eggleston <markeggleston@gcc.gnu.org>
+
+       Backport from master
+       2020-04-02  Mark Eggleston <markeggleston@gcc.gnu.org>
+       Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/94030
+       * gfortran.dg/pr94030_1.f90: New test.
+       * gfortran.dg/pr94030_2.f90: New test.
+
 2020-04-01  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gfortran.dg/pr94030_1.f90 b/gcc/testsuite/gfortran.dg/pr94030_1.f90
new file mode 100644 (file)
index 0000000..e63d3cc
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+!
+
+subroutine f(n)
+  integer :: n
+  integer :: arr(n)
+  integer :: i
+  equivalence (i, arr(1))
+end
+
+! { dg-error "Array 'arr' at .1. with non-constant bounds cannot be an EQUIVALENCE object" " " { target *-*-* } 8 }
diff --git a/gcc/testsuite/gfortran.dg/pr94030_2.f90 b/gcc/testsuite/gfortran.dg/pr94030_2.f90
new file mode 100644 (file)
index 0000000..84bfdea
--- /dev/null
@@ -0,0 +1,33 @@
+! { dg-do compile }
+!
+! Provided by Steve Kargl.
+
+subroutine foo(n,m)
+  integer, intent(in) :: n, m
+  integer a(n)
+  real b(n)
+  equivalence(a,b)
+  if (m /= 2) then
+      a = 1
+      print *, a(1)
+  else
+      b = 42.
+      print *, b(1)
+   end if
+end subroutine 
+
+subroutine bar(m)
+  integer, intent(in) :: m
+  integer x(8)
+  real y(8)
+  equivalence(x,y)
+  if (m /= 2) then
+      x = 1
+      print *, x(1)
+  else
+      y = 42.
+      print *, y(1)
+   end if
+end subroutine 
+
+! { dg-error "Array '.' at .1. with non-constant bounds cannot be an EQUIVALENCE object" " " { target *-*-* } 9 }