public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5003] Fortran: Fix a problem with SELECT TYPE selectors [PR104555].
@ 2023-10-30 7:13 Paul Thomas
0 siblings, 0 replies; only message in thread
From: Paul Thomas @ 2023-10-30 7:13 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f3e44d079747daf56307ada8a2e2e56b64934014
commit r14-5003-gf3e44d079747daf56307ada8a2e2e56b64934014
Author: Paul Thomas <pault@gcc.gnu.org>
Date: Mon Oct 30 07:12:40 2023 +0000
Fortran: Fix a problem with SELECT TYPE selectors [PR104555].
2023-10-30 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/104555
* resolve.cc (resolve_select_type): If the selector expression
has no class component references and the expression is a
derived type, copy the typespec of the symbol to that of the
expression.
gcc/testsuite/
PR fortran/104555
* gfortran.dg/pr104555.f90: New test.
Diff:
---
gcc/fortran/resolve.cc | 6 ++++++
gcc/testsuite/gfortran.dg/pr104555.f90 | 32 ++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 9f4dc0726457..81a14653a044 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -9578,6 +9578,12 @@ resolve_select_type (gfc_code *code, gfc_namespace *old_ns)
{
if (code->expr1->symtree->n.sym->attr.untyped)
code->expr1->symtree->n.sym->ts = code->expr2->ts;
+ /* Sometimes the selector expression is given the typespec of the
+ '_data' field, which is logical enough but inappropriate here. */
+ if (code->expr2->ts.type == BT_DERIVED
+ && code->expr2->symtree
+ && code->expr2->symtree->n.sym->ts.type == BT_CLASS)
+ code->expr2->ts = code->expr2->symtree->n.sym->ts;
selector_type = CLASS_DATA (code->expr2)
? CLASS_DATA (code->expr2)->ts.u.derived : code->expr2->ts.u.derived;
}
diff --git a/gcc/testsuite/gfortran.dg/pr104555.f90 b/gcc/testsuite/gfortran.dg/pr104555.f90
new file mode 100644
index 000000000000..1fc5b5bb977b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104555.f90
@@ -0,0 +1,32 @@
+! { dg-do compile }
+!
+! Test the fix for PR104555 in which the select type statement caused an
+! ICE because the selector expression was type(t) rather than class(t).
+!
+! Contributed by Gerhard Steinmetz <gscfq@t-online.de>
+!
+program p
+ type t
+ character(:), allocatable :: a
+ end type
+ call s(t("abcd"))
+ call s([t("efgh")])
+contains
+ subroutine s(x)
+ class(t) :: x(..)
+ select rank (x)
+ rank (0)
+ print *, "|", x%a, "|"
+ select type (y => x)
+ type is (t)
+ print *, "|", y%a, "|"
+ end select
+ rank (1)
+ print *, "|", x(1)%a, "|"
+ select type (y => x)
+ type is (t)
+ print *, "|", y(1)%a, "|"
+ end select
+ end select
+ end
+end
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-10-30 7:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30 7:13 [gcc r14-5003] Fortran: Fix a problem with SELECT TYPE selectors [PR104555] Paul Thomas
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).