From: Andre Vehreschild Date: Mon, 3 Mar 2025 13:42:28 +0000 (+0100) Subject: Fortran: Prevent ICE when getting caf-token from abstract type [PR77872] X-Git-Tag: basepoints/gcc-16~1749 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bd664838398980f1c8af60a946947ff83744fcc;p=thirdparty%2Fgcc.git Fortran: Prevent ICE when getting caf-token from abstract type [PR77872] PR fortran/77872 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_get_tree_for_caf_expr): Pick up token from decl when it is present there for class types. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/class_1.f90: New test. --- diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 7c0b17428cd..0d790b63f95 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -2394,6 +2394,11 @@ gfc_get_tree_for_caf_expr (gfc_expr *expr) if (CLASS_DATA (expr->symtree->n.sym)->attr.codimension) return caf_decl; } + else if (DECL_P (caf_decl) && DECL_LANG_SPECIFIC (caf_decl) + && GFC_DECL_TOKEN (caf_decl) + && CLASS_DATA (expr->symtree->n.sym)->attr.codimension) + return caf_decl; + for (ref = expr->ref; ref; ref = ref->next) { if (ref->type == REF_COMPONENT diff --git a/gcc/testsuite/gfortran.dg/coarray/class_1.f90 b/gcc/testsuite/gfortran.dg/coarray/class_1.f90 new file mode 100644 index 00000000000..fa70b1d6162 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray/class_1.f90 @@ -0,0 +1,16 @@ +!{ dg-do compile } +! +! Compiling the call x%f() ICEd. Check it's fixed. +! Contributed by Gerhard Steinmetz + +module pr77872_abs + type, abstract :: t + contains + procedure(s), pass, deferred :: f + end type +contains + subroutine s(x) + class(t) :: x[*] + call x%f() + end +end module pr77872_abs