From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id BB8D9384F4A6; Mon, 12 Dec 2022 19:43:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB8D9384F4A6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670874207; bh=cn92cZjJM8UnCBnZfgka4so6gCdT39n8Crs5S+HeDx4=; h=From:To:Subject:Date:From; b=Myz9yV2FbuzIl8CHIf10YoEEKg8CATaA+QjHQT4kxUuY611g0VwsfLqt/x1MWNabt oA2RFkMjU1wMGbWgrnaxaQwmZT5jfPOQ5Gcxid0bF6rA76/SFA4DkfPNRMY8Yzk32s 6p1qhSWsEgzQKyeH8F3BRSsquc3PU1DfJyWAjdDY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4623] Fortran: improve checking of assumed-size array spec [PR102180] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/master X-Git-Oldrev: 9fe7d3debbf60ed9fef8053123ad542a99d62100 X-Git-Newrev: cf5327b89ab610649c5faab78ea7907bb74b103c Message-Id: <20221212194327.BB8D9384F4A6@sourceware.org> Date: Mon, 12 Dec 2022 19:43:27 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cf5327b89ab610649c5faab78ea7907bb74b103c commit r13-4623-gcf5327b89ab610649c5faab78ea7907bb74b103c Author: Harald Anlauf Date: Sun Dec 11 23:24:03 2022 +0100 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. Diff: --- gcc/fortran/array.cc | 19 ++++++++++++++++--- gcc/testsuite/gfortran.dg/pr102180.f90 | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index bbdb5b392fc..10d9e0c5354 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 diff --git a/gcc/testsuite/gfortran.dg/pr102180.f90 b/gcc/testsuite/gfortran.dg/pr102180.f90 new file mode 100644 index 00000000000..cbf3e7299e7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr102180.f90 @@ -0,0 +1,19 @@ +! { dg-do compile } +! { dg-options "-fcoarray=lib" } +! PR fortran/102180 - Improve checking of assumed size array spec + +subroutine s(x,y) + real :: x(0:*) ! legal + real :: y[0:*] ! legal +end + +subroutine t(x,y) + real :: x(:*) ! { dg-error "A lower bound must precede colon" } + real :: y[:*] ! { dg-error "A lower bound must precede colon" } +end + +subroutine u(x,y,z) + real :: x(2,*) + real :: y(2,2:*) + real :: z(2,:*) ! { dg-error "A lower bound must precede colon" } +end