Patchwork [Fortran] Fix module I/O with assumed-rank arrays

login
register
mail settings
Submitter Tobias Burnus
Date July 26, 2012, 8:41 a.m.
Message ID <501102D4.6050300@net-b.de>
Download mbox | patch
Permalink /patch/173370/
State New
Headers show

Comments

Tobias Burnus - July 26, 2012, 8:41 a.m.
On 07/26/2012 10:00 AM, Mikael Morin wrote:
> I assume this sits on top of the previous patch? Then OK for both.

Yes. It was supposed to be a complete patch, but as I screwed up (git 
diff vs. git diff --cached, combined with git add), it was only an 
interdiff.

Thanks for the review. I committed it as Rev. 189881.

Tobias,
who should really avoid late-evening patches and feels the need for 
vacation.

Patch

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(revision 189880)
+++ gcc/fortran/ChangeLog	(working copy)
@@ -1,3 +1,9 @@ 
+2012-07-26  Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>
+	    Tobias Burnus  <burnus@net-b.de>
+
+	* module.c (mio_array_spec): Don't read as->lower for
+	assumed-rank arrays.
+
 2012-07-25  Tobias Burnus  <burnus@net-b.de>
 
 	* trans-types.c (gfc_real16_is_float128): Fix spelling
Index: gcc/fortran/module.c
===================================================================
--- gcc/fortran/module.c	(revision 189880)
+++ gcc/fortran/module.c	(working copy)
@@ -2359,9 +2359,15 @@ 
 
   if (iomode == IO_OUTPUT)
     {
+      int rank;
+
       if (*asp == NULL)
 	goto done;
       as = *asp;
+
+      /* mio_integer expects nonnegative values.  */
+      rank = as->rank > 0 ? as->rank : 0;
+      mio_integer (&rank);
     }
   else
     {
@@ -2372,20 +2378,23 @@ 
 	}
 
       *asp = as = gfc_get_array_spec ();
+      mio_integer (&as->rank);
     }
 
-  mio_integer (&as->rank);
   mio_integer (&as->corank);
   as->type = MIO_NAME (array_type) (as->type, array_spec_types);
 
+  if (iomode == IO_INPUT && as->type == AS_ASSUMED_RANK)
+    as->rank = -1;
   if (iomode == IO_INPUT && as->corank)
     as->cotype = (as->type == AS_DEFERRED) ? AS_DEFERRED : AS_EXPLICIT;
 
-  for (i = 0; i < as->rank + as->corank; i++)
-    {
-      mio_expr (&as->lower[i]);
-      mio_expr (&as->upper[i]);
-    }
+  if (as->rank > 0)
+    for (i = 0; i < as->rank + as->corank; i++)
+      {
+	mio_expr (&as->lower[i]);
+	mio_expr (&as->upper[i]);
+      }
 
 done:
   mio_rparen ();