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