From patchwork Wed Nov 9 20:50:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 17814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp554696wru; Wed, 9 Nov 2022 12:51:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM4bD1wrcvMgUEHz7lbB7bGerkqXbeK2N3UlIrtTw1R3lpgg+ihVbCQFQizPkSfzzOlQMEtq X-Received: by 2002:a17:907:1c88:b0:7ad:8f76:699e with SMTP id nb8-20020a1709071c8800b007ad8f76699emr57096376ejc.114.1668027070372; Wed, 09 Nov 2022 12:51:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668027070; cv=none; d=google.com; s=arc-20160816; b=t+ajoOkmjFadpkd7EhHVN1xAW00UJ0a31NfFTW847OEmag+kvXSnIf/26D8ax1eBo2 wd7FtGaJd+rlueVWk0rUObVWbZhLaO0GlcxhtN0RhHKNM484YnOL0sYyJaHA7siQgD0L VbJs6jgbwsELP/Yni7NcdxmccKkHcspuIepBMXNlGzxqCYZwWccnlZS8cy4pQUQQaUeD vp3KmiuxeyDW54y+JuV/zCQab1v9tt0DoLY70zShflnOki1dOHSY/ror8iesqdRqTd2+ rQU4zPXmPOl1PrWSOQW+y+Xp8+r4QXbabD2+uKBYIohRehIm96tglG4Gjk4vqv94KQwt bf2g== 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=3uKDyiLS6rrHsPmTJs6NnYkjORLjjng7PrEKFpjcNLc=; b=e5vlaykaK/eOix9JMbQ1AQZJ3BRfQ/19/X+FOBg2rnlBga07Wg1PLa3PcwElTmKDY3 Q+SIebI7bofDuEqTV+Ls10qZlZWDThELM9ERijxuoCOqCv27HX8eH6p4KWpOFzYGgycy 5o00or/JQv71EN4v2+xDZe9fYjgGZJrUIsWuouGakq5pKqtnz8ekXa/EvPYX0JAkTMB2 +Nx8b6/WuLiywQnDdAI+zuSZf8wY6Axp/9yyta8seXKJDyvififerVvW8fCB0vbJ07Ap 9Nz8qcy/wrxXbBYZPc5/9ueQjQRDLYWi7iFOhvpS4SdPcNVKyN+8VGOClotrbNJYAgxl id3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XxKeZ2+l; 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 hc10-20020a170907168a00b007ae685f22dfsi13848264ejc.792.2022.11.09.12.51.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 12:51:10 -0800 (PST) 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=XxKeZ2+l; 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 2DA593858C29 for ; Wed, 9 Nov 2022 20:51:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DA593858C29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668027069; bh=3uKDyiLS6rrHsPmTJs6NnYkjORLjjng7PrEKFpjcNLc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=XxKeZ2+lp/QX3lkxl67GtrExjerA3cvVTKlCn7FHDI6w/2MQXQokVuAridr5dzuQF qaioByfZSdstsbYcKLa40a1wLSfn9gQqx1TrP03FpM7B74oAsZ6JfqRqRJDGVD6QRk k1uUlCokDNo9rNVT8uRpJAe03L6eTVenwOsmNBms= 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.17.20]) by sourceware.org (Postfix) with ESMTPS id ADC3B3858D1E; Wed, 9 Nov 2022 20:50:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ADC3B3858D1E X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.86.171] ([93.207.86.171]) by web-mail.gmx.net (3c-app-gmx-bap34.server.lan [172.19.172.104]) (via HTTP); Wed, 9 Nov 2022 21:50:22 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: Proxy ping [PATCH] Fortran: diagnostics for actual arguments to pointer dummy arguments [PR94104] Date: Wed, 9 Nov 2022 21:50:22 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:mzMg4A1PbWq8YgB1bwmundJzQclSvvS05AUSM+YDYGJgLMeWywpHnr23CebxdWJjIZ9DY OfPzcupVqIqaHSurv68bGaPNrzM4qh4TRswH4aubdKCg/o31xehzn74AwXrjzyLbI+sTs6V7CsFI +dWM7ILgnjOM0X+6ufm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0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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?1749053153404152477?= X-GMAIL-MSGID: =?utf-8?q?1749053153404152477?= Dear all, Jose posted a patch here that was never reviewed: https://gcc.gnu.org/pipermail/fortran/2021-June/056162.html I think the diagnostics improvement is helpful, as it adjusts to the changes from F2003 to F2008. The patch suffered a little from bitrot, but was otherwise straightforward to apply. I slightly edited the commit message, as I found the original one difficult to parse. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 46957184b74af8d5a3b41704f5ef48a12f37fe33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rui=20Faustino=20de=20Sousa?= Date: Wed, 9 Nov 2022 21:30:25 +0100 Subject: [PATCH] Fortran: diagnostics for actual arguments to pointer dummy arguments [PR94104] Error message improvement. In Fortran 2008 actual procedure arguments associated with a pointer, intent(in) attribute, dummy argument can also have the target attribute, not just pointer. gcc/fortran/ChangeLog: PR fortran/94104 * interface.cc (gfc_compare_actual_formal): Improve error message dependent on Fortran standard level. gcc/testsuite/ChangeLog: PR fortran/94104 * gfortran.dg/parens_2.f90: Adjust to improved error message. * gfortran.dg/PR94104a.f90: New test. * gfortran.dg/PR94104b.f90: New test. --- gcc/fortran/interface.cc | 48 +++++++++++++++++--------- gcc/testsuite/gfortran.dg/PR94104a.f90 | 29 ++++++++++++++++ gcc/testsuite/gfortran.dg/PR94104b.f90 | 29 ++++++++++++++++ gcc/testsuite/gfortran.dg/parens_2.f90 | 2 +- 4 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/PR94104a.f90 create mode 100644 gcc/testsuite/gfortran.dg/PR94104b.f90 diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index d3e199535b3..49dbd1d886c 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -3477,25 +3477,39 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal, goto match; } - if (a->expr->expr_type != EXPR_NULL - && compare_pointer (f->sym, a->expr) == 0) + if (a->expr->expr_type != EXPR_NULL) { - if (where) - gfc_error ("Actual argument for %qs must be a pointer at %L", - f->sym->name, &a->expr->where); - ok = false; - goto match; - } + int cmp = compare_pointer (f->sym, a->expr); + bool pre2008 = ((gfc_option.allow_std & GFC_STD_F2008) == 0); - if (a->expr->expr_type != EXPR_NULL - && (gfc_option.allow_std & GFC_STD_F2008) == 0 - && compare_pointer (f->sym, a->expr) == 2) - { - if (where) - gfc_error ("Fortran 2008: Non-pointer actual argument at %L to " - "pointer dummy %qs", &a->expr->where,f->sym->name); - ok = false; - goto match; + if (pre2008 && cmp == 0) + { + if (where) + gfc_error ("Actual argument for %qs at %L must be a pointer", + f->sym->name, &a->expr->where); + ok = false; + goto match; + } + + if (pre2008 && cmp == 2) + { + if (where) + gfc_error ("Fortran 2008: Non-pointer actual argument at %L to " + "pointer dummy %qs", &a->expr->where, f->sym->name); + ok = false; + goto match; + } + + if (!pre2008 && cmp == 0) + { + if (where) + gfc_error ("Actual argument for %qs at %L must be a pointer " + "or a valid target for the dummy pointer in a " + "pointer assignment statement", + f->sym->name, &a->expr->where); + ok = false; + goto match; + } } diff --git a/gcc/testsuite/gfortran.dg/PR94104a.f90 b/gcc/testsuite/gfortran.dg/PR94104a.f90 new file mode 100644 index 00000000000..a1e578ac9ba --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR94104a.f90 @@ -0,0 +1,29 @@ +! { dg-do compile } +! { dg-options "-std=f2003" } +! +! PR fortran/94104 +! + +program diag_p + implicit none + + integer, parameter :: n = 7 + + integer :: a(n) + integer, target :: b(n) + + a = 1 + print *, sumf(a) ! { dg-error "Actual argument for 'a' at .1. must be a pointer" } + print *, sumf(b) ! { dg-error "Fortran 2008: Non-pointer actual argument at .1. to pointer dummy 'a'" } + +contains + + function sumf(a) result(s) + integer, pointer, intent(in) :: a(:) + + integer :: s + + s = sum(a) + end function sumf + +end program diag_p diff --git a/gcc/testsuite/gfortran.dg/PR94104b.f90 b/gcc/testsuite/gfortran.dg/PR94104b.f90 new file mode 100644 index 00000000000..ee7d640b926 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR94104b.f90 @@ -0,0 +1,29 @@ +! { dg-do compile } +! { dg-options "-std=f2008" } +! +! PR fortran/94104 +! + +program diag_p + implicit none + + integer, parameter :: n = 7 + + integer :: a(n) + integer, target :: b(n) + + a = 1 + print *, sumf(a) ! { dg-error "Actual argument for 'a' at .1. must be a pointer or a valid target" } + print *, sumf(b) + +contains + + function sumf(a) result(s) + integer, pointer, intent(in) :: a(:) + + integer :: s + + s = sum(a) + end function sumf + +end program diag_p diff --git a/gcc/testsuite/gfortran.dg/parens_2.f90 b/gcc/testsuite/gfortran.dg/parens_2.f90 index bc2acd8e71d..dc5965de014 100644 --- a/gcc/testsuite/gfortran.dg/parens_2.f90 +++ b/gcc/testsuite/gfortran.dg/parens_2.f90 @@ -2,7 +2,7 @@ ! { dg-do compile } ! Originally contributed by Joost VandeVondele INTEGER, POINTER :: I -CALL S1((I)) ! { dg-error "Actual argument for .i. must be a pointer" } +CALL S1((I)) ! { dg-error "Actual argument for .i. at .1. must be a pointer or a valid target" } CONTAINS SUBROUTINE S1(I) INTEGER, POINTER ::I -- 2.35.3