Message ID | trinity-6d934a50-8304-4704-bce4-36a2afbc687e-1664911631690@3c-app-gmx-bs14 |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp276316wrs; Tue, 4 Oct 2022 12:27:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5E4Zd7ttIMvSIBuW8kvDBvCJiftMRDxcX2CSOpJJ1nPbxGfreCOEeKUJvxjHE+dXVWr7iI X-Received: by 2002:a17:907:3f26:b0:78d:1b32:bf85 with SMTP id hq38-20020a1709073f2600b0078d1b32bf85mr3281440ejc.628.1664911679288; Tue, 04 Oct 2022 12:27:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664911679; cv=none; d=google.com; s=arc-20160816; b=epWSeipFdZbZosUsZAHI5dZtudS8U3rT3TGm+sdryDz5CW87DNGDLXk2WD+F3wx7jv 8XDLhlyvcpiCiGmTfyXW1YYhxtP11/cDQpZVk4e7j1iRdU/Y7x3i0/L9mZT3QKAZLsTJ 39PQsHGyyq0hK3/cjohjzUQ2JX40NOjlzSM09yPG95FAPHPwIOIFZbU4ns49fUd+/19a ly4McpDWr0XIWFM3uhhV90gOlHW38NoYgSoUSuHb98lN3R+hsiLdAfXtQ+6XCEh328Iq qN8dbUOTpyVNheIsJjeEc1z8Sl6Qz+2fJnDhdDGnRbjIK+WxY/KNSGX6b+aOrWXDwCz2 5Z+g== 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:sensitivity :importance:date:subject:to:message-id:mime-version:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=sklRSGh9dF4wW+Uh0K2Rqn4wGgssA11ctpZr60/YucM=; b=QNpDC3wyt8en2bj+htJHlNacpSyZB0k+YX0MfE09Zg19cmAAXIecvjJby/cjc2lKzc hqUy/+w0RKTvDa3HEyagTwmzzWV/9dlrsJ4Q+yVgSEyggjpl4YSbtrt3B740i7YgwPMJ sNupQ8f5+6rdZCkFzR/pBfW2ZasucWq2Yuk499digjAEj4IH4IrUJ+DWsrsVaT2rlfT+ I79sCBQ9jUpNZy+rTqnnIyEx4a36lWjQTS5tVC8HZFeYFiZp3NbAYzhB/fa/yS1fwt3F nOnpRBHLtZip9u2Usw+tPt5SW6WFpF2XxXafs2x+IBsFqeDwirGgk4sLIx5t59cN/aSP O6ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ue829F6R; 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 g12-20020a1709065d0c00b0078aeb7747c0si6729873ejt.640.2022.10.04.12.27.59 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 12:27:59 -0700 (PDT) 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=ue829F6R; 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 17FDF3858424 for <ouuuleilei@gmail.com>; Tue, 4 Oct 2022 19:27:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17FDF3858424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664911678; bh=sklRSGh9dF4wW+Uh0K2Rqn4wGgssA11ctpZr60/YucM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ue829F6RgU596lSCnSlnQe87Bc8M8M8zxTVZGevwtEuh7aS+Qi0nqr43mbaqPT7Yq iEW7BhOGHSYxahzVIsMv1d85wqSXhR2zmSn3E/TjK7YFOve2A+xJ79lk0b8S3F0uSi JaYCrMt6jgAVGGe2kOD0vd0kk4y8SLX+2M66kIiQ= 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.19]) by sourceware.org (Postfix) with ESMTPS id 32E933858D39; Tue, 4 Oct 2022 19:27:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 32E933858D39 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.82.142] ([93.207.82.142]) by web-mail.gmx.net (3c-app-gmx-bs14.server.lan [172.19.170.66]) (via HTTP); Tue, 4 Oct 2022 21:27:11 +0200 MIME-Version: 1.0 Message-ID: <trinity-6d934a50-8304-4704-bce4-36a2afbc687e-1664911631690@3c-app-gmx-bs14> To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org> Subject: [PATCH] Fortran: reject procedures and procedure pointers as output item [PR107074] Content-Type: multipart/mixed; boundary=refeik-02721314-e37d-400c-9cbe-a2ec3e1180f3 Date: Tue, 4 Oct 2022 21:27:11 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 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oOEij4NJmlFozcF9PwDIJM6uQZ7S0hzFQCqUGYEc7h EepOo6tQocXM4rCJOtbZAU7QDs5L7jKx+Vugj2ftP0gK8iEBMBqZU4/V9KEWKiKzYVifHugwk sSRKx3M X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Harald Anlauf via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Harald Anlauf <anlauf@gmx.de> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745786428720094978?= X-GMAIL-MSGID: =?utf-8?q?1745786428720094978?= |
Series |
Fortran: reject procedures and procedure pointers as output item [PR107074]
|
|
Commit Message
Harald Anlauf
Oct. 4, 2022, 7:27 p.m. UTC
Dear all, when looking at output item lists we didn't catch procedures and procedure pointers and ran into a gfc_internal_error(). Such items are not allowed by the Fortran standard, e.g. for procedure pointers there is C1233 (R1217) An expression that is an output-item shall not have a value that is a procedure pointer. Attached patch generates an error instead. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald
Comments
Hello Le 04/10/2022 à 21:27, Harald Anlauf via Fortran a écrit : > Dear all, > > when looking at output item lists we didn't catch procedures > and procedure pointers and ran into a gfc_internal_error(). > Such items are not allowed by the Fortran standard, e.g. for > procedure pointers there is > > C1233 (R1217) An expression that is an output-item shall not > have a value that is a procedure pointer. > > Attached patch generates an error instead. > > Regtested on x86_64-pc-linux-gnu. OK for mainline? > Please move the check to resolve_transfer in resolve.cc. Strangely, the patch doesn't seem to fix the problem on the testcase here. There is an outer parenthese expression preventing the condition you added from triggering. Can you double check? If we take the standard to the letter, only output items are forbidden, so a check is missing for writing context. I don't know how it can work for input items though, so maybe not worth it. In any case, the error shouldn't mention output items in reading context. Here is a variant of the testcase with procedure pointer components, that fails differently but can probably be caught as well. program p implicit none type :: t procedure(f), pointer, nopass :: b end type t type(t) :: a interface real function f() end function f end interface print *, merge (a%b, a%b, .true.) end
Hi Mikael, > Gesendet: Mittwoch, 05. Oktober 2022 um 12:34 Uhr > Von: "Mikael Morin" <morin-mikael@orange.fr> > Please move the check to resolve_transfer in resolve.cc. I have done this, see attached updated patch. Regtests cleanly on x86_64-pc-linux-gnu. > Strangely, the patch doesn't seem to fix the problem on the testcase > here. There is an outer parenthese expression preventing the condition > you added from triggering. Can you double check? You are right: I had a one-liner in my worktree from PR105371 that fixes an issue with gfc_simplify_merge and that seems to help here. It is now included. > If we take the standard to the letter, only output items are forbidden, > so a check is missing for writing context. I don't know how it can work > for input items though, so maybe not worth it. In any case, the error > shouldn't mention output items in reading context. > > Here is a variant of the testcase with procedure pointer components, > that fails differently but can probably be caught as well. > > program p > implicit none > type :: t > procedure(f), pointer, nopass :: b > end type t > type(t) :: a > > interface > real function f() > end function f > end interface > > print *, merge (a%b, a%b, .true.) > end I hadn't thought about this, and found a solution that also fixes this one. Great example! This is now an additional test. OK for mainline? And thanks for your comments! Harald
Le 05/10/2022 à 22:40, Harald Anlauf a écrit : > Hi Mikael, > >> Gesendet: Mittwoch, 05. Oktober 2022 um 12:34 Uhr >> Von: "Mikael Morin" <morin-mikael@orange.fr> >> Please move the check to resolve_transfer in resolve.cc. > > I have done this, see attached updated patch. > > Regtests cleanly on x86_64-pc-linux-gnu. > >> Strangely, the patch doesn't seem to fix the problem on the testcase >> here. There is an outer parenthese expression preventing the condition >> you added from triggering. Can you double check? > > You are right: I had a one-liner in my worktree from PR105371 that > fixes an issue with gfc_simplify_merge and that seems to help here. > It is now included. > The rest looks good, but I'm not sure about your one-liner. I will try to come with a real test later, but in principle, if you have a call to FOO(MERGE(A,A,.TRUE.)) you can't simplify it to FOO(A) as writes to the argument in FOO should not overwrite the content of A. The dummy should be associated with a temporary value, not to A.
Le 06/10/2022 à 10:37, Mikael Morin a écrit : > Le 05/10/2022 à 22:40, Harald Anlauf a écrit : >> Hi Mikael, >> >>> Gesendet: Mittwoch, 05. Oktober 2022 um 12:34 Uhr >>> Von: "Mikael Morin" <morin-mikael@orange.fr> >>> Please move the check to resolve_transfer in resolve.cc. >> >> I have done this, see attached updated patch. >> >> Regtests cleanly on x86_64-pc-linux-gnu. >> >>> Strangely, the patch doesn't seem to fix the problem on the testcase >>> here. There is an outer parenthese expression preventing the condition >>> you added from triggering. Can you double check? >> >> You are right: I had a one-liner in my worktree from PR105371 that >> fixes an issue with gfc_simplify_merge and that seems to help here. >> It is now included. >> > The rest looks good, but I'm not sure about your one-liner. > I will try to come with a real test later, but in principle, if you have > a call to FOO(MERGE(A,A,.TRUE.)) you can't simplify it to FOO(A) as > writes to the argument in FOO should not overwrite the content of A. The > dummy should be associated with a temporary value, not to A. > Here is a test that your patch breaks. Admittedly it's rejected if A has the INTENT(INOUT) attribute, but without it, I think it's allowed. program p integer :: b b = 1 call foo(merge(b,b,.true.)) if (b /= 1) stop 1 contains subroutine foo(a) integer :: a if (a == 1) a = 42 end subroutine foo end program p
Hi Mikael, I definitely agree that we need a temporary for the result of MERGE(a,a,.true.), I just haven't found out how to do that. The reason for the bad one-liner was that in gfc_simplify_merge result = gfc_get_parentheses (result); actually does have issues, in that the subsequent gfc_simplify_expr (result, 1); seems to fail in interesting cases (as in PR105371). So that is something to look into... Cheers, Harald > Gesendet: Donnerstag, 06. Oktober 2022 um 22:32 Uhr > Von: "Mikael Morin" <morin-mikael@orange.fr> > An: "Harald Anlauf" <anlauf@gmx.de> > Cc: "gcc-patches" <gcc-patches@gcc.gnu.org>, "fortran" <fortran@gcc.gnu.org> > Betreff: Re: [PATCH, v2] Fortran: reject procedures and procedure pointers as IO element [PR107074] > > Le 06/10/2022 à 10:37, Mikael Morin a écrit : > > Le 05/10/2022 à 22:40, Harald Anlauf a écrit : > >> Hi Mikael, > >> > >>> Gesendet: Mittwoch, 05. Oktober 2022 um 12:34 Uhr > >>> Von: "Mikael Morin" <morin-mikael@orange.fr> > >>> Please move the check to resolve_transfer in resolve.cc. > >> > >> I have done this, see attached updated patch. > >> > >> Regtests cleanly on x86_64-pc-linux-gnu. > >> > >>> Strangely, the patch doesn't seem to fix the problem on the testcase > >>> here. There is an outer parenthese expression preventing the condition > >>> you added from triggering. Can you double check? > >> > >> You are right: I had a one-liner in my worktree from PR105371 that > >> fixes an issue with gfc_simplify_merge and that seems to help here. > >> It is now included. > >> > > The rest looks good, but I'm not sure about your one-liner. > > I will try to come with a real test later, but in principle, if you have > > a call to FOO(MERGE(A,A,.TRUE.)) you can't simplify it to FOO(A) as > > writes to the argument in FOO should not overwrite the content of A. The > > dummy should be associated with a temporary value, not to A. > > > Here is a test that your patch breaks. > Admittedly it's rejected if A has the INTENT(INOUT) attribute, but > without it, I think it's allowed. > > program p > integer :: b > b = 1 > call foo(merge(b,b,.true.)) > if (b /= 1) stop 1 > contains > subroutine foo(a) > integer :: a > if (a == 1) a = 42 > end subroutine foo > end program p > >
From 3b15fe83830c1e75339114e0241e9d2158393017 Mon Sep 17 00:00:00 2001 From: Harald Anlauf <anlauf@gmx.de> Date: Tue, 4 Oct 2022 21:19:21 +0200 Subject: [PATCH] Fortran: reject procedures and procedure pointers as output item [PR107074] gcc/fortran/ChangeLog: PR fortran/107074 * trans-io.cc (transfer_expr): A procedure or a procedure pointer cannot be output items. gcc/testsuite/ChangeLog: PR fortran/107074 * gfortran.dg/pr107074.f90: New test. --- gcc/fortran/trans-io.cc | 14 ++++++++++++++ gcc/testsuite/gfortran.dg/pr107074.f90 | 11 +++++++++++ 2 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr107074.f90 diff --git a/gcc/fortran/trans-io.cc b/gcc/fortran/trans-io.cc index 9f86815388c..c4e1537eed6 100644 --- a/gcc/fortran/trans-io.cc +++ b/gcc/fortran/trans-io.cc @@ -2430,6 +2430,20 @@ transfer_expr (gfc_se * se, gfc_typespec * ts, tree addr_expr, break; + case BT_PROCEDURE: + if (code->expr1 + && code->expr1->symtree + && code->expr1->symtree->n.sym) + { + if (code->expr1->symtree->n.sym->attr.proc_pointer) + gfc_error ("Procedure pointer at %C cannot be an output item"); + else + gfc_error ("Procedure at %C cannot be an output item"); + return; + } + /* If a PROCEDURE item gets through to here, fall through and ICE. */ + gcc_fallthrough (); + case_bt_struct: case BT_CLASS: if (gfc_bt_struct (ts->type) || ts->type == BT_CLASS) diff --git a/gcc/testsuite/gfortran.dg/pr107074.f90 b/gcc/testsuite/gfortran.dg/pr107074.f90 new file mode 100644 index 00000000000..a09088c2e9d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr107074.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/107074 - ICE: Bad IO basetype (8) +! Contributed by G.Steinmetz + +program p + implicit none + integer, external :: a + procedure(real), pointer :: b + print *, merge (a, a, .true.) ! { dg-error "Procedure" } + print *, merge (b, b, .true.) ! { dg-error "Procedure pointer" } +end -- 2.35.3