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