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

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