From patchwork Sun Oct 31 17:25:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 46872 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 BBC973857817 for ; Sun, 31 Oct 2021 17:26:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBC973857817 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635701160; bh=Myc+Byc/vG2bLDXC6zXQxp1pXcy6efecoytMJCIpuhU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=hNDhcDaLGIS9p8lGZn+3dT4QowS/juRKHzQbSexxhY6fGjavkexpxkps/Xb8QgKbq Mb5xzwQ+bH/P3f/V/kfRG9aagxaLhgBJuz3xyCTr4y1RlBuH0IbyUvAU5sDVFSg6UC zZ1MQAqB+ShcB1tZaBw5OlqhggF5/rGTyCFYG7nw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 5C78A3858436; Sun, 31 Oct 2021 17:25:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5C78A3858436 Received: by mail-wm1-x331.google.com with SMTP id c71-20020a1c9a4a000000b0032cdcc8cbafso7504702wme.3; Sun, 31 Oct 2021 10:25:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Myc+Byc/vG2bLDXC6zXQxp1pXcy6efecoytMJCIpuhU=; b=Iq2ubE9wap26Nbmh1NXtLOcYWx5P8lLrer+S4JBruxLXvICvjl79Vn2WvGKAZ02nIO UieqIW6gfZnCtmXJlfM3zglh/5dbX0W/mZAeaDVK9hH/GRkKG+cxG1pRyZzFkHs8QXYY iA+5CnenyB4mG7zOTmkhQp1Cu2SREwfZZn8H/QGhMmxtupu0xmaTnYo1KnADYRnIAl8z 7b79wMHDHI/XdbhClNBuYHNDRxwiYPrvsjjCbHyOI/Wa0s4mA6UQw6jnAN/yJLbAeXk8 TDaPAE6D9t1kjF1MpApiRsKYX2B5tae+l+JZSADgskFNTYG8M/euKFhkDdHoTsO55oAj 3gdQ== X-Gm-Message-State: AOAM531BlyokOZWs7SZY4vY8D4tw30yPqWYjh4BSM6RWj5KcidGGZb9M eO+4kYNOe7fVi7pvF62voRc= X-Google-Smtp-Source: ABdhPJwZjR482espw+JP9kjlIUZbRgb/U9ZqrTUNuVYkMzmj7pwzM93oxDKGA6dcx+AN9Lvt8HanDw== X-Received: by 2002:a05:600c:2252:: with SMTP id a18mr17245747wmm.133.1635701128293; Sun, 31 Oct 2021 10:25:28 -0700 (PDT) Received: from nbbrfq.weghof (dynamic-2bq7di4u2lfl4qjka9-pd01.res.v6.highway.a1.net. [2001:871:227:33a8:f6a3:c58c:7641:e771]) by smtp.gmail.com with ESMTPSA id w5sm11468431wra.87.2021.10.31.10.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 10:25:27 -0700 (PDT) Received: from b by nbbrfq.weghof with local (Exim 4.95) (envelope-from ) id 1mhEaF-00G7L3-50; Sun, 31 Oct 2021 18:25:27 +0100 To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH] Fortran: Missing error with IMPLICIT none (external) [PR100972] Date: Sun, 31 Oct 2021 18:25:20 +0100 Message-Id: <20211031172520.3841446-1-rep.dot.nop@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer Cc: Bernhard Reutner-Fischer Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Bernhard Reutner-Fischer gcc/fortran/ChangeLog: PR fortran/100972 * decl.c (gfc_match_implicit_none): Fix typo in warning. * resolve.c (resolve_unknown_f): Reject external procedures without explicit EXTERNAL attribute whe IMPLICIT none (external) is in effect. gcc/testsuite/ChangeLog: PR fortran/100972 * gfortran.dg/implicit_14.f90: Adjust error. * gfortran.dg/external_implicit_none_3.f08: New test. --- As Gerhard Steinmetz noticed, gfc_match_implicit_none() had a notify_std that mentioned IMPORT instead of IMPLICIT. Fix that typo. IMPLICIT NONE (external) is supposed to require external procedures to be explicitly declared with EXTERNAL. We cannot do this when parsing in e.g. gfc_match_rvalue->gfc_match_varspec because the procedure might live way down in a CONTAINS like in bind-c-contiguous-3.f90. Hence diagnose missing EXTERNAL declaraions when resolving. Bootstrapped and regtested on x86_64-unknown-linux without regressions. Ok for trunk? --- gcc/fortran/decl.c | 2 +- gcc/fortran/resolve.c | 13 +++++++++++++ .../gfortran.dg/external_implicit_none_3.f08 | 17 +++++++++++++++++ gcc/testsuite/gfortran.dg/implicit_14.f90 | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/external_implicit_none_3.f08 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index e9e23fe1acb..ab88ab5e9c1 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -4715,7 +4715,7 @@ gfc_match_implicit_none (void) if (c == '(') { (void) gfc_next_ascii_char (); - if (!gfc_notify_std (GFC_STD_F2018, "IMPORT NONE with spec list at %C")) + if (!gfc_notify_std (GFC_STD_F2018, "IMPLICIT NONE with spec list at %C")) return MATCH_ERROR; gfc_gobble_whitespace (); diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 21126cba262..1f4abd08720 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -2974,6 +2974,19 @@ resolve_unknown_f (gfc_expr *expr) return false; } + /* IMPLICIT NONE (external) procedures require an explicit EXTERNAL attr. */ + /* Intrinsics were handled above, only non-intrinsics left here. */ + if (sym->attr.flavor == FL_PROCEDURE + && sym->attr.implicit_type + && sym->ns + && sym->ns->has_implicit_none_export) + { + gfc_error ("Missing explicit declaration with EXTERNAL attribute " + "for symbol %qs at %L", sym->name, &sym->declared_at); + sym->error = 1; + return false; + } + /* The reference is to an external name. */ sym->attr.proc = PROC_EXTERNAL; diff --git a/gcc/testsuite/gfortran.dg/external_implicit_none_3.f08 b/gcc/testsuite/gfortran.dg/external_implicit_none_3.f08 new file mode 100644 index 00000000000..329deedc413 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/external_implicit_none_3.f08 @@ -0,0 +1,17 @@ +! { dg-do compile } +! { dg-options "-std=f2018" } +! Tests fix for PR100972 - Fails to warn about missing EXTERNAL attribute +! Contributed by Gerhard Steinmetz + +program p + implicit none (external) + real, external :: f + real :: a + real :: b + integer :: i + character :: c + a = f() ! OK + b = g() ! { dg-error "Missing explicit declaration with EXTERNAL attribute" } + i = h() ! { dg-error "Missing explicit declaration with EXTERNAL attribute" } + c = j() ! { dg-error "Missing explicit declaration with EXTERNAL attribute" } +end diff --git a/gcc/testsuite/gfortran.dg/implicit_14.f90 b/gcc/testsuite/gfortran.dg/implicit_14.f90 index 8282c1f1f86..422d913fd4f 100644 --- a/gcc/testsuite/gfortran.dg/implicit_14.f90 +++ b/gcc/testsuite/gfortran.dg/implicit_14.f90 @@ -4,5 +4,5 @@ ! Support Fortran 2018's IMPLICIT NONE with spec list ! (currently implemented as vendor extension) -implicit none (type) ! { dg-error "Fortran 2018: IMPORT NONE with spec list at \\(1\\)" } +implicit none (type) ! { dg-error "Fortran 2018: IMPLICIT NONE with spec list at \\(1\\)" } end