From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id 3D5E93858D1E; Fri, 24 Mar 2023 18:41:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D5E93858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679683305; bh=KEnQUaE0TrQ8Th90fi7R6eS0gkerSDw19vL30tevJVU=; h=From:To:Subject:Date:From; b=NJwbFW1Pq1eWKy7C+l2+MUVgbX2OZtnrCAj+4h6S+woN5acropioHk83LzI3t5Bqd xgwxLgcsddjl7u06GoXYA7TPLZhTzb6ReAi5qkVW0OaTKq05gTlShmIeVJU4j1/5nW Mqhc5j+jhcPB73leu+GbGFPfyYFhqHnQ6+GjUOs8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10594] Fortran: procedures with BIND(C) attribute require explicit interface [PR85877] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 6d3c71225d69305f9456c92f9da8c9e06bbaaca6 X-Git-Newrev: 0257ba766443f11cf61c52db9b480337e44b48c8 Message-Id: <20230324184145.3D5E93858D1E@sourceware.org> Date: Fri, 24 Mar 2023 18:41:45 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0257ba766443f11cf61c52db9b480337e44b48c8 commit r11-10594-g0257ba766443f11cf61c52db9b480337e44b48c8 Author: Harald Anlauf Date: Fri Mar 17 22:24:49 2023 +0100 Fortran: procedures with BIND(C) attribute require explicit interface [PR85877] gcc/fortran/ChangeLog: PR fortran/85877 * resolve.c (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. (cherry picked from commit 5426ab34643d9e6502f3ee572891a03471fa33ed) Diff: --- gcc/fortran/resolve.c | 10 ++++++++++ gcc/testsuite/gfortran.dg/pr85877.f90 | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 939b740df61..155005d30bb 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -13516,6 +13516,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..d8f08cbd210 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr85877.f90 @@ -0,0 +1,25 @@ +! { dg-do compile } +! PR fortran/85877 +! A procedure with the bind(c) attribute shall have an explicit interface +! Contributed by G. Steinmetz + +function f() bind(c) + f = 42. +end + +subroutine p + bind(c) f ! { dg-error "must be explicit" } + x = f() +end + +function g() bind(c) + g = 42. +end + +subroutine s + interface + function g() bind(c) + end function g + end interface + x = g() +end