https://gcc.gnu.org/g:5bd664838398980f1c8af60a946947ff83744fcc

commit r15-7804-g5bd664838398980f1c8af60a946947ff83744fcc
Author: Andre Vehreschild <ve...@gcc.gnu.org>
Date:   Mon Mar 3 14:42:28 2025 +0100

    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:
---
 gcc/fortran/trans-expr.cc                     |  5 +++++
 gcc/testsuite/gfortran.dg/coarray/class_1.f90 | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 7c0b17428cdd..0d790b63f956 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 000000000000..fa70b1d61629
--- /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  <gerhard.steinmetz.fort...@t-online.de>
+
+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

Reply via email to