From 70385de214fe4de289c56e7f4e06a4b252414379 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 20 Dec 2021 22:01:05 +0100
Subject: [PATCH] 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.
---
gcc/fortran/match.c | 13 +++++++++++++
gcc/testsuite/gfortran.dg/select_10.f90 | 25 +++++++++++++++++++++++++
2 files changed, 38 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/select_10.f90
@@ -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;
new file mode 100644
@@ -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
--
2.26.2