From: Harald Anlauf <anlauf@gmx.de>
To: Thomas Koenig <tkoenig@netcologne.de>,
fortran <fortran@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fortran: procedures with BIND(C) attribute require explicit interface [PR85877]
Date: Sat, 18 Mar 2023 21:59:07 +0100 [thread overview]
Message-ID: <ce489a6c-9c95-d5de-0e8a-5a7d90c62600@gmx.de> (raw)
In-Reply-To: <3496724e-5ebd-d133-c6f6-807068b175f4@netcologne.de>
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
>
>
WARNING: multiple messages have this Message-ID
From: Harald Anlauf <anlauf@gmx.de>
To: gcc-patches@gcc.gnu.org
Cc: fortran@gcc.gnu.org
Subject: Re: [PATCH] Fortran: procedures with BIND(C) attribute require explicit interface [PR85877]
Date: Sat, 18 Mar 2023 21:59:07 +0100 [thread overview]
Message-ID: <ce489a6c-9c95-d5de-0e8a-5a7d90c62600@gmx.de> (raw)
Message-ID: <20230318205907.NpAC_QsT5O8w_YExeG9TXQRNNR-QYAAasyISkFzXguM@z> (raw)
In-Reply-To: <3496724e-5ebd-d133-c6f6-807068b175f4@netcologne.de>
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
>
>
next prev parent reply other threads:[~2023-03-18 20:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-17 21:36 Harald Anlauf
2023-03-18 18:52 ` Thomas Koenig
2023-03-18 20:59 ` Harald Anlauf [this message]
2023-03-18 20:59 ` Harald Anlauf
2023-03-19 7:34 ` Thomas Koenig
2023-03-19 19:38 ` Harald Anlauf
2023-03-19 19:38 ` Harald Anlauf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ce489a6c-9c95-d5de-0e8a-5a7d90c62600@gmx.de \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=tkoenig@netcologne.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).