The following program produces an internal compiler error for me. module a type, abstract :: t1 end type type, extends(t1) :: t2 end type contains subroutine b implicit none class(t1) :: c2 select type (d => c2) end select type end subroutine b end module a Removing the select type statement gives the expected error: a.f90:9:19: class(t1) :: c2 1 Error: CLASS variable ‘c2’ at (1) must be dummy, allocatable or pointer Adding allocatable or pointer attributes fixes the ICE.
Confirmed, all releases I have (4.5.0) ICE.
Further reduced test case: program a implicit none type :: t1 end type class(t1) :: c2 select type (d => c2) end select type end
The ICE (and another one that is triggered by the same test case) is fixed with this patch: diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 85247dd8334..6cf816be511 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -6009,7 +6009,7 @@ copy_ts_from_selector_to_associate (gfc_expr *associate, gfc_expr *selector) else assoc_sym->as = NULL; - if (selector->ts.type == BT_CLASS) + if (selector->ts.type == BT_CLASS && gfc_expr_attr (selector).class_ok) { /* The correct class container has to be available. */ assoc_sym->ts.type = BT_CLASS; diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index ea0ce800743..97f5402bf29 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -8862,7 +8862,8 @@ resolve_select_type (gfc_code *code, gfc_namespace *old_ns) return; } - if (!code->expr1->symtree->n.sym->attr.class_ok) + if (!code->expr1->symtree->n.sym->attr.class_ok + || !gfc_expr_attr (code->expr2).class_ok) return; if (code->expr2)
The patch in comment #3 shows lots of regressions in the testsuite, but this one should be better: diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 85247dd8334..6cf816be511 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -6009,7 +6009,7 @@ copy_ts_from_selector_to_associate (gfc_expr *associate, gfc_expr *selector) else assoc_sym->as = NULL; - if (selector->ts.type == BT_CLASS) + if (selector->ts.type == BT_CLASS && gfc_expr_attr (selector).class_ok) { /* The correct class container has to be available. */ assoc_sym->ts.type = BT_CLASS; diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index ea0ce800743..67b625f3a51 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -8867,6 +8867,9 @@ resolve_select_type (gfc_code *code, gfc_namespace *old_ns) if (code->expr2) { + if (!gfc_expr_attr (code->expr2).class_ok) + return; + if (code->expr1->symtree->n.sym->attr.untyped) code->expr1->symtree->n.sym->ts = code->expr2->ts; selector_type = CLASS_DATA (code->expr2)->ts.u.derived; Unfortunately it still fails on: FAIL: gfortran.dg/allocate_with_source_15.f03 -Os (internal compiler error) FAIL: gfortran.dg/select_type_26.f03 -O0 (internal compiler error) FAIL: gfortran.dg/select_type_27.f03 -O0 (internal compiler error)
The ICE is gone for GCC10.2.1 and 11.0.
(In reply to Dominique d'Humieres from comment #5) > The ICE is gone for GCC10.2.1 and 11.0. Then we should commit the test case and close.
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:0ec53a3df536f83ec72ef25b045768c06c363f86 commit r12-4723-g0ec53a3df536f83ec72ef25b045768c06c363f86 Author: Harald Anlauf <anlauf@gmx.de> Date: Tue Oct 26 22:22:36 2021 +0200 Fortran: error recovery on invalid code with SELECT TYPE gcc/testsuite/ChangeLog: PR fortran/86551 * gfortran.dg/pr86551.f90: New test to verify that PR86551 remains fixed.
Testcase committed. Closing. Thanks for the report!