public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Proxy ping [PATCH] Fortran: Fix ICE with automatic reallocation [PR100245]
Date: Fri, 2 Sep 2022 21:46:14 +0200	[thread overview]
Message-ID: <trinity-abb0772a-6d33-411d-bd47-c27f551b9934-1662147974622@3c-app-gmx-bs46> (raw)

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

Dear all,

Jose posted a small patch here that was never reviewed:

  https://gcc.gnu.org/pipermail/fortran/2021-April/055982.html

IMHO the patch is fine and nearly obvious.

I inquired in the PR, and Jose did not object to my handling of
his patch.  So - unless there are objections - I will commit
the patch in the next days in the slightly corrected version as
attached below (with fixed PR typo in commit message ;-).

Regtested on x86_64-pc-linux-gnu.

Thanks,
Harald


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

From d7e5cca20be4a4ed00705f0d577302819ad97123 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Rui=20Faustino=20de=20Sousa?=
 <jrfsousa@gmail.com>
Date: Fri, 2 Sep 2022 21:35:22 +0200
Subject: [PATCH] Fortran: Fix ICE with automatic reallocation [PR100245]

gcc/fortran/ChangeLog:

	PR fortran/100245
	* trans-expr.cc (trans_class_assignment): Add if clause to handle
	derived type in the LHS.

gcc/testsuite/ChangeLog:

	PR fortran/100245
	* gfortran.dg/PR100245.f90: New test.
---
 gcc/fortran/trans-expr.cc              |  3 +++
 gcc/testsuite/gfortran.dg/PR100245.f90 | 28 ++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/PR100245.f90

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 850007fd2e1..13c3e7df45f 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11436,6 +11436,9 @@ trans_class_assignment (stmtblock_t *block, gfc_expr *lhs, gfc_expr *rhs,
       class_han = GFC_CLASS_TYPE_P (TREE_TYPE (lse->expr))
 	  ? gfc_class_data_get (lse->expr) : lse->expr;

+      if (!POINTER_TYPE_P (TREE_TYPE (class_han)))
+	class_han = gfc_build_addr_expr (NULL_TREE, class_han);
+
       /* Allocate block.  */
       gfc_init_block (&alloc);
       gfc_allocate_using_malloc (&alloc, class_han, size, NULL_TREE);
diff --git a/gcc/testsuite/gfortran.dg/PR100245.f90 b/gcc/testsuite/gfortran.dg/PR100245.f90
new file mode 100644
index 00000000000..07c1f7b3a1c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR100245.f90
@@ -0,0 +1,28 @@
+! { dg-do run }
+!
+! Test the fix for PR100245
+!
+
+program main_p
+
+  implicit none
+
+  type :: foo_t
+    integer :: a
+  end type foo_t
+
+  integer, parameter :: a = 42
+
+  class(foo_t), allocatable :: val
+  class(foo_t), allocatable :: rs1
+  type(foo_t),  allocatable :: rs2
+
+  allocate(val, source=foo_t(42))
+  if (val%a/=a) stop 1
+  rs1 = val
+  if (rs1%a/=a) stop 2
+  rs2 = val
+  if (rs2%a/=a) stop 3
+  deallocate(val, rs1, rs2)
+
+end program main_p
--
2.35.3


                 reply	other threads:[~2022-09-02 19:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-abb0772a-6d33-411d-bd47-c27f551b9934-1662147974622@3c-app-gmx-bs46 \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).