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

login
register
mail settings
Submitter Tobias Burnus
Date July 25, 2012, 8:08 p.m.
Message ID <50105221.5060702@net-b.de>
Download mbox | patch
Permalink /patch/173257/
State New
Headers show

Comments

Tobias Burnus - July 25, 2012, 8:08 p.m.
The following issue was found by Alessandro. (It got triggered by a 
larger test case, which is required for a larger patch by Alessandro, 
which is not yet finished.)

Accessing the "lower[-1]" is probably not the best idea …

Build on x86-64-linux.
OK for the trunk?

Tobias

Patch

2012-07-25  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.

diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c
index a3b9088..51b7059 100644
--- a/gcc/fortran/module.c
+++ b/gcc/fortran/module.c
@@ -2381,11 +2381,12 @@  mio_array_spec (gfc_array_spec **asp)
   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 ();