* [PATCH] PR fortran/103776 - ICE in gfc_compare_string, at fortran/arith.c:1118
@ 2021-12-20 21:07 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2021-12-20 21:07 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 338 bytes --]
Dear all,
we need to check that expressions in CASE selectors are scalar,
and reject them early if they aren't.
Testcase by Gerhard. The fix is obvious and sort of a follow-up
to the fix for PR103591.
Regtested on x86_64-pc-linux-gnu.
Will commit as obvious within 48h unless there are objections or
other comments.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-CASE-selector-expressions-must-be-scalar.patch --]
[-- Type: text/x-patch, Size: 2210 bytes --]
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
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 52bc5af7542..617fb35c9cd 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 00000000000..2d9b0170ce9
--- /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
--
2.26.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-12-20 21:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-20 21:07 [PATCH] PR fortran/103776 - ICE in gfc_compare_string, at fortran/arith.c:1118 Harald Anlauf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).