public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran, PR84244, v1] Fix  ICE in recompute_tree_invariant_for_addr_expr, at tree.c:4535
@ 2024-07-11 14:05 Andre Vehreschild
  2024-07-17 13:11 ` [Ping, Patch, " Andre Vehreschild
  0 siblings, 1 reply; 7+ messages in thread
From: Andre Vehreschild @ 2024-07-11 14:05 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

[-- Attachment #1: Type: text/plain, Size: 366 bytes --]

Hi all,

the attached patch fixes a segfault in the compiler, where for pointer
components of a derived type the caf_token in the component was not
set, when the derived was previously used outside of a coarray.

Regtests ok on x86_64-pc-linux-gnu / Fedora 39. Ok for mainline?

Regards,
	Andre
--
Andre Vehreschild * Email: vehre ad gcc dot gnu dot org

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr84244_1.patch --]
[-- Type: text/x-patch, Size: 2703 bytes --]

From 88f209316a980fbe78423d6aba747bb6b7fd404f Mon Sep 17 00:00:00 2001
From: Andre Vehreschild <vehre@gcc.gnu.org>
Date: Thu, 11 Jul 2024 15:44:56 +0200
Subject: [PATCH] [Fortran] Fix ICE in recompute_tree_invariant_for_addr_expr,
 at tree.c:4535 [PR84244]

Declaring an unused function with a derived type having a pointer
component and using that derived type as a coarray, lead the compiler to
ICE because the caf_token for the pointer was not linked into the
component correctly.

	PR fortran/84244

gcc/fortran/ChangeLog:

	* trans-types.cc (gfc_get_derived_type): When a caf_sub_token is
	generated for a component, link it to the component it is
	generated for (the previous one).

gcc/testsuite/ChangeLog:

	* gfortran.dg/coarray/ptr_comp_5.f08: New test.
---
 gcc/fortran/trans-types.cc                    |  6 +++++-
 .../gfortran.dg/coarray/ptr_comp_5.f08        | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/coarray/ptr_comp_5.f08

diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index c76cdca4eae..83c0708ccbd 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -2647,7 +2647,7 @@ gfc_get_derived_type (gfc_symbol * derived, int codimen)
   tree *chain = NULL;
   bool got_canonical = false;
   bool unlimited_entity = false;
-  gfc_component *c;
+  gfc_component *c, *last_c = nullptr;
   gfc_namespace *ns;
   tree tmp;
   bool coarray_flag, class_coarray_flag;
@@ -2947,10 +2947,14 @@ gfc_get_derived_type (gfc_symbol * derived, int codimen)
 	 types.  */
       if (class_coarray_flag || !c->backend_decl)
 	c->backend_decl = field;
+      if (c->attr.caf_token && last_c)
+	last_c->caf_token = field;

       if (c->attr.pointer && (c->attr.dimension || c->attr.codimension)
 	  && !(c->ts.type == BT_DERIVED && strcmp (c->name, "_data") == 0))
 	GFC_DECL_PTR_ARRAY_P (c->backend_decl) = 1;
+
+      last_c = c;
     }

   /* Now lay out the derived type, including the fields.  */
diff --git a/gcc/testsuite/gfortran.dg/coarray/ptr_comp_5.f08 b/gcc/testsuite/gfortran.dg/coarray/ptr_comp_5.f08
new file mode 100644
index 00000000000..ed3a8db13fa
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/ptr_comp_5.f08
@@ -0,0 +1,19 @@
+! { dg-do compile }
+
+! Check PR84244 does not ICE anymore.
+
+program ptr_comp_5
+  integer, target :: dest = 42
+  type t
+    integer, pointer :: p
+  end type
+  type(t) :: o[*]
+
+  o%p => dest
+contains
+  ! This unused routine is crucial for the ICE.
+  function f(x)
+    type(t), intent(in) ::x
+  end function
+end program
+
--
2.45.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-08-19  7:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-11 14:05 [Patch, Fortran, PR84244, v1] Fix ICE in recompute_tree_invariant_for_addr_expr, at tree.c:4535 Andre Vehreschild
2024-07-17 13:11 ` [Ping, Patch, " Andre Vehreschild
2024-08-09 14:27   ` [Ping 2, Patch, Fortran, PR84244, v3] " Andre Vehreschild
2024-08-16 10:05     ` [Ping x 3, " Andre Vehreschild
2024-08-16 17:20       ` Harald Anlauf
2024-08-16 17:20         ` Harald Anlauf
2024-08-19  7:33         ` Andre Vehreschild

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).