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: 66583 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 230B63858032 for ; Sun, 19 Mar 2023 12:05:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 230B63858032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679227525; bh=xJ5OMQYZ9pPG6T6gNFOUQfxoCuNfyF9AGJwOdlDmcNY=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Jl2v3HKc5CB8OgDvJdPHHYlZmNGVSUQPNXRCb+m4ib+vNbM8gphDs31IRc76hZ6ZZ VRMhMRQzcDQ2Dhthjw0WOnz2nqqbwo4H5fCmOE8fncQweoV5cj+fRKPCgBoab7ockh FdWJfV/c9A9OCKQjkBQseEZ+7oYKprXmTl3GYJI8= 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-Google-Smtp-Source: AK7set/066SQktFuHVBCGqL/2PiL+65PmM4dWZOFynq7J54FjurJYrSzjrfbs23Bbt3z4MY2+02E+TjiArOFyl+M/AI= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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;