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

9805c9
From 60b2e0b9ad2057f256591f56d5433e9ca54bf56f Mon Sep 17 00:00:00 2001
9805c9
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
Date: Fri, 26 Aug 2016 17:46:05 +0100
9805c9
Subject: [PATCH 14/16] Fill in missing array dimensions using the lower bound
9805c9
9805c9
Use -fdec-add-missing-indexes to enable feature. Also enabled by fdec.
9805c9
---
9805c9
 gcc/fortran/lang.opt                  |  8 ++++++++
9805c9
 gcc/fortran/options.c                 |  1 +
9805c9
 gcc/fortran/resolve.c                 | 24 ++++++++++++++++++++++++
9805c9
 gcc/testsuite/gfortran.dg/array_6.f90 | 23 +++++++++++++++++++++++
9805c9
 gcc/testsuite/gfortran.dg/array_7.f90 | 23 +++++++++++++++++++++++
9805c9
 gcc/testsuite/gfortran.dg/array_8.f90 | 23 +++++++++++++++++++++++
9805c9
 6 files changed, 102 insertions(+)
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/array_6.f90
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/array_7.f90
9805c9
 create mode 100644 gcc/testsuite/gfortran.dg/array_8.f90
9805c9
9805c9
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
9805c9
index ffd9ce6f270..dca3fd27aa3 100644
9805c9
--- a/gcc/fortran/lang.opt
9805c9
+++ b/gcc/fortran/lang.opt
9805c9
@@ -281,6 +281,10 @@ Wmissing-include-dirs
9805c9
 Fortran
9805c9
 ; Documented in C/C++
9805c9
 
9805c9
+Wmissing-index
9805c9
+Fortran Var(warn_missing_index) Warning LangEnabledBy(Fortran,Wall)
9805c9
+Warn that the lower bound of a missing index will be used.
9805c9
+
9805c9
 Wuse-without-only
9805c9
 Fortran Var(warn_use_without_only) Warning
9805c9
 Warn about USE statements that have no ONLY qualifier.
9805c9
@@ -440,6 +444,10 @@ fdec
9805c9
 Fortran Var(flag_dec)
9805c9
 Enable all DEC language extensions.
9805c9
 
9805c9
+fdec-add-missing-indexes
9805c9
+Fortran Var(flag_dec_add_missing_indexes)
9805c9
+Enable the addition of missing indexes using their lower bounds.
9805c9
+
9805c9
 fdec-blank-format-item
9805c9
 Fortran Var(flag_dec_blank_format_item)
9805c9
 Enable the use of blank format items in format strings.
9805c9
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
9805c9
index b6fd327d057..f417f48f6a7 100644
9805c9
--- a/gcc/fortran/options.c
9805c9
+++ b/gcc/fortran/options.c
9805c9
@@ -85,6 +85,7 @@ set_dec_flags (int value)
9805c9
   SET_BITFLAG (flag_dec_non_logical_if, value, value);
9805c9
   SET_BITFLAG (flag_dec_promotion, value, value);
9805c9
   SET_BITFLAG (flag_dec_sequence, value, value);
9805c9
+  SET_BITFLAG (flag_dec_add_missing_indexes, value, value);
9805c9
 }
9805c9
 
9805c9
 /* Finalize DEC flags.  */
9805c9
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
9805c9
index 08627866c9c..70093c952f6 100644
9805c9
--- a/gcc/fortran/resolve.c
9805c9
+++ b/gcc/fortran/resolve.c
9805c9
@@ -4676,6 +4676,30 @@ compare_spec_to_ref (gfc_array_ref *ar)
9805c9
   if (ar->type == AR_FULL)
9805c9
     return true;
9805c9
 
9805c9
+  if (flag_dec_add_missing_indexes && as->rank > ar->dimen)
9805c9
+    {
9805c9
+      /* Add in the missing dimensions, assuming they are the lower bound
9805c9
+         of that dimension if not specified.  */
9805c9
+      int j;
9805c9
+      if (warn_missing_index)
9805c9
+	{
9805c9
+          gfc_warning (OPT_Wmissing_index, "Using the lower bound for "
9805c9
+		       "unspecified dimensions in array reference at %L",
9805c9
+		       &ar->where);
9805c9
+	}
9805c9
+      /* Other parts of the code iterate ar->start and ar->end from 0 to
9805c9
+	 ar->dimen, so it is safe to assume slots from ar->dimen upwards
9805c9
+	 are unused (i.e. there are no gaps; the specified indexes are
9805c9
+	 contiguous and start at zero.  */
9805c9
+      for(j = ar->dimen; j <= as->rank; j++)
9805c9
+        {
9805c9
+	  ar->start[j] = gfc_copy_expr (as->lower[j]);
9805c9
+	  ar->end[j]   = gfc_copy_expr (as->lower[j]);
9805c9
+	  ar->dimen_type[j] = DIMEN_ELEMENT;
9805c9
+        }
9805c9
+      ar->dimen = as->rank;
9805c9
+    }
9805c9
+
9805c9
   if (as->rank != ar->dimen)
9805c9
     {
9805c9
       gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
9805c9
diff --git a/gcc/testsuite/gfortran.dg/array_6.f90 b/gcc/testsuite/gfortran.dg/array_6.f90
9805c9
new file mode 100644
9805c9
index 00000000000..5c26e18ab3e
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/array_6.f90
9805c9
@@ -0,0 +1,23 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-fdec -Wmissing-index" }!
9805c9
+! Checks that under-specified arrays (referencing arrays with fewer
9805c9
+! dimensions than the array spec) generates a warning.
9805c9
+!
9805c9
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
+! Updated by Mark Eggleston <mark.eggleston@codethink.co.uk>
9805c9
+!
9805c9
+
9805c9
+program under_specified_array
9805c9
+    integer chessboard(8,8)
9805c9
+    integer chessboard3d(8,8,3:5)
9805c9
+    chessboard(3,1) = 5
9805c9
+    chessboard(3,2) = 55
9805c9
+    chessboard3d(4,1,3) = 6
9805c9
+    chessboard3d(4,1,4) = 66
9805c9
+    chessboard3d(4,4,3) = 7
9805c9
+    chessboard3d(4,4,4) = 77
9805c9
+  
9805c9
+    if (chessboard(3).ne.5) stop 1  ! { dg-warning "Using the lower bound for unspecified dimensions in array reference" }
9805c9
+    if (chessboard3d(4).ne.6) stop 2  ! { dg-warning "Using the lower bound for unspecified dimensions in array reference" }
9805c9
+    if (chessboard3d(4,4).ne.7) stop 3  ! { dg-warning "Using the lower bound for unspecified dimensions in array reference" }
9805c9
+end program
9805c9
diff --git a/gcc/testsuite/gfortran.dg/array_7.f90 b/gcc/testsuite/gfortran.dg/array_7.f90
9805c9
new file mode 100644
9805c9
index 00000000000..5588a5bd02d
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/array_7.f90
9805c9
@@ -0,0 +1,23 @@
9805c9
+! { dg-do run }
9805c9
+! { dg-options "-fdec-add-missing-indexes -Wmissing-index" }!
9805c9
+! Checks that under-specified arrays (referencing arrays with fewer
9805c9
+! dimensions than the array spec) generates a warning.
9805c9
+!
9805c9
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
+! Updated by Mark Eggleston <mark.eggleston@codethink.co.uk>
9805c9
+!
9805c9
+
9805c9
+program under_specified_array
9805c9
+    integer chessboard(8,8)
9805c9
+    integer chessboard3d(8,8,3:5)
9805c9
+    chessboard(3,1) = 5
9805c9
+    chessboard(3,2) = 55
9805c9
+    chessboard3d(4,1,3) = 6
9805c9
+    chessboard3d(4,1,4) = 66
9805c9
+    chessboard3d(4,4,3) = 7
9805c9
+    chessboard3d(4,4,4) = 77
9805c9
+  
9805c9
+    if (chessboard(3).ne.5) stop 1  ! { dg-warning "Using the lower bound for unspecified dimensions in array reference" }
9805c9
+    if (chessboard3d(4).ne.6) stop 2  ! { dg-warning "Using the lower bound for unspecified dimensions in array reference" }
9805c9
+    if (chessboard3d(4,4).ne.7) stop 3  ! { dg-warning "Using the lower bound for unspecified dimensions in array reference" }
9805c9
+end program
9805c9
diff --git a/gcc/testsuite/gfortran.dg/array_8.f90 b/gcc/testsuite/gfortran.dg/array_8.f90
9805c9
new file mode 100644
9805c9
index 00000000000..f0d2ef5e37d
9805c9
--- /dev/null
9805c9
+++ b/gcc/testsuite/gfortran.dg/array_8.f90
9805c9
@@ -0,0 +1,23 @@
9805c9
+! { dg-do compile }
9805c9
+! { dg-options "-fdec -fno-dec-add-missing-indexes" }!
9805c9
+! Checks that under-specified arrays (referencing arrays with fewer
9805c9
+! dimensions than the array spec) generates a warning.
9805c9
+!
9805c9
+! Contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
9805c9
+! Updated by Mark Eggleston <mark.eggleston@codethink.co.uk>
9805c9
+!
9805c9
+
9805c9
+program under_specified_array
9805c9
+    integer chessboard(8,8)
9805c9
+    integer chessboard3d(8,8,3:5)
9805c9
+    chessboard(3,1) = 5
9805c9
+    chessboard(3,2) = 55
9805c9
+    chessboard3d(4,1,3) = 6
9805c9
+    chessboard3d(4,1,4) = 66
9805c9
+    chessboard3d(4,4,3) = 7
9805c9
+    chessboard3d(4,4,4) = 77
9805c9
+  
9805c9
+    if (chessboard(3).ne.5) stop 1  ! { dg-error "Rank mismatch" }
9805c9
+    if (chessboard3d(4).ne.6) stop 2  ! { dg-error "Rank mismatch" }
9805c9
+    if (chessboard3d(4,4).ne.7) stop 3  ! { dg-error "Rank mismatch" }
9805c9
+end program
9805c9
-- 
9805c9
2.11.0
9805c9