aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/array.cc
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2022-12-11 23:24:03 +0100
committerHarald Anlauf <anlauf@gmx.de>2022-12-12 20:39:28 +0100
commitcf5327b89ab610649c5faab78ea7907bb74b103c (patch)
treea31444cf310113b88eaa7741ae7db7586596dac3 /gcc/fortran/array.cc
parent9fe7d3debbf60ed9fef8053123ad542a99d62100 (diff)
downloadgcc-cf5327b89ab610649c5faab78ea7907bb74b103c.zip
gcc-cf5327b89ab610649c5faab78ea7907bb74b103c.tar.gz
gcc-cf5327b89ab610649c5faab78ea7907bb74b103c.tar.bz2
Fortran: improve checking of assumed-size array spec [PR102180]
gcc/fortran/ChangeLog: PR fortran/102180 * array.cc (match_array_element_spec): Add check for bad assumed-implied-spec. (gfc_match_array_spec): Reorder logic so that the first bad array element spec may trigger an error. gcc/testsuite/ChangeLog: PR fortran/102180 * gfortran.dg/pr102180.f90: New test.
Diffstat (limited to 'gcc/fortran/array.cc')
-rw-r--r--gcc/fortran/array.cc19
1 files changed, 16 insertions, 3 deletions
diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc
index bbdb5b3..10d9e0c 100644
--- a/gcc/fortran/array.cc
+++ b/gcc/fortran/array.cc
@@ -489,7 +489,20 @@ match_array_element_spec (gfc_array_spec *as)
}
if (gfc_match_char (':') == MATCH_YES)
- return AS_DEFERRED;
+ {
+ locus old_loc = gfc_current_locus;
+ if (gfc_match_char ('*') == MATCH_YES)
+ {
+ /* F2018:R821: "assumed-implied-spec is [ lower-bound : ] *". */
+ gfc_error ("A lower bound must precede colon in "
+ "assumed-size array specification at %L", &old_loc);
+ return AS_UNKNOWN;
+ }
+ else
+ {
+ return AS_DEFERRED;
+ }
+ }
m = gfc_match_expr (upper);
if (m == MATCH_NO)
@@ -591,6 +604,8 @@ gfc_match_array_spec (gfc_array_spec **asp, bool match_dim, bool match_codim)
{
as->rank++;
current_type = match_array_element_spec (as);
+ if (current_type == AS_UNKNOWN)
+ goto cleanup;
/* Note that current_type == AS_ASSUMED_SIZE for both assumed-size
and implied-shape specifications. If the rank is at least 2, we can
@@ -600,8 +615,6 @@ gfc_match_array_spec (gfc_array_spec **asp, bool match_dim, bool match_codim)
if (as->rank == 1)
{
- if (current_type == AS_UNKNOWN)
- goto cleanup;
as->type = current_type;
}
else