* [PATCH] Fortran: ICE on recursive derived types with allocatable components [PR107872]
@ 2022-12-09 21:27 Harald Anlauf
2022-12-09 21:58 ` Paul Richard Thomas
0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-12-09 21:27 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 338 bytes --]
Dear all,
I am submitting the attached simple - and obvious - patch on
behalf of Paul. It prevents a resource exhaustion due to an
infinite loop, and has been regtested by multiple contributers, ;-)
at least on x86_64-pc-linux-gnu.
I intend to commit it to mainline within 24 hours, unless
there are further comments.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr107872.diff --]
[-- Type: text/x-patch, Size: 2622 bytes --]
From 01254aa2eb766c7584fd047568d7277d4d65d067 Mon Sep 17 00:00:00 2001
From: Paul Thomas <pault@gcc.gnu.org>
Date: Fri, 9 Dec 2022 22:13:45 +0100
Subject: [PATCH] Fortran: ICE on recursive derived types with allocatable
components [PR107872]
gcc/fortran/ChangeLog:
PR fortran/107872
* resolve.cc (derived_inaccessible): Skip over allocatable components
to prevent an infinite loop.
gcc/testsuite/ChangeLog:
PR fortran/107872
* gfortran.dg/pr107872.f90: New test.
---
gcc/fortran/resolve.cc | 3 +-
gcc/testsuite/gfortran.dg/pr107872.f90 | 40 ++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr107872.f90
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 75dc4b59105..158bf08ec26 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -7536,7 +7536,8 @@ derived_inaccessible (gfc_symbol *sym)
for (c = sym->components; c; c = c->next)
{
/* Prevent an infinite loop through this function. */
- if (c->ts.type == BT_DERIVED && c->attr.pointer
+ if (c->ts.type == BT_DERIVED
+ && (c->attr.pointer || c->attr.allocatable)
&& sym == c->ts.u.derived)
continue;
diff --git a/gcc/testsuite/gfortran.dg/pr107872.f90 b/gcc/testsuite/gfortran.dg/pr107872.f90
new file mode 100644
index 00000000000..09838479e92
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107872.f90
@@ -0,0 +1,40 @@
+! { dg-do run }
+!
+! Test the fix for PR107872, where an ICE occurred in
+! resolve.cc(derived_inaccessible) because derived types with
+! recursive allocatable components were not catered for.
+!
+module mod1
+ type t
+ integer :: data
+ type(t), allocatable :: next
+ contains
+ procedure, private :: write_t
+ generic :: write(formatted) => write_t
+ end type
+contains
+ recursive subroutine write_t(this, unit, iotype, v_list, iostat, iomsg)
+ class(t), intent(in) :: this
+ integer, intent(in) :: unit
+ character(*), intent(in) :: iotype
+ integer, intent(in) :: v_list(:)
+ integer, intent(out) :: iostat
+ character(*), intent(inout) :: iomsg
+ if (ALLOCATED(this%next)) &
+ write (unit, '(dt)') this%next
+ write (unit, '(i2)') this%data
+ end subroutine
+end module
+
+ use mod1
+ type(t) :: a
+ character (8) :: buffer
+ a%data = 1
+ allocate (a%next)
+ a%next%data = 2
+ allocate (a%next%next)
+ a%next%next%data = 3
+ write (buffer, '(dt)')a
+ deallocate (a%next)
+ if (trim (buffer) .ne. ' 3 2 1') stop 1
+end
--
2.35.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fortran: ICE on recursive derived types with allocatable components [PR107872]
2022-12-09 21:27 [PATCH] Fortran: ICE on recursive derived types with allocatable components [PR107872] Harald Anlauf
@ 2022-12-09 21:58 ` Paul Richard Thomas
0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2022-12-09 21:58 UTC (permalink / raw)
To: Harald Anlauf; +Cc: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 644 bytes --]
Hi Harald,
Thanks for doing that. My attention is elsewhere gfortran-wise.
Good for mainline.
Paul
On Fri, 9 Dec 2022 at 21:27, Harald Anlauf via Fortran <fortran@gcc.gnu.org>
wrote:
> Dear all,
>
> I am submitting the attached simple - and obvious - patch on
> behalf of Paul. It prevents a resource exhaustion due to an
> infinite loop, and has been regtested by multiple contributers, ;-)
> at least on x86_64-pc-linux-gnu.
>
> I intend to commit it to mainline within 24 hours, unless
> there are further comments.
>
> Thanks,
> Harald
>
>
--
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-09 21:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-09 21:27 [PATCH] Fortran: ICE on recursive derived types with allocatable components [PR107872] Harald Anlauf
2022-12-09 21:58 ` Paul Richard Thomas
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).