Automatic arrays aren't allowed in EQUIVALENCE

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Automatic arrays aren't allowed in EQUIVALENCE

gcc - fortran mailing list
Consider,

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

One of these subroutines contains two errors that violate a constraint.
gfortran happily compiles the above.  This seems to fix the problem.


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (revision 280157)
+++ gcc/fortran/resolve.c (working copy)
@@ -16820,7 +16820,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;
 
@@ -16828,8 +16829,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);

PS: I'm no longer subscribed to fortran@, so if you wish to ask me
question make to Reply-to-all.

--
Steve