From patchwork Wed Dec 16 22:23:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1417410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cx8mC4Mwkz9sT5 for ; Thu, 17 Dec 2020 09:23:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A8E8E388C033; Wed, 16 Dec 2020 22:23:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 1CAB4385702D; Wed, 16 Dec 2020 22:23:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1CAB4385702D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: wmpw3cvekKaQbkqZfHBKHhUQTYzFFabWBOvT3oVLJwp+UoPbMIcs/AmgCK3OoTQZVnzHiZNHht HkoQWORSBzoogXqdx1MeYmJgZCtamC9qwHM5D3WnF7dFUS6mWf15ruTd7F9BUtvGn2HNJOfdwQ 0iJrcCDCETY7ds4ISbARuvDX64T68ojsDQfCH8A55Nxvvkct5611oFmaSGOyNSWjmRANcFg/3V 5a+U2rRp/AsrL+OcOpoC4Obtax7a9r0AbNL2sUyy50BJfJ7q1q5Hxed1dftlTrEeYSUvdtNUWt Ii8= X-IronPort-AV: E=Sophos;i="5.78,425,1599552000"; d="diff'?scan'208";a="58545584" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 16 Dec 2020 14:23:10 -0800 IronPort-SDR: PMtMEo3f5HNFOsLmlSv9RsO3EHqu18MgGuHUJYR79cGurXzrnf934gyaIA4OgDVkuUK36/AccI htVxjRXmv9ecN8kcJMCmZYsXIOji2UxRWb2WCU2MdFOCVjlji5wBTw3Fr2x8RjeoruH1nbHxJK h8kzkIx+O/u7ueKnaROd97DoeIutemPlS6ncf0b5cf5vzMmAIvR1CPQvlu5XF0bK6Hrere3P6+ tfar5pXCnsGv/kDZv8vqXFIkfgZdhzgpPryErWVAPpFZ3LRU7cxcQfU99wIPt+iwR+8Ffp5Kb8 x7U= To: gcc-patches , fortran From: Tobias Burnus Subject: [Patch] Fortran: Delay vtab generation until after parsing [PR92587] Message-ID: <6b20a856-d983-5e37-47d2-6749a1a6cfcf@codesourcery.com> Date: Wed, 16 Dec 2020 23:23:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-05.mgc.mentorg.com (139.181.222.5) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Calling gfc_find_vtab during resolution during parsing comes too early for finalizers. This patch just moves it to the resolution, which seems to be the simplest solution. (I tried way more complicated ones which do not work; thus, I settled for the simple solution ...) OK for GCC 9/10/mainline? Tobias PS: I was wondering about FORALL (which is resolved separately), but as "f = b" does not work (missing loop index) and as "f(i)%a = b" is broken (no reallocation, no __copy call, → https://gcc.gnu.org/PR98336 ) I think no action is needed for now. ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter Fortran: Delay vtab generation until after parsing [PR92587] gcc/fortran/ChangeLog: PR fortran/92587 * match.c (gfc_match_assignment): Move gfc_find_vtab call from here ... * resolve.c (gfc_resolve_code): ... to here. gcc/testsuite/ChangeLog: PR fortran/92587 * gfortran.dg/finalize_37.f90: New test. gcc/fortran/match.c | 3 -- gcc/fortran/resolve.c | 3 ++ gcc/testsuite/gfortran.dg/finalize_37.f90 | 51 ++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index bee73e7b008..c13fe96ed33 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -1389,9 +1389,6 @@ gfc_match_assignment (void) gfc_check_do_variable (lvalue->symtree); - if (lvalue->ts.type == BT_CLASS) - gfc_find_vtab (&rvalue->ts); - return MATCH_YES; } diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 05a5e43c90b..1da7ba4d031 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -11896,6 +11896,9 @@ start: if (!t) break; + if (code->expr1->ts.type == BT_CLASS) + gfc_find_vtab (&code->expr2->ts); + /* Remove a GFC_ISYM_CAF_GET inserted for a coindexed variable on the LHS. */ if (code->expr1->expr_type == EXPR_FUNCTION diff --git a/gcc/testsuite/gfortran.dg/finalize_37.f90 b/gcc/testsuite/gfortran.dg/finalize_37.f90 new file mode 100644 index 00000000000..3f872633fdd --- /dev/null +++ b/gcc/testsuite/gfortran.dg/finalize_37.f90 @@ -0,0 +1,51 @@ +! { dg-do compile } +! { dg-additional-options "-fdump-tree-original" } +! +! PR fortran/92587 +! + +module m + implicit none (type, external) + type t2 + contains + final :: fini + end type + type t3 + type(t2) :: a + end type + type, extends(t3) :: t4 + end type + class(t4), allocatable :: y + class(t4), allocatable :: z +contains + subroutine sub + y = z + end + subroutine fini(x) + type(t2) :: x + end +end + +module m2 + use m + implicit none (type, external) + type, extends(t3) :: t5 + end type + type, extends(t3) :: t6 + contains + final :: fin2 + end type +contains + subroutine bar(x, y, z) + class(t4), allocatable, intent(out) :: x + class(t5), allocatable, intent(out) :: y + class(t6), allocatable, intent(out) :: z + end + subroutine fin2 (x) + type(t6) :: x + end +end + +! { dg-final { scan-tree-dump "__final_m_T2 \\\(struct" "original" } } +! { dg-final { scan-tree-dump "__final_m_T3 \\\(struct" "original" } } +! { dg-final { scan-tree-dump "__final_m2_T6 \\\(struct" "original" } }