From patchwork Sun Mar 19 12:04:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Richard Thomas X-Patchwork-Id: 71763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp693366wrt; Sun, 19 Mar 2023 05:05:41 -0700 (PDT) X-Google-Smtp-Source: AK7set/i65GJn9GFXuOsQq2BPwwjVoO1kfojFaPoEogEoOYtBbQ7AHVqm0oz54Bl4N5955kbw5zj X-Received: by 2002:aa7:d5c7:0:b0:4fa:ada1:796d with SMTP id d7-20020aa7d5c7000000b004faada1796dmr9320112eds.10.1679227541419; Sun, 19 Mar 2023 05:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679227541; cv=none; d=google.com; s=arc-20160816; b=Ee+2CUP5feCvd6dPHG1VDBlDea0DC7pSwTDXhPShWS4QojU4hEwQ5KN8aDA20rE8oD MdB2Os9EG1AnOLOinPyCMYi+hgtwjJq2G0MR9uT3FI0CQ75CQmopYH9QIUhgmAwiLemx nUQevnuvNx5SjqiQ+HhLHRCRcZtVxFTSffxQ35zDLu/Mjw9ff0XJgRtns7i7vzGG8021 oSXe9h1s2q6ZfcDlHeYT4wjAEsBcy//cBNjLBXdzySEWChE1dWJpkg3crBROuEnFmRE/ tN+tIvthm4bpxCV+/dNDUaERxs2HpQIZHNoonkfNoU2JnEHtpQUM/Lk1JfvIzAE2pCjH W2aw== 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:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=xJ5OMQYZ9pPG6T6gNFOUQfxoCuNfyF9AGJwOdlDmcNY=; b=lIvofE5NtcN1IlE986Oan1RpSJoNA8j4xXVg1Vjn/u6pRmF0LEJ9rzssTnqKeiboLk KlL0I8catfdgX5uVqnzDtd4Tdj9jB9NX/anJD3njoEAWcPbEqxIbKQuGDOTx6cWIE6Hm PwrJmpv8Qro1navBIWXhu4kRlofVSoWfIXX1EBHZS6UjMaSiI3sQOTe7Hw+wuOT1fbxn DaqDsYsWHjDGweQ+mwIC53DRcZRJkscdZA/8ViGRtx34uQmHzWGBNCqjGtlr1y45+KIq B2COtHibLlE+L8wBB8x1Xr3coDORJwpQiRwoRzVc+rAGeETJhhmVsxKtqo6GFxmfhwCL qgaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=toSmy7sT; 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 ca23-20020aa7cd77000000b004cdc92cc419si7356410edb.11.2023.03.19.05.05.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 05:05:41 -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=toSmy7sT; 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 3B06E3857BA4 for ; Sun, 19 Mar 2023 12:05:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B06E3857BA4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679227540; bh=xJ5OMQYZ9pPG6T6gNFOUQfxoCuNfyF9AGJwOdlDmcNY=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=toSmy7sTrMCDaSgOaXuhoLxj5LUzKaQjX/6xCfuYJdks7TqL9OaC0dQYk1eZPxS6g 2tLnIlSrasjuFBmDz/V6Irou6soLLl3B5xHdona6ESAeHc/e+tTVWqzZUgOxhEURou dhk5VN4cNKuXZwL4pV6+B+raGHL7WFQGsfbnjk6g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 362143858D35; Sun, 19 Mar 2023 12:04:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 362143858D35 Received: by mail-pl1-x629.google.com with SMTP id o2so2354114plg.4; Sun, 19 Mar 2023 05:04:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679227476; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=tCWyHYyHi44U2IzIUStdlrJBMpFqgYMStf1v9rHv9MU=; b=QlkuO6ilOXaRWV1Jb9MmZd3uxAdP6fwJ3e4Bc1iMxdD6fO7tjzCjY37tzJOtL+8NN6 SF3kcQ+YKO+wthTNKEpYSJ+jGILyD+zrYWYQ/6VBEbvdc61Au81+T6IlyfhssY/VJLMy MVH5DCxykGysDwO794LCcVm8OBELaRDOo1khyHD9zmk22XrizZ/0D0Cmj+zWAcOswVor 8mtu5SAIx45APfhtm+LpALmFZP+PqKOxIDvuvdAFqjinL8mL/drX0GmGXEiaojwDW4mW TCjNqugNLUcTLU4MY6NxdpDIKMonhwG7yq4QGCmn4rb4PxKQLusOzbZzfLH2MEtnNzn7 HVQA== X-Gm-Message-State: AO0yUKU8EV5HV9GnnGFyjlMWvipRVWXWD7mNSWptTvnJCKRBezZZHFWl UjCcWO/7petZuI5aKkkbCq1eAq3472McXJt4IWad+/GMaZM= X-Received: by 2002:a17:90a:d596:b0:23d:2000:ccd6 with SMTP id v22-20020a17090ad59600b0023d2000ccd6mr3718347pju.2.1679227476520; Sun, 19 Mar 2023 05:04:36 -0700 (PDT) MIME-Version: 1.0 Date: Sun, 19 Mar 2023 12:04:25 +0000 Message-ID: Subject: [Patch, fortran] PR87127 - External function not recognised from within an associate block To: "fortran@gcc.gnu.org" , gcc-patches X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, 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-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Paul Richard Thomas via Gcc-patches From: Paul Richard Thomas Reply-To: Paul Richard Thomas 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?1760797698468524361?= X-GMAIL-MSGID: =?utf-8?q?1760797698468524361?= Hi All, I committed this to 8-branch on 2019-04-24 but not to 9-branch. I have no record of why I did this. The patch now requires an additional line, && sym->ns->proc_name->attr.proc != PROC_MODULE to prevent the error message in pr88376.f90 from changing to the less helpful Error: Specification function ā€˜nā€™ at (1) must be PURE I propose to commit to mainline and backport to 12-branch unless there are objections in the next 24 hours. Cheers Paul Fortran: Recognise external function from within an associate block that has not been declared as external [PR87127] 2023-03-19 Paul Thomas gcc/fortran PR fortran/87127 * resolve.cc (check_host_association): If an external function is typed but not declared explicitly to be external, change the old symbol from a variable to an external function. gcc/testsuite/ PR fortran/87127 * gfortran.dg/external_procedures_4.f90: New test. diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index ba603b4c407..a947f908ece 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -6079,11 +6079,14 @@ resolve_procedure: /* Checks to see that the correct symbol has been host associated. - The only situation where this arises is that in which a twice - contained function is parsed after the host association is made. - Therefore, on detecting this, change the symbol in the expression - and convert the array reference into an actual arglist if the old - symbol is a variable. */ + The only situations where this arises are: + (i) That in which a twice contained function is parsed after + the host association is made. On detecting this, change + the symbol in the expression and convert the array reference + into an actual arglist if the old symbol is a variable; or + (ii) That in which an external function is typed but not declared + explcitly to be external. Here, the old symbol is changed + from a variable to an external function. */ static bool check_host_association (gfc_expr *e) { @@ -6185,6 +6188,27 @@ check_host_association (gfc_expr *e) gfc_resolve_expr (e); sym->refs++; } + /* This case corresponds to a call, from a block or a contained + procedure, to an external function, which has not been declared + as being external in the main program but has been typed. */ + else if (sym && old_sym != sym + && !e->ref + && sym->ts.type == BT_UNKNOWN + && old_sym->ts.type != BT_UNKNOWN + && sym->attr.flavor == FL_PROCEDURE + && old_sym->attr.flavor == FL_VARIABLE + && sym->ns->parent == old_sym->ns + && sym->ns->proc_name + && sym->ns->proc_name->attr.proc != PROC_MODULE + && (sym->ns->proc_name->attr.flavor == FL_LABEL + || sym->ns->proc_name->attr.flavor == FL_PROCEDURE)) + { + old_sym->attr.flavor = FL_PROCEDURE; + old_sym->attr.external = 1; + old_sym->attr.function = 1; + old_sym->result = old_sym; + gfc_resolve_expr (e); + } } /* This might have changed! */ return e->expr_type == EXPR_FUNCTION;