From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: procedures with BIND(C) attribute require explicit interface [PR85877]
Date: Fri, 17 Mar 2023 22:36:43 +0100 [thread overview]
Message-ID: <trinity-7cc4f143-7033-4551-af8d-b4fbe021637d-1679089003636@3c-app-gmx-bs05> (raw)
[-- Attachment #1: Type: text/plain, Size: 363 bytes --]
Dear all,
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?
The PR marks this as a long-time regression, so it might be backported
to all open branches.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr85877.diff --]
[-- Type: text/x-patch, Size: 1895 bytes --]
From c48c670ff0ce4f0d2ffb1d43aca2ec1bed1fa2ef Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Fri, 17 Mar 2023 22:24:49 +0100
Subject: [PATCH] Fortran: procedures with BIND(C) attribute require explicit
interface [PR85877]
gcc/fortran/ChangeLog:
PR fortran/85877
* resolve.cc (resolve_fl_procedure): Check for an explicit interface
of procedures with the BIND(C) attribute (F2018:15.4.2.2).
gcc/testsuite/ChangeLog:
PR fortran/85877
* gfortran.dg/pr85877.f90: New test.
---
gcc/fortran/resolve.cc | 10 ++++++++++
gcc/testsuite/gfortran.dg/pr85877.f90 | 17 +++++++++++++++++
2 files changed, 27 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/pr85877.f90
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 46585879ddc..7ec65f16240 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -13661,6 +13661,16 @@ check_formal:
}
}
}
+
+ /* F2018:15.4.2.2 requires an explicit interface for procedures with the
+ BIND(C) attribute. */
+ if (sym->attr.is_bind_c && sym->attr.if_source == IFSRC_UNKNOWN)
+ {
+ gfc_error ("Interface of %qs at %L must be explicit",
+ sym->name, &sym->declared_at);
+ return false;
+ }
+
return true;
}
diff --git a/gcc/testsuite/gfortran.dg/pr85877.f90 b/gcc/testsuite/gfortran.dg/pr85877.f90
new file mode 100644
index 00000000000..675faac0027
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr85877.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! PR fortran/85877
+! A procedure with the bind(c) attribute shall have an explicit interface
+! Contributed by G. Steinmetz
+
+subroutine p
+ bind(c) f ! { dg-error "must be explicit" }
+ x = f()
+end
+
+subroutine s
+ interface
+ function g() bind(c)
+ end function g
+ end interface
+ x = g()
+end
--
2.35.3
next reply other threads:[~2023-03-17 21:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-17 21:36 Harald Anlauf [this message]
2023-03-18 18:52 ` Thomas Koenig
2023-03-18 20:59 ` Harald Anlauf
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=trinity-7cc4f143-7033-4551-af8d-b4fbe021637d-1679089003636@3c-app-gmx-bs05 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/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).