From patchwork Fri Mar 17 21:36:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 71458 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2222wrt; Fri, 17 Mar 2023 14:37:31 -0700 (PDT) X-Google-Smtp-Source: AK7set8daFcpDUgMoHDHvSMzJgZnAXD1MrMcx3SVxOXuS59p8E6jyKqS8wMG23m5CNBeQbdXoaeq X-Received: by 2002:a17:906:2a51:b0:87f:5d0a:c610 with SMTP id k17-20020a1709062a5100b0087f5d0ac610mr789753eje.32.1679089051217; Fri, 17 Mar 2023 14:37:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679089051; cv=none; d=google.com; s=arc-20160816; b=lvbxJe5Ec6h2FQ53MWIOGKB2MNiS5HoqRL8bUcRD9+cJYL4mdu1ycP36HcSV56jeQL u0T5X3jtntLU6Kp4/hxhj+cZGXffhEDdlgOM1cgYOo7EKHSzE7Hq56W9XgtesEgcTPFl oocMa2mauNNUpl1BVhWoHBfB/Jspl3x2tTp5X3tqbPvRxZFHPlh2fSToCK/yCnCFpWdQ D/nwaRwzaKFEw+RjH0HvxKaoQCXCl03CGnChrFL3GuQmMDgpjfp0UCoteS0SqmHMCdzS K3CMXfMBJCWmZMfHhMJcRRciI28EYHCGkUX2HZp0jjzyBCEiHWo1BYmCC0hkGHWx1Cvp dxcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=bZ3oqbW0rbLeGKviUY7VP0Zx4dA9KRjIh0t+AUxsrAk=; b=jxZfCUcksuiBV3dQuz4gM+N7us8yWoPUM//GdH/SM/jJ7WcDTFyZALHjGLlOTEYNaC VW46OItGb9VnNaGpksM/lyUihp8fnKlqzTipbE+GANOqamUjKN4CRCQs5BuRkBCzj7c7 voAlB87d2RjoIgwxvXj/JnJd3cV+iRLt00gdvtCi4xNvw20ifZFCrewCMBclqteMBykD z6IkfgzBR73VecvmIeUnWmWtesYXwnBeJ+PlF3nWpvsUtFmzhy7RsdJzv8ttztmZQA6c 5JkA1j8+WTyOjHeZUyRQ7eq/rJIswwejzv6k2+LGQVlKSSB4hTBXbjgEDsR9k6+5GrH5 Jh/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LvoO2lFS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i14-20020a1709064ece00b00930ca0feb65si3020339ejv.1001.2023.03.17.14.37.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 14:37:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LvoO2lFS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E48483850429 for ; Fri, 17 Mar 2023 21:37:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E48483850429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679089048; bh=bZ3oqbW0rbLeGKviUY7VP0Zx4dA9KRjIh0t+AUxsrAk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LvoO2lFSMVMQtBz2RoOuonK9m7vmLM7JQ4jBDOFHX6j51cX6oEPRzLqYnGsWthWXc oyo6IlyHtZhZD3N+JMvHjPq59bd6pnjfeungkUJdDWHYK6EGBCXVUbtuw5mdBkq+dC E2Ncj6Fuz6bLajgV8X8N2SZCNzwRrNHpCaXrx/wo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by sourceware.org (Postfix) with ESMTPS id 3C9633851402; Fri, 17 Mar 2023 21:36:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C9633851402 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.82.104] ([93.207.82.104]) by web-mail.gmx.net (3c-app-gmx-bs05.server.lan [172.19.170.54]) (via HTTP); Fri, 17 Mar 2023 22:36:43 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: procedures with BIND(C) attribute require explicit interface [PR85877] Date: Fri, 17 Mar 2023 22:36:43 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:FoLZdNaKuuGMPZpW3bDFdKYnD4GXqfzuHUf9QixG6F/oZQ9ODBesV41SkAo57eoCJtwee /OzgMxzMxeWZDlqfkWo2J5mAH/zWz7hilM38/rd4ywDIoCvpNnx9vhHOMVFxn7PG9LRbOY9R6wD1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spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760652481417014818?= X-GMAIL-MSGID: =?utf-8?q?1760652481417014818?= 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 From c48c670ff0ce4f0d2ffb1d43aca2ec1bed1fa2ef Mon Sep 17 00:00:00 2001 From: Harald Anlauf 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