From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx-relay05-hz2.antispameurope.com (mx-relay05-hz2.antispameurope.com [83.246.65.91]) by sourceware.org (Postfix) with ESMTPS id 910FB3858423 for ; Sat, 2 Oct 2021 19:57:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 910FB3858423 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=net-b.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=net-b.de Received: from s041.wsp.plusnet.de ([195.90.7.81]) by mx-relay05-hz2.antispameurope.com; Sat, 02 Oct 2021 21:56:58 +0200 Received: from [172.30.68.158] (nat-dem.mentorg.com [139.181.48.2]) by s041.wsp.plusnet.de (Postfix) with ESMTPSA id 3608A2C00BB; Sat, 2 Oct 2021 21:56:54 +0200 (CEST) Subject: Re: [Patch] Fortran: Avoid var initialization in interfaces [PR54753] To: Sandra Loosemore , Tobias Burnus , gcc-patches , fortran , Harald Anlauf References: <40ee9c33-3122-54aa-a43b-655bb280b7fc@codesourcery.com> <0131e2d5-be68-d3b1-b90f-6640c358e1ab@codesourcery.com> From: Tobias Burnus Message-ID: <185251be-e866-4d5e-0deb-944940cd5511@net-b.de> Date: Sat, 2 Oct 2021 21:56:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------B39B0F27007B429E5FC02911" Content-Language: en-US X-cloud-security-sender: burnus@net-b.de X-cloud-security-recipient: gcc-patches@gcc.gnu.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mx-relay05-hz2.antispameurope.com with ED1358C131E X-cloud-security-connect: s041.wsp.plusnet.de[195.90.7.81], TLS=1, IP=195.90.7.81 X-cloud-security-Digest: d2a6205098d32808b38bffbf4fb75011 X-cloud-security: scantime:1.581 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: , X-List-Received-Date: Sat, 02 Oct 2021 19:57:02 -0000 This is a multi-part message in MIME format. --------------B39B0F27007B429E5FC02911 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Harald, unfortunately, your email did not arrive at fortran@gcc.gnu.org – nor at my private address. I copied it from https://gcc.gnu.org/pipermail/gcc-patches/2021-October/580794.html You wrote: > >/I do not see this error. Can you double check that you indeed use the />/posted patch: />//>/https://gcc.gnu.org/pipermail/gcc-patches/2021-September/580483.html > – />/and nothing else, e.g., an earlier draft? / > Sandra is right. Actually I do see that regression, too. > The default initialization is missing in F1, see dump-tree: Look as if I had attached the first/interim version of the patch – which lacked what I wrote in the patch submission at: https://gcc.gnu.org/pipermail/gcc-patches/2021-September/580483.html Namely, I wrote: > Regarding the patch, '!= IFSRC_IFBODY' has to be used; "== IFSRC_DECL" > won't work as the the generatedy ENTRY master function has IFSRC_UNKNOWN. Thus, no surprise that it passes here – while you see the fail. Tobias --------------B39B0F27007B429E5FC02911 Content-Type: text/x-patch; charset=UTF-8; name="intent-out.diff" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="intent-out.diff" 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..511fe3a5e55 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_IFBODY)) || (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_IFBODY))) 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_IFBODY)) 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_IFBODY && !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 --------------B39B0F27007B429E5FC02911--