From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by sourceware.org (Postfix) with ESMTPS id 40F843856B60; Fri, 9 Dec 2022 21:27:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 40F843856B60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1670621235; bh=V6AsqVvs3J/PtVeUM/lJ3IunMSsRUNSU7o5XcSdap8E=; h=X-UI-Sender-Class:From:To:Subject:Date; b=CfQLrAfv8E2rWQWS7Sy8TWlmjsjX/wvxq3Uo1fBQKeWyfkQx6sgJU2+zkKZFrnu3R WxHyUygjoANPzxSYMpXBAN/W2P6X+IrHWF1BCFJ0XeRLpJ7je0dRGAAo02if3Bo73V QSIR+/EBHLGq7U6cALTbiBtvTWzc97oc4ebU6x/7DtkMpyx4JCTorKWdcMVzOse4JO oQLPIC3QA6I5XgPYk9gagFB+nCm+MOQSyQuNHhvbDCQTVYrkO+FjbhN5GSIUbLcI4o 0l63EaY50I4V6LAtUiOV/XN3sdD2iJFSxIDBG07Sicm7pbLz43sPdxzx5QB4zjkKJV qwbXMZPu56+jQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.90.18] ([93.207.90.18]) by web-mail.gmx.net (3c-app-gmx-bs62.server.lan [172.19.170.146]) (via HTTP); Fri, 9 Dec 2022 22:27:15 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: ICE on recursive derived types with allocatable components [PR107872] Content-Type: multipart/mixed; boundary=sgnirk-e0b57171-9f56-47d2-909d-61ac99216690 Date: Fri, 9 Dec 2022 22:27:15 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1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cL9uTEeG6VVMhRxD6YfmqKpyBdb+aB mNyK88bamzXESfLhj/EZbMSjg2Q8PzUpGk5+kwfuMtGuEggdzq4qse2Y8FNIIxnPEMDHZ2mQB BW/hbp8ehCJTri8FeV9xpBIg== X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --sgnirk-e0b57171-9f56-47d2-909d-61ac99216690 Content-Type: text/plain; charset=UTF-8 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 --sgnirk-e0b57171-9f56-47d2-909d-61ac99216690 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr107872.diff Content-Transfer-Encoding: quoted-printable =46rom 01254aa2eb766c7584fd047568d7277d4d65d067 Mon Sep 17 00:00:00 2001 From: Paul Thomas 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. =2D-- 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 =2D-- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -7536,7 +7536,8 @@ derived_inaccessible (gfc_symbol *sym) for (c =3D sym->components; c; c =3D c->next) { /* Prevent an infinite loop through this function. */ - if (c->ts.type =3D=3D BT_DERIVED && c->attr.pointer + if (c->ts.type =3D=3D BT_DERIVED + && (c->attr.pointer || c->attr.allocatable) && sym =3D=3D c->ts.u.derived) continue; diff --git a/gcc/testsuite/gfortran.dg/pr107872.f90 b/gcc/testsuite/gfortr= an.dg/pr107872.f90 new file mode 100644 index 00000000000..09838479e92 =2D-- /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) =3D> 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 =3D 1 + allocate (a%next) + a%next%data =3D 2 + allocate (a%next%next) + a%next%next%data =3D 3 + write (buffer, '(dt)')a + deallocate (a%next) + if (trim (buffer) .ne. ' 3 2 1') stop 1 +end =2D- 2.35.3 --sgnirk-e0b57171-9f56-47d2-909d-61ac99216690--