From patchwork Wed Sep 29 08:53:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 45546 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56BFA3857C59 for ; Wed, 29 Sep 2021 08:53:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 4AEB93858D35; Wed, 29 Sep 2021 08:53:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4AEB93858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: /6cUnGjLXt3NuVQMvovvWQ3vNdmqHN/hRaBwSkIBjcQ5xNkiAKQjE6N3IYXvkk34dTn0R9NAER Q/w2uPGB80itCjif8dEsFXlLWxN24ALCbA7avgdyxg/8x1N3XQbBwirqp0i6/t4GdBGpD+Ufua Fy1NGGGDDoohmEplb0KtRe3g966EtHDaeB/Uwikuv3cqX9zy8qMM0j67A9sRyGbphlevz+CtOW mi/+5mLy104me4d2Os8FEOOLN73f7yo1BJCDMV2VdtfJNYoEEr66xubNgPTa1xqeI3Cbs1hPpW 5KRosP0Kh5YPPzAhZSRKQEjv X-IronPort-AV: E=Sophos;i="5.85,331,1624348800"; d="diff'?scan'208";a="66485166" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 29 Sep 2021 00:53:25 -0800 IronPort-SDR: z27Vc0BCmCpEm1WvKSfNbaOLWrjPjQBlDsrOxomkvntXGIh7z+m5Vmraq+hPhm6MbVI0+CNL2J 4eYiV2h//n3xZZ3k+9J9NYw7/DUlsFSa4WFIV8+uxs1ZJFu0p4idsTQYS9mNXG2vmqxKDIwY3P atxC+GOF4+yNmTNVPkbaL0Y4KmKlx9LS56V/rjSuIEIbC3deIOduU5jSrazZfftA8OjiZ5Wqg2 1ohWUHwaK+jtqwb5owd79dIAj3//of3ugCwLYmHiYn1zdBC6S94LVYPpXCjdls1OS9Ws9XwViG iDc= To: gcc-patches , fortran From: Tobias Burnus Subject: [Patch] Fortran: Avoid var initialization in interfaces [PR54753] Message-ID: <40ee9c33-3122-54aa-a43b-655bb280b7fc@codesourcery.com> Date: Wed, 29 Sep 2021 10:53:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Found when looking at F2018:C839 / PR54753. For INTENT(OUT) the dummy variable (might) also be default initialized or deallocated. However, with assumed rank, that causes issues, which C839 prevents. In the current GCC implementation, missing C839 constraint diagnostic, but also rejects-valid/ice-on-valid appears. There are three issues, this patch solves the first: * reject-valid issue due to adding the initializer also to a dummy argument which is in an INTERFACE block. Having initializers in INTERFACE blocks is pointless and causes for the attached testcase the bogus error: "Assumed-rank variable y at (1) may only be used as actual argument" (Except for wasting resources and this error, they should be ignored in trans*.c and usually do not cause any further harm.) I think Sandra has a nearly ready patch to do the C839 constraint diagnostic, which needs the attached patch to do the checks. The third issue is that GCC currently gives either an ICE or the above error message when declaring a procedure with a valid assumed-rank intent(out) dummy. This has still to be solved as well. But first I wanted to unblock Sandra's C839 work with this patch :-) Regarding the patch, '!= IFSRC_IFBODY' has to be used; "== IFSRC_DECL" won't work as the the generatedy ENTRY master function has IFSRC_UNKNOWN. OK for mainline? Tobias PS: Some patch reviews are that fast that it is impossible to send the OK; at least, I did not manage to do for Harald's last two - for the last one I was at least 4min too late. ;-) ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 Fortran: Avoid var initialization in interfaces [PR54753] Intent(out) implies deallocation/default initialization; however, it is pointless to do this for dummy-arguments symbols of procedures which are inside an INTERFACE block. – This also fixes a bogus error for the attached included testcase, but fixing the non-interface version still has to be done. PR fortran/54753 gcc/fortran/ChangeLog: * resolve.c (can_generate_init, resolve_fl_variable_derived, resolve_symbol): Only do initialization with intent(out) if not inside of an interface block. gcc/testsuite/ChangeLog: * gfortran.dg/assumed_rank_23.f90: New test. gcc/fortran/resolve.c | 11 ++++++++--- gcc/testsuite/gfortran.dg/assumed_rank_23.f90 | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 30b96b2f597..5d2478d9b96 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -12676,7 +12676,8 @@ can_generate_init (gfc_symbol *sym) || a->cray_pointer || sym->assoc || (!a->referenced && !a->result) - || (a->dummy && a->intent != INTENT_OUT) + || (a->dummy && (a->intent != INTENT_OUT + || sym->ns->proc_name->attr.if_source != IFSRC_DECL)) || (a->function && sym != sym->result) ); } @@ -12913,7 +12914,9 @@ resolve_fl_variable_derived (gfc_symbol *sym, int no_init_flag) /* Assign default initializer. */ if (!(sym->value || sym->attr.pointer || sym->attr.allocatable) - && (!no_init_flag || sym->attr.intent == INTENT_OUT)) + && (!no_init_flag + || (sym->attr.intent == INTENT_OUT + && sym->ns->proc_name->attr.if_source == IFSRC_DECL))) sym->value = gfc_generate_initializer (&sym->ts, can_generate_init (sym)); return true; @@ -16154,7 +16157,8 @@ resolve_symbol (gfc_symbol *sym) || sym->ts.u.derived->attr.alloc_comp || sym->ts.u.derived->attr.pointer_comp)) && !(a->function && sym != sym->result)) - || (a->dummy && a->intent == INTENT_OUT && !a->pointer)) + || (a->dummy && !a->pointer && a->intent == INTENT_OUT + && sym->ns->proc_name->attr.if_source == IFSRC_DECL)) apply_default_init (sym); else if (a->function && sym->result && a->access != ACCESS_PRIVATE && (sym->ts.u.derived->attr.alloc_comp @@ -16166,6 +16170,7 @@ resolve_symbol (gfc_symbol *sym) if (sym->ts.type == BT_CLASS && sym->ns == gfc_current_ns && sym->attr.dummy && sym->attr.intent == INTENT_OUT + && sym->ns->proc_name->attr.if_source == IFSRC_DECL && !CLASS_DATA (sym)->attr.class_pointer && !CLASS_DATA (sym)->attr.allocatable) apply_default_init (sym); diff --git a/gcc/testsuite/gfortran.dg/assumed_rank_23.f90 b/gcc/testsuite/gfortran.dg/assumed_rank_23.f90 new file mode 100644 index 00000000000..c83aa7de1a3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/assumed_rank_23.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! +! PR fortran/54753 +! TS29113:C535c +! F2018:C839 +! +module m + + interface + subroutine s1 (x, y) + class(*) :: x(..) + class(*), intent (out) :: y(..) + end subroutine + end interface + +end module