From: Harald Anlauf Date: Mon, 20 Dec 2021 21:01:05 +0000 (+0100) Subject: Fortran: CASE selector expressions must be scalar X-Git-Tag: upstream/12.2.0~2597 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5474092c9afbd76cbd457facce3757d8d2fad07b;p=platform%2Fupstream%2Fgcc.git Fortran: CASE selector expressions must be scalar gcc/fortran/ChangeLog: PR fortran/103776 * match.c (match_case_selector): Reject expressions in CASE selector which are not scalar. gcc/testsuite/ChangeLog: PR fortran/103776 * gfortran.dg/select_10.f90: New test. --- diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 52bc5af..617fb35 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -6088,6 +6088,19 @@ match_case_selector (gfc_case **cp) } } + if (c->low && c->low->rank != 0) + { + gfc_error ("Expression in CASE selector at %L must be scalar", + &c->low->where); + goto cleanup; + } + if (c->high && c->high->rank != 0) + { + gfc_error ("Expression in CASE selector at %L must be scalar", + &c->high->where); + goto cleanup; + } + *cp = c; return MATCH_YES; diff --git a/gcc/testsuite/gfortran.dg/select_10.f90 b/gcc/testsuite/gfortran.dg/select_10.f90 new file mode 100644 index 0000000..2d9b017 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/select_10.f90 @@ -0,0 +1,25 @@ +! { dg-do compile } +! PR fortran/103776 - ICE in gfc_compare_string +! Contributed by G.Steinmetz + +program p + integer :: n + select case (n) + case ([1]) ! { dg-error "must be scalar" } + end select + select case (n) + case (:[2]) ! { dg-error "must be scalar" } + end select + select case (n) + case (['1']) ! { dg-error "must be scalar" } + end select + select case (n) + case (['1']:2) ! { dg-error "must be scalar" } + end select + select case (n) + case(['1']:['2']) ! { dg-error "must be scalar" } + end select + select case (n) + case(1:['2']) ! { dg-error "must be scalar" } + end select +end