Blame SOURCES/0018-Fill-in-missing-array-dimensions-using-the-lower-bou.patch

840d93
From b8527b8f03c4c50869c4f9a063f5c7686e58e5e9 Mon Sep 17 00:00:00 2001
840d93
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
840d93
Date: Fri, 26 Aug 2016 17:46:05 +0100
840d93
Subject: [PATCH 18/23] Fill in missing array dimensions using the lower bound
840d93
840d93
This feature is enabled by the `-fstd=extra-legacy` compiler flag
840d93
---
840d93
840d93
840d93
    0018-Fill-in-missing-array-dimensions-using-the-lower-bou.patch
840d93
840d93
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
840d93
index a831f70..ac35357 100644
840d93
--- a/gcc/fortran/resolve.c
840d93
+++ b/gcc/fortran/resolve.c
840d93
@@ -4396,6 +4396,27 @@ compare_spec_to_ref (gfc_array_ref *ar)
840d93
   if (ar->type == AR_FULL)
840d93
     return true;
840d93
 
840d93
+  if ((gfc_option.allow_std & GFC_STD_EXTRA_LEGACY)
840d93
+      && as->rank > ar->dimen)
840d93
+    {
840d93
+      /* Add in the missing dimensions, assuming they are the lower bound
840d93
+         of that dimension if not specified. */
840d93
+      int j;
840d93
+      gfc_warning (0, "Using the lower bound for unspecified dimensions "
840d93
+                   "in array reference at %L", &ar->where);
840d93
+      /* Other parts of the code iterate ar->start and ar->end from 0 to
840d93
+	 ar->dimen, so it is safe to assume slots from ar->dimen upwards
840d93
+	 are unused (i.e. there are no gaps; the specified indexes are
840d93
+	 contiguous and start at zero */
840d93
+      for(j = ar->dimen; j <= as->rank; j++)
840d93
+        {
840d93
+	  ar->start[j] = gfc_copy_expr (as->lower[j]);
840d93
+	  ar->end[j]   = gfc_copy_expr (as->lower[j]);
840d93
+	  ar->dimen_type[j] = DIMEN_ELEMENT;
840d93
+        }
840d93
+      ar->dimen = as->rank;
840d93
+    }
840d93
+
840d93
   if (as->rank != ar->dimen)
840d93
     {
840d93
       gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
840d93
diff --git a/gcc/testsuite/gfortran.dg/array_6.f90 b/gcc/testsuite/gfortran.dg/array_6.f90
840d93
new file mode 100644
840d93
index 0000000..20752a1
840d93
--- /dev/null
840d93
+++ b/gcc/testsuite/gfortran.dg/array_6.f90
840d93
@@ -0,0 +1,13 @@
840d93
+! { dg-do compile }
840d93
+! { dg-options "-std=extra-legacy" }!
840d93
+! Checks that under-specified arrays (referencing arrays with fewer
840d93
+! dimensions than the array spec) generates a warning.
840d93
+!
840d93
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
840d93
+!
840d93
+
840d93
+program under_specified_array
840d93
+    INTEGER chsbrd(8,8)
840d93
+    chsbrd(3,1) = 5
840d93
+    print *, chsbrd(3) ! { dg-warning "Using the lower bound for unspecified dimensions in array reference" }
840d93
+end program