Hi all,

I figured this patch has not been okay'ed yet. Anyone in for a review?

Regtests ok on x86_64-pc-linux-gnu / F39. Ok for trunk?

Regards,
        Andre

On Thu, 26 Sep 2024 16:02:21 +0200
Andre Vehreschild <ve...@gmx.de> wrote:

> Hi all,
>
> attached patch fixes an ICE when a derived type was used as a coarray in a
> submodule. The fix is to not allow caf-token creation for vtypes. Again this,
> like the previous patch on pr80235, feels like fixing the symptom and not the
> cause. But I can't find where it goes wrong. So if some one has more insight,
> let me know, please.
>
> Besides that regtests ok on x86_64-pc-linux-gnu / Fedora 39. Ok for mainline?
>
> Regards,
>       Andre
> --
> Andre Vehreschild * Email: vehre ad gmx dot de


--
Andre Vehreschild * Email: vehre ad gmx dot de
From 4fd053badaa08e1c21109a23fed5669383be1094 Mon Sep 17 00:00:00 2001
From: Andre Vehreschild <ve...@gcc.gnu.org>
Date: Wed, 25 Sep 2024 14:19:38 +0200
Subject: [PATCH] [Fortran] Fix ICE when extended coarray is used in submodule
 [PR93158]

gcc/fortran/ChangeLog:

	PR fortran/93158

	* trans-types.cc: Prevent adding caf-tokens to vtypes.

gcc/testsuite/ChangeLog:

	* gfortran.dg/coarray/add_sources/submodule_2_mod.f90: New test.
	* gfortran.dg/coarray/submodule_2.f90: New test.
---
 gcc/fortran/trans-types.cc                    | 36 +++++++++----------
 .../coarray/add_sources/submodule_2_mod.f90   | 14 ++++++++
 .../gfortran.dg/coarray/submodule_2.f90       | 14 ++++++++
 3 files changed, 46 insertions(+), 18 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/coarray/add_sources/submodule_2_mod.f90
 create mode 100644 gcc/testsuite/gfortran.dg/coarray/submodule_2.f90

diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index e596a362c02..aa181adcb98 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -3162,24 +3162,24 @@ gfc_get_derived_type (gfc_symbol * derived, int codimen)

 copy_derived_types:

-  for (c = derived->components; c; c = c->next)
-    {
-      /* Do not add a caf_token field for class container components.  */
-      if ((codimen || coarray_flag)
-	  && !c->attr.dimension && !c->attr.codimension
-	  && (c->attr.allocatable || c->attr.pointer)
-	  && !derived->attr.is_class)
-	{
-	  /* Provide sufficient space to hold "_caf_symbol".  */
-	  char caf_name[GFC_MAX_SYMBOL_LEN + 6];
-	  gfc_component *token;
-	  snprintf (caf_name, sizeof (caf_name), "_caf_%s", c->name);
-	  token = gfc_find_component (derived, caf_name, true, true, NULL);
-	  gcc_assert (token);
-	  c->caf_token = token->backend_decl;
-	  suppress_warning (c->caf_token);
-	}
-    }
+  if (!derived->attr.vtype)
+    for (c = derived->components; c; c = c->next)
+      {
+	/* Do not add a caf_token field for class container components.  */
+	if ((codimen || coarray_flag) && !c->attr.dimension
+	    && !c->attr.codimension && (c->attr.allocatable || c->attr.pointer)
+	    && !derived->attr.is_class)
+	  {
+	    /* Provide sufficient space to hold "_caf_symbol".  */
+	    char caf_name[GFC_MAX_SYMBOL_LEN + 6];
+	    gfc_component *token;
+	    snprintf (caf_name, sizeof (caf_name), "_caf_%s", c->name);
+	    token = gfc_find_component (derived, caf_name, true, true, NULL);
+	    gcc_assert (token);
+	    c->caf_token = token->backend_decl;
+	    suppress_warning (c->caf_token);
+	  }
+      }

   for (gfc_symbol *dt = gfc_derived_types; dt; dt = dt->dt_next)
     {
diff --git a/gcc/testsuite/gfortran.dg/coarray/add_sources/submodule_2_mod.f90 b/gcc/testsuite/gfortran.dg/coarray/add_sources/submodule_2_mod.f90
new file mode 100644
index 00000000000..b0d79565fe5
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/add_sources/submodule_2_mod.f90
@@ -0,0 +1,14 @@
+module surfaces_interface
+  type package
+  end type
+
+  type surfaces
+    class(package), allocatable  :: halo_data
+  end type
+
+  interface
+    module subroutine set_halo_data()
+    end subroutine
+  end interface
+end module
+
diff --git a/gcc/testsuite/gfortran.dg/coarray/submodule_2.f90 b/gcc/testsuite/gfortran.dg/coarray/submodule_2.f90
new file mode 100644
index 00000000000..663dac67d67
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/submodule_2.f90
@@ -0,0 +1,14 @@
+!{ dg-do compile }
+!{ dg-compile-aux-modules add_sources/submodule_2_mod.f90 }
+
+! Contributed by Damian Rouson  <damian@archaeologic.codes>
+! Check PR93158 is fixed.
+
+submodule(surfaces_interface) surfaces_implementation
+  type(surfaces) singleton[*]
+contains
+  module procedure set_halo_data
+    stop 0
+  end procedure
+end submodule
+
--
2.47.0

Reply via email to