]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Prevent ICE when getting caf-token from abstract type [PR77872]
authorAndre Vehreschild <vehre@gcc.gnu.org>
Mon, 3 Mar 2025 13:42:28 +0000 (14:42 +0100)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Tue, 4 Mar 2025 08:38:14 +0000 (09:38 +0100)
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.

gcc/fortran/trans-expr.cc
gcc/testsuite/gfortran.dg/coarray/class_1.f90 [new file with mode: 0644]

index 7c0b17428cdda7d2bad23f2e9c31810a6a01a06d..0d790b63f956139799d4df490898a66d484c0a9b 100644 (file)
@@ -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 (file)
index 0000000..fa70b1d
--- /dev/null
@@ -0,0 +1,16 @@
+!{ dg-do compile }
+!
+! Compiling the call x%f() ICEd.  Check it's fixed.
+! Contributed by Gerhard Steinmetz  <gerhard.steinmetz.fortran@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