From patchwork Thu Apr 20 20:01:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 86020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp583258vqo; Thu, 20 Apr 2023 13:03:04 -0700 (PDT) X-Google-Smtp-Source: AKy350Ym+GoL4epdF11KLxAY4FkbcZTxwZ0rz6Jt4T4yT3Z65ppqjtIKJ4/D70BQeDxooQUDXDOo X-Received: by 2002:aa7:cd6e:0:b0:4fd:2aac:d480 with SMTP id ca14-20020aa7cd6e000000b004fd2aacd480mr3397321edb.21.1682020984407; Thu, 20 Apr 2023 13:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682020984; cv=none; d=google.com; s=arc-20160816; b=pK/QyxGXHnaUcFuUNIeNXgnLPIbN9ubEjl1NZUxDRDGoOFQ7BmnQNsQrRF4sMZ7R9D 3W9ZDRadKow24T/0P+d1BsDK7n/9ZGqXezvGLSntt1NZk5bJ6tRvIQXnA1qOFsDjtFX3 0scQdbcysAS94iVc0D7AQX9HcgVSOqtlamjbIUx2qqLEqgYoxk/zihcMOM0qY7KXibNq EMn9iFq4urkQGBqVBDLN5R8xRbvl//6RiFj3VLQhxL3a6ojmtmQhcFlo5AEzY47mNAvY tuwf34A8SdqOPhVSUxNL4Bm17o1lpTjCZH7w9LdUpKyaclKKJVK2i/HswqzrsuxvtJi7 np3g== 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:cc:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=MUEB8u3vzVg2Sy/UsTxmQIOpmRm9sBtK4P97DY6BUO0=; b=IC0MdREjE3rLw8Ey4ZvcBuGSc9V3Rtuj20s4lcVK/K/JhZR7JN6rd1dvNdBx4qfb2w ZOm4uRRdfjKs3RIR1bkyTZTlHS85cVbYoAPlbLid6z70afXYX2IBxhVInt65eJ0u1rpH KK2HA74+Xhi95vJJe8uBRtABV/sRvKuTKFCp9Z5ogIH7JPk+7Xyhe7lm0Hw6VkNXXWoH IJ2XbvSeCz/RFxnqULzY4RlLInIA/NKKDtpOe2B/AkinCtOkvsvL9dv83/tA0QgVbQ7y OPmKMaslQmka8qgyRgq/s3lERZP78hucki1h9Hr/u8rGs505q9ERezxFs97g0tbtTTKR ON9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZW4w79x4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id b3-20020aa7dc03000000b00506996f15e7si2213113edu.98.2023.04.20.13.03.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 13:03:04 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZW4w79x4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 025DC385B508 for ; Thu, 20 Apr 2023 20:02:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 025DC385B508 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682020968; bh=MUEB8u3vzVg2Sy/UsTxmQIOpmRm9sBtK4P97DY6BUO0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ZW4w79x4nVUYV3aRybThzJZyviL5XXlrr0+smPAh07LJ3hFHV8wREVF/G4SJm3dSr i/7Yh5MrO+i6yGy55s78Rfo66xtJtYmD0CtZ+qIdvc/QJ7BPQMbty24krMIMN4gABD I92o9u+gERrHdvkK3tLuayuwvE7UCKYf/PuAcer4= 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.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 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: To: fortran , gcc-patches Cc: kargl@gcc.gnu.org Subject: [PATCH] Fortran: function results never have the ALLOCATABLE attribute [PR109500] Date: Thu, 20 Apr 2023 22:01:59 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:cxh/Zf9stkWtf/tJCelG75pgl0Hrm1TQPKDk7UmO7f7keFmZE0B5E6Kc98JOPuqei1u1S tZN8wXcSbca6dplxwJDwkD9qP35FcUo5ICmB23EcTchHNUSbR5+7Lz0pcrhUxGUBkz5U3IoJXNHS Yefk8xLu6Go0TQ/VOR+BXmo2geK++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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 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?1763726835780874610?= X-GMAIL-MSGID: =?utf-8?q?1763726835780874610?= 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 From 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 --- 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 --- 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 == 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 = false; + goto match; + } + /* Check intent = OUT/INOUT for definable actual argument. */ if (!in_statement_function && (f->sym->attr.intent == INTENT_OUT diff --git a/gcc/testsuite/gfortran.dg/allocatable_function_11.f90 b/gcc/testsuite/gfortran.dg/allocatable_function_11.f90 new file mode 100644 index 00000000000..1a2831e186f --- /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 => f + p = 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=42) + end function + + logical function is_allocated(p) + integer, allocatable :: p + is_allocated = allocated(p) + end function +end program -- 2.35.3