From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id B13553858038; Wed, 8 Dec 2021 19:23:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B13553858038 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 r11-9366] Fortran: add check for type of upper bound in case range X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 8ff9ed7f4f7e80b4602524689dc486cf35e84e87 X-Git-Newrev: 423e0a98e3d972fb180803665a8c02b017b72d15 Message-Id: <20211208192331.B13553858038@sourceware.org> Date: Wed, 8 Dec 2021 19:23:31 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Dec 2021 19:23:31 -0000 https://gcc.gnu.org/g:423e0a98e3d972fb180803665a8c02b017b72d15 commit r11-9366-g423e0a98e3d972fb180803665a8c02b017b72d15 Author: Harald Anlauf Date: Mon Dec 6 23:15:11 2021 +0100 Fortran: add check for type of upper bound in case range gcc/fortran/ChangeLog: PR fortran/103591 * match.c (match_case_selector): Check type of upper bound in case range. gcc/testsuite/ChangeLog: PR fortran/103591 * gfortran.dg/select_9.f90: New test. (cherry picked from commit f47662204de27f7685699eeef89aa173ccf32d85) Diff: --- gcc/fortran/match.c | 9 +++++++++ gcc/testsuite/gfortran.dg/select_9.f90 | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index bccc85df87a..74d03d062b3 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -6092,6 +6092,15 @@ match_case_selector (gfc_case **cp) m = gfc_match_init_expr (&c->high); if (m == MATCH_ERROR) goto cleanup; + if (m == MATCH_YES + && c->high->ts.type != BT_LOGICAL + && c->high->ts.type != BT_INTEGER + && c->high->ts.type != BT_CHARACTER) + { + gfc_error ("Expression in CASE selector at %L cannot be %s", + &c->high->where, gfc_typename (c->high)); + goto cleanup; + } /* MATCH_NO is fine. It's OK if nothing is there! */ } } diff --git a/gcc/testsuite/gfortran.dg/select_9.f90 b/gcc/testsuite/gfortran.dg/select_9.f90 new file mode 100644 index 00000000000..c580e8162bd --- /dev/null +++ b/gcc/testsuite/gfortran.dg/select_9.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR fortran/103591 - ICE in gfc_compare_string +! Contributed by G.Steinmetz + +program p + integer :: n + select case (n) + case ('1':2.) ! { dg-error "cannot be REAL" } + end select +end