From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ciao.gmane.io (ciao.gmane.io [116.202.254.214]) by sourceware.org (Postfix) with ESMTPS id 6EA933858C2B for ; Sat, 18 Mar 2023 20:59:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6EA933858C2B Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=m.gmane-mx.org Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1pdddv-0004TH-Mi for gcc-patches@gcc.gnu.org; Sat, 18 Mar 2023 21:59:11 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: gcc-patches@gcc.gnu.org From: Harald Anlauf Subject: Re: [PATCH] Fortran: procedures with BIND(C) attribute require explicit interface [PR85877] Date: Sat, 18 Mar 2023 21:59:07 +0100 Message-ID: References: <3496724e-5ebd-d133-c6f6-807068b175f4@netcologne.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Content-Language: en-US In-Reply-To: <3496724e-5ebd-d133-c6f6-807068b175f4@netcologne.de> Cc: fortran@gcc.gnu.org X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,BODY_8BITS,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20230318205907.NpAC_QsT5O8w_YExeG9TXQRNNR-QYAAasyISkFzXguM@z> Hi Thomas, Am 18.03.23 um 19:52 schrieb Thomas Koenig via Gcc-patches: > Hi Harald, > >> the Fortran standard requires an explicit procedure interface in certain >> situations, such as when they have a BIND(C) attribute (F2018:15.4.2.2). >> The attached patch adds a check for this. >> >> Regtested on x86_64-pc-linux-gnu.  OK for mainline? > > While this fixes the ICE, it misses > > function f() bind(c) >   f = 42. > end > > subroutine p >   bind(c) f     ! { dg-error "must be explicit" } >   x = f() > end what do you mean by "it misses"? I do not see an explicit interface here, only a global symbol. All compiler I tried with the above code reject it one way or the other, e g. Cray: x = f() ^ ftn-954 crayftn: ERROR P, File = pr85877-2.f90, Line = 12, Column = 3 Procedure "f", referenced at line 6 (pr85877-2.f90) must have an explicit interface because one or more arguments have the BIND attribute. > subroutine s >   interface >      function g() bind(c) >      end function g >   end interface >   x = g() > end > > where the interface is picked up via a global symbol. Is it really true that this is in the spirit of the standard? Is the global declaration above really equivalent to an explicit interface? I would expect legal code to be like: function g() bind(c) g = 42. end subroutine s interface function g() bind(c) end function g end interface x = g() end unless you do it in the context of a module and in the right way. > This code > may not be valid; nagfor rejects it, but I cannot find a > constraint at least in the F2022 draft that prohibits it. I thought that F2018:15.4.2.2 and F2023:15.4.2.2(7) are rather clear and "explicit" on this. IMHO the case of "f" above seems to be excluded and thus not conforming. > Hm... might it be better to check for attr->module_procedure || > attr->if_source == IFSRC_IFBODY? Maybe we should find a set of legal and illegal cases that we can agree upon. Thanks, Harald > Best regards > >     Thomas > >