From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by sourceware.org (Postfix) with ESMTPS id 341883858D37; Thu, 20 Apr 2023 20:02:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 341883858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1682020919; i=anlauf@gmx.de; bh=n/RulwBvZNSTc1pBBLy9YbF3mxJd0wgBZNCMpGfaT7s=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=fOx0vvozOEJrHeFDkMKpPzYLDQJeiOvzHHgXoNRlpDv1FlzDrSRbslmZ44j1gbWZi jWLf8IhK55MO8HuS/2gNIH3CoAasP47nVvJ+2+f2+XWgYk8H7pZbePGPWHM12BRCUk gfOz+hKnSdb4rUkvCac07eLFTNLf2wjNTSSCHySSO1l88sVeO42lsQJVf0D7aXePqW XfWZyRGx8w/6htLrM9JJxZA+9EMHme2UIrRxZYuBIeWxMrzPThHpSW/B+pfqu8bkKp HLqFzqehKE5JOJp7XCsZfVhXPWTB1mHQxCYWy9SCRtsAmX18pbjhAlBcmht6CqMQ/j 8E5K+4TEQmtKg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.14.164] ([79.251.14.164]) by web-mail.gmx.net (3c-app-gmx-bs34.server.lan [172.19.170.86]) (via HTTP); Thu, 20 Apr 2023 22:01:59 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Cc: kargl@gcc.gnu.org Subject: [PATCH] Fortran: function results never have the ALLOCATABLE attribute [PR109500] Content-Type: multipart/mixed; boundary=trekuen-51445888-790e-4bdf-8f09-04535aa52a89 Date: Thu, 20 Apr 2023 22:01:59 +0200 Importance: normal Sensitivity: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J20tuLuc4ytJvw1A7duIeAB10Qp/F1Bvavu1MghiszsL1FbUCyReh oU6i0dlnh0Ai30AMnAXR7ucBhuxe7qEmrH0lvKNW6i0GBvG7dr4Z/jHRSobzavviHtOkx2top wCPcdUnb5xslfmKvSfJRQFrA== X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --trekuen-51445888-790e-4bdf-8f09-04535aa52a89 Content-Type: text/plain; charset=UTF-8 Dear all, Fortran 2018 added a clarification that the *result* of a function whose result *variable* has the ALLOCATABLE attribute is a *value* that itself does not have the ALLOCATABLE attribute. For those interested: there was a thread on the J3 mailing list some time ago (for links see the PR). The patch which implements a related check was co-authored with Steve and regtested by him. Testcase verified against NAG. OK for mainline (gcc-14)? Thanks, Harald & Steve --trekuen-51445888-790e-4bdf-8f09-04535aa52a89 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr109500.diff Content-Transfer-Encoding: quoted-printable =46rom 2cebc8f9e7b399b7747c9ad0392831de91851b5b Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 20 Apr 2023 21:47:34 +0200 Subject: [PATCH] Fortran: function results never have the ALLOCATABLE attribute [PR109500] Fortran 2018 8.5.3 (ALLOCATABLE attribute) explains in Note 1 that the result of referencing a function whose result variable has the ALLOCATABLE attribute is a value that does not itself have the ALLOCATABLE attribute. gcc/fortran/ChangeLog: PR fortran/109500 * interface.cc (gfc_compare_actual_formal): Reject allocatable functions being used as actual argument for allocable dummy. gcc/testsuite/ChangeLog: PR fortran/109500 * gfortran.dg/allocatable_function_11.f90: New test. Co-authored-by: Steven G. Kargl =2D-- gcc/fortran/interface.cc | 12 +++++++ .../gfortran.dg/allocatable_function_11.f90 | 36 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/allocatable_function_11.f90 diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index e9843e9549c..968ee193c07 100644 =2D-- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -3638,6 +3638,18 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap,= gfc_formal_arglist *formal, goto match; } + if (a->expr->expr_type =3D=3D EXPR_FUNCTION + && a->expr->value.function.esym + && f->sym->attr.allocatable) + { + if (where) + gfc_error ("Actual argument for %qs at %L is a function result " + "and the dummy argument is ALLOCATABLE", + f->sym->name, &a->expr->where); + ok =3D false; + goto match; + } + /* Check intent =3D OUT/INOUT for definable actual argument. */ if (!in_statement_function && (f->sym->attr.intent =3D=3D INTENT_OUT diff --git a/gcc/testsuite/gfortran.dg/allocatable_function_11.f90 b/gcc/t= estsuite/gfortran.dg/allocatable_function_11.f90 new file mode 100644 index 00000000000..1a2831e186f =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocatable_function_11.f90 @@ -0,0 +1,36 @@ +! { dg-do compile } +! PR fortran/109500 - check F2018:8.5.3 Note 1 +! +! The result of referencing a function whose result variable has the +! ALLOCATABLE attribute is a value that does not itself have the +! ALLOCATABLE attribute. + +program main + implicit none + integer, allocatable :: p + procedure(f), pointer :: pp + pp =3D> f + p =3D f() + print *, allocated (p) + print *, is_allocated (p) + print *, is_allocated (f()) ! { dg-error "is a function result" } + print *, is_allocated (pp()) ! { dg-error "is a function result" } + call s (p) + call s (f()) ! { dg-error "is a function result" } + call s (pp()) ! { dg-error "is a function result" } + +contains + subroutine s(p) + integer, allocatable :: p + end subroutine s + + function f() + integer, allocatable :: f + allocate (f, source=3D42) + end function + + logical function is_allocated(p) + integer, allocatable :: p + is_allocated =3D allocated(p) + end function +end program =2D- 2.35.3 --trekuen-51445888-790e-4bdf-8f09-04535aa52a89--