From patchwork Wed Sep 21 21:07:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp39555dyb; Wed, 21 Sep 2022 14:08:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6L2YQ+XbjvhHu1Rs9wJMjSYwo99TcjPg1g7IFcGfZN2vXdlnf5BXF/Twfn+Fdo+75Zp/9t X-Received: by 2002:a50:ee08:0:b0:44f:dc1:fc6b with SMTP id g8-20020a50ee08000000b0044f0dc1fc6bmr23774eds.15.1663794489171; Wed, 21 Sep 2022 14:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663794489; cv=none; d=google.com; s=arc-20160816; b=UW1BQhcR3woKeOMdl2NSFzT0kz/57TDAZjfz5wClA6fI4Xr5tmBk0rzZyN+61dRG3P 4HfcG4B8+pNnvfrljTm2n3h4WRS5bhZgeIqBqb1Mi3pMkivbH23yEVrVGZA5YcdzvBQD 8dB/eNB5VHf6K7wR1nzy3BcWDvarfsdBQ/adwjeWv/p0/6bVE59JKfq7EmScz7R5BoaO RfbIIoaMBvbr3eKCVvwMrtD0Y7/zOnMRC4BE0i/1XfiR1YX5jPLxMR/nNsGkKas7dY8R 1STWjWZi035F0lRpOE72dNXZNgbFV+IA86YmjIUwrEn2OsJ+np+Jpg2P0fsTOUDjegVC LRvQ== 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:sensitivity :importance:date:subject:to:message-id:mime-version:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=Vq9RArg1azfkG+ie5DTQEioIFNn1C9W5vjfSIbxnyoo=; b=n8kAIwKLn/IxrioZpvAifTeBIz7sUcEoWJ79y9m4yieU1uqPLuiyG+0DShzpnQqmMB i1C/UVul+fIIAjlrXUrg5+snx2IEcNF5DvtgdsGww5ctKSu9/kbGfWM9/OMy7GzACMq0 94WzdCRFWGR83zwmuwskask5cxUb6Doow85MEsFUjl6arpwri3AScndxyfGzeljwQJ1Z JTVOnoML+1X0cqVNbmHajafxmShYElozRyLmwVn3tSGCaqDKYtwHMWI6CvxXXJ8yukzR JCs7CHeN5lJFjMHDVeOW2hvJfEDtI1wnqpEHOMMrIIld8Rw6/HCu5T+NCauwTAgWTY0b kM8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="imHCRCa/"; 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 js17-20020a17090797d100b0073d9d374e81si3779585ejc.681.2022.09.21.14.08.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 14:08:09 -0700 (PDT) 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="imHCRCa/"; 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 1D3CB3858005 for ; Wed, 21 Sep 2022 21:08:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D3CB3858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663794487; bh=Vq9RArg1azfkG+ie5DTQEioIFNn1C9W5vjfSIbxnyoo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=imHCRCa/phyeBHXBRTPw8txHOzsW+sowYBH4ua+lksYjW7ybcgWy5yQ0JUmdpOC6B sH7nvu8F1sOySq4NXHwpYdRXgXTYmjM0EeOHFsi6SGt6rce2rLyrgR1h+Sqmq5ldgd zOIoqadVxGAjc5OZe6qGhAFd6Q2oSaGMRf3lkX8I= 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.17.20]) by sourceware.org (Postfix) with ESMTPS id 861533858C53; Wed, 21 Sep 2022 21:07:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 861533858C53 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.89.8] ([93.207.89.8]) by web-mail.gmx.net (3c-app-gmx-bap37.server.lan [172.19.172.107]) (via HTTP); Wed, 21 Sep 2022 23:07:04 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: Proxy ping [PATCH] Fortran: Fix automatic reallocation inside select rank [PR100103] Date: Wed, 21 Sep 2022 23:07:04 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:QQt/9iQW7qTGj7HvWu+7s6LcV1p/FB4NZ1HH857RemJM+QVGTFdRL3bJ4QhVpopn+Ur8s 2IRn+RgnN5R527iXlKwbti7RcOT2UjzXlXTSiZIhRR4qenbEQJosRY9JrW9esxXuk9H46x9Sjff8 db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REEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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?1744614970098739363?= X-GMAIL-MSGID: =?utf-8?q?1744614970098739363?= Dear all, the patch for this PR was submitted for review by Jose here: https://gcc.gnu.org/pipermail/fortran/2021-April/055934.html but unfortunately was never reviewed. I verified that it works on mainline and x86_64-pc-linux-gnu, and I think that it is fine. Although the above mail suggests that there is a dependency on the fix for another PR with a rather lengthy patch, it appears that this is no longer the case. It might be that the fix for PR100245 (another reallocation issue) already did the necessary job. So OK for mainline? Thanks, Harald From 6c93c5058f552f47a3d828d3fb19cca652901299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rui=20Faustino=20de=20Sousa?= Date: Wed, 21 Sep 2022 22:55:02 +0200 Subject: [PATCH] Fortran: Fix automatic reallocation inside select rank [PR100103] gcc/fortran/ChangeLog: PR fortran/100103 * trans-array.cc (gfc_is_reallocatable_lhs): Add select rank temporary associate names as possible targets of automatic reallocation. gcc/testsuite/ChangeLog: PR fortran/100103 * gfortran.dg/PR100103.f90: New test. --- gcc/fortran/trans-array.cc | 4 +- gcc/testsuite/gfortran.dg/PR100103.f90 | 76 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/PR100103.f90 diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 05134952db4..795ce14af08 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -10378,7 +10378,7 @@ gfc_is_reallocatable_lhs (gfc_expr *expr) /* An allocatable class variable with no reference. */ if (sym->ts.type == BT_CLASS - && !sym->attr.associate_var + && (!sym->attr.associate_var || sym->attr.select_rank_temporary) && CLASS_DATA (sym)->attr.allocatable && expr->ref && ((expr->ref->type == REF_ARRAY && expr->ref->u.ar.type == AR_FULL @@ -10393,7 +10393,7 @@ gfc_is_reallocatable_lhs (gfc_expr *expr) /* An allocatable variable. */ if (sym->attr.allocatable - && !sym->attr.associate_var + && (!sym->attr.associate_var || sym->attr.select_rank_temporary) && expr->ref && expr->ref->type == REF_ARRAY && expr->ref->u.ar.type == AR_FULL) diff --git a/gcc/testsuite/gfortran.dg/PR100103.f90 b/gcc/testsuite/gfortran.dg/PR100103.f90 new file mode 100644 index 00000000000..21405610a71 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR100103.f90 @@ -0,0 +1,76 @@ +! { dg-do run } +! +! Test the fix for PR100103 +! + +program main_p + implicit none + + integer :: i + integer, parameter :: n = 11 + + type :: foo_t + integer :: i + end type foo_t + + type(foo_t), parameter :: a(*) = [(foo_t(i), i=1,n)] + + type(foo_t), allocatable :: bar_d(:) + class(foo_t), allocatable :: bar_p(:) + class(*), allocatable :: bar_u(:) + + + call foo_d(bar_d) + if(.not.allocated(bar_d)) stop 1 + if(any(bar_d%i/=a%i)) stop 2 + deallocate(bar_d) + call foo_p(bar_p) + if(.not.allocated(bar_p)) stop 3 + if(any(bar_p%i/=a%i)) stop 4 + deallocate(bar_p) + call foo_u(bar_u) + if(.not.allocated(bar_u)) stop 5 + select type(bar_u) + type is(foo_t) + if(any(bar_u%i/=a%i)) stop 6 + class default + stop 7 + end select + deallocate(bar_u) + +contains + + subroutine foo_d(that) + type(foo_t), allocatable, intent(out) :: that(..) + + select rank(that) + rank(1) + that = a + rank default + stop 8 + end select + end subroutine foo_d + + subroutine foo_p(that) + class(foo_t), allocatable, intent(out) :: that(..) + + select rank(that) + rank(1) + that = a + rank default + stop 9 + end select + end subroutine foo_p + + subroutine foo_u(that) + class(*), allocatable, intent(out) :: that(..) + + select rank(that) + rank(1) + that = a + rank default + stop 10 + end select + end subroutine foo_u + +end program main_p -- 2.35.3