From patchwork Fri Dec 9 21:27:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 31927 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp999040wrr; Fri, 9 Dec 2022 13:28:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf7hM3qdhuqZ/Np6dWIglhrVje8MsUm4wuCaLGR0jVM1OP71SJSBI6oQAY4bES3tKIuC55ei X-Received: by 2002:a05:6402:14a:b0:467:8e69:ff10 with SMTP id s10-20020a056402014a00b004678e69ff10mr6615623edu.26.1670621305787; Fri, 09 Dec 2022 13:28:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670621305; cv=none; d=google.com; s=arc-20160816; b=pHs71YYZbo3psW7/vfti9cB7VetHr1h8rX+wuBgdKg4yO5rHvZGiqDIWDuRfprrIyc AsY03KQAZkh1ipbxvfQHpNaVckZJsyoV0i+be8ohNEwgDt9EW5BCIlVTXNh4txQphXUl obVhhBCx/cgjCz6ceHpZQT7TpdGxJRPU7pSa3pE0ns85xHY5XgHYA3DomsNxbBIEKEEf 1NfQZJh6qXDZ/GzfYwgwEPy1h6qoKI6Pz4ephMLSFB2FOU/L7m8jGp5gkiiGyHQ8ShHS 1LYTSlXAexWDBiB977aQWwEs/fCLIm1CW7k7Vqty6mkca0YTrcxvPvTs65YDDZK487HX px3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=BVTmZ7MV9jnjBcGq2qFRB7MMtPdl69dgB9mAUKal+2Y=; b=CCLVFMj2h+80l+Fyza3jJ83W9eb5OKYkxUCQN+1qDYBK+QEfrnZ9Osf74x+k55p6XW wP4x0slKDH86/3htI5qLFRZ0CM6cKqCNJdfcuhZmqerMCdWDz0u+imPklDLv2kdGIQek 6XaQNdywplVZ01ZsmAKa4Q9vu+lvEJEDV3ZW0JnjakaPMBKozFKM3VgnPrieJU7hR6UA mr9COMqzxyEun/nJ1Udg5i6/qeUMTCi50P2otjRhZYt6+4aJGqASpcy2Wln7lhVFLPVE SMM+MomlikhB6IpXVALDQmCUtrSbyffVLMBI42V3c+2g0Lx0qvtU5Od6+R00qRt2Jdiv Rhng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VTOhg5nT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o7-20020aa7d3c7000000b0046ac332a141si1807281edr.628.2022.12.09.13.28.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 13:28:25 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=VTOhg5nT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 40BD0383AB4C for ; Fri, 9 Dec 2022 21:28:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 40BD0383AB4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670621304; bh=BVTmZ7MV9jnjBcGq2qFRB7MMtPdl69dgB9mAUKal+2Y=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VTOhg5nTnZS+belznLo8nfKYjxPySC2kofCHMODpdFoFoqvJOFWbQGbzGgs9WVFsV nbBcX5J22EXut9mpYQFaBwqjvDb4FQ+ovpfJyJB7b7OhAxaKgljR6xdObmdYNe2Eyc uRiMoIzBgrlMuFaGCgZSE23G6Dbyw/ey2ilNBSnM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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: To: fortran , gcc-patches Subject: [PATCH] Fortran: ICE on recursive derived types with allocatable components [PR107872] Date: Fri, 9 Dec 2022 22:27:15 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:EfeS4ktOcula93DQ57TB5jjxZymyUQ/t0DSPtC6TojRNl6IhbVqhB8mjbO15Ru8xY1Jf3 b8Sh90Ao+KzUawrG/DYmjSHJQBC8vlbnCZbrCOoPcLpEEgKLm9UphU7QnB0W6Bm9SclMDAk+xpuh /GBNa4rZbJYd17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_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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751773405986613945?= X-GMAIL-MSGID: =?utf-8?q?1751773405986613945?= 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 From 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. --- 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