From patchwork Sun Dec 5 21:55:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 48516 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 3C5713858D39 for ; Sun, 5 Dec 2021 21:56:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C5713858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638741406; bh=Jba5OA2ju8RGni+0a5Gf0IllOSDJc8Khn8FEkvwmmR8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Sb62gJjKrNanW6AcgqK7LqmUml4AYNjGrnd7LJKWY5dZMMeTE/PyJky4vA11Plnvv He2rsBZS3cu/Iq3sqN9GjEvA2x7k2SyF7sE9mWiY14L51WpJBQ2NXrfBUUcCG2yMXp FnHXTc82+6yIrKSTg/vh1zZ8pSMzJYH6txHIgQN4= 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.21]) by sourceware.org (Postfix) with ESMTPS id 698A03858D39; Sun, 5 Dec 2021 21:55:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 698A03858D39 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.4.129] ([79.251.4.129]) by web-mail.gmx.net (3c-app-gmx-bs27.server.lan [172.19.170.79]) (via HTTP); Sun, 5 Dec 2021 22:55:04 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] PR fortran/103418 - random_number() does not accept pointer, intent(in) array argument Date: Sun, 5 Dec 2021 22:55:04 +0100 Importance: normal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/bsIOlH0oKozXpCmOK9yw+OK2f/5UA0TQKRHViWlrBFhPNdE2DNZlwbI/D1dz9SL 49mQDMVOXImdAp+XHpgYIhLJNPmJ0aayMsf+hIMMKO1tzB1xwWZlla5KRwIwUnEagcIXtpWd/ Ntv13A0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Dear all, the check of dummy arguments with pointer attribute and INTENT(IN) was broken in the case the argument was passed to an intrinsic. We therefore rejected valid code as e.g. given in the PR. The patch relaxes the excessive check. This requires the adjustment of one of the tests for MOVE_ALLOC. Regtested on x86_64-pc-linux-gnu. OK for mainline? As this is a rejects-valid and possibly annoying, I would like to backport as far seems reasonable. Thanks, Harald From fa07ada75a5ea25845d7e168204cd980263a7d8d Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sun, 5 Dec 2021 22:45:32 +0100 Subject: [PATCH] Fortran: fix check for pointer dummy arguments with INTENT(IN) gcc/fortran/ChangeLog: PR fortran/103418 * check.c (variable_check): Correct check of procedure dummy arguments with INTENT(IN) and POINTER attribute to get accepted when passed to intrinsics. gcc/testsuite/ChangeLog: PR fortran/103418 * gfortran.dg/move_alloc_8.f90: Adjust error messages. * gfortran.dg/pointer_intent_9.f90: New test. Co-authored-by: Steven G. Kargl --- gcc/fortran/check.c | 2 +- gcc/testsuite/gfortran.dg/move_alloc_8.f90 | 4 +-- .../gfortran.dg/pointer_intent_9.f90 | 28 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pointer_intent_9.f90 diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index ee3a51ee253..879b5b1996e 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -1031,7 +1031,7 @@ variable_check (gfc_expr *e, int n, bool allow_proc) break; } - if (!ref) + if (!ref && !(pointer && (e->rank == 0 || e->ref))) { gfc_error ("%qs argument of %qs intrinsic at %L cannot be " "INTENT(IN)", gfc_current_intrinsic_arg[n]->name, diff --git a/gcc/testsuite/gfortran.dg/move_alloc_8.f90 b/gcc/testsuite/gfortran.dg/move_alloc_8.f90 index f624b703cc9..d968ea0e5cd 100644 --- a/gcc/testsuite/gfortran.dg/move_alloc_8.f90 +++ b/gcc/testsuite/gfortran.dg/move_alloc_8.f90 @@ -60,7 +60,7 @@ subroutine test2 (x, px) integer, allocatable :: a type(t2), pointer :: ta - call move_alloc (px, ta) ! { dg-error "cannot be INTENT.IN." } + call move_alloc (px, ta) ! { dg-error "must be ALLOCATABLE" } call move_alloc (x%a, a) ! { dg-error "cannot be INTENT.IN." } call move_alloc (x%ptr%a, a) ! OK (3) call move_alloc (px%a, a) ! OK (4) @@ -84,7 +84,7 @@ subroutine test3 (x, px) integer, allocatable :: a class(t2), pointer :: ta - call move_alloc (px, ta) ! { dg-error "cannot be INTENT.IN." } + call move_alloc (px, ta) ! { dg-error "must be ALLOCATABLE" } call move_alloc (x%a, a) ! { dg-error "cannot be INTENT.IN." } call move_alloc (x%ptr%a, a) ! OK (6) call move_alloc (px%a, a) ! OK (7) diff --git a/gcc/testsuite/gfortran.dg/pointer_intent_9.f90 b/gcc/testsuite/gfortran.dg/pointer_intent_9.f90 new file mode 100644 index 00000000000..000f407d393 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pointer_intent_9.f90 @@ -0,0 +1,28 @@ +! { dg-do compile } +! PR fortran/103418 +! Validate checks for use of dummy arguments with pointer attribute + +module m + type t + real, pointer :: a, b(:) + end type t +contains + subroutine s1 (a, b, c, d) + real, pointer, intent(in) :: a, b(:) + type(t), intent(in) :: c + class(t), intent(in) :: d + real, pointer :: pa, pb(:) + call random_number (a) ! legal + call random_number (b) + call random_number (c% a) + call random_number (c% b) + call random_number (d% a) + call random_number (d% b) + call move_alloc (a, pa) ! { dg-error "must be ALLOCATABLE" } + call move_alloc (b, pb) ! { dg-error "must be ALLOCATABLE" } + allocate (a) ! { dg-error "pointer association context" } + allocate (b(10)) ! { dg-error "pointer association context" } + allocate (c% a) ! { dg-error "pointer association context" } + allocate (c% b(10)) ! { dg-error "pointer association context" } + end subroutine s1 +end module -- 2.26.2