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