Message ID | CAGkQGiJJYwM1w_ECV-GgpoauKa8LT+08u3c4XAEpBGosZSxnkA@mail.gmail.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 8123D385771E for <patchwork@sourceware.org>; Wed, 12 Apr 2023 15:25:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8123D385771E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681313147; bh=vhz77+LKjjA5BGv7AgYn4eV0yNtduq6A5ML7p7y13iE=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=XBmoGTh9D3aJ4idjz1OsPbK+EdYmq3DflJmSqyZsMEp/Ann/oUx0fsCZcFj53tpA2 HFzcawvHQAr83A0d3gKIMw1tzLd2/M2bTNdKXh7nDHjFz4b/Xwj0VXQJzwLHw92r5r G/pbNKZfYemVBQrqHMmTL/VIdxzQXEpbXIb3jiYA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 3B7593858D28; Wed, 12 Apr 2023 15:25:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B7593858D28 Received: by mail-pj1-x102d.google.com with SMTP id y11-20020a17090a600b00b0024693e96b58so10860626pji.1; Wed, 12 Apr 2023 08:25:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681313117; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7OWFHra944i2jqzOnulInLxM86TEvxGYi3XoW4dAXTQ=; b=V7d1umaSvnjx3NVDicFPeNOIuyHIYS9oukipqK7nE0lFISmckk3o5JZ6M2A9W0z9c9 d+nTtOpKO6OdKt++NjhHkmXCS20AQE6XlrVGmTxSpAXFpJnuThZHy58ZbuBY0TLE5Val HnKEd5HBr7jzOsPnnH6g4NYT7DZmfDx4Q9KjVssuKDJ0M4kPA13hHS++u2cZ/dR2d7Fi mtvrQczIF+SnmB5Nmsq/LXQ55q7DIPzcSKgFWA1GcMfCl+8kBMfab2HuqbwqFA01Ko2R 8hTea4WOhRBAu9G8LLHMXlnmX4RVAO9ydi3PjVUJ/fa9zSs4apTd9jiIptwu91K0K/MS NL0A== X-Gm-Message-State: AAQBX9e6QDHUg89Oyuk5mbQosxcqjQkMHNq553ZFkVlL1J4+Sm591DR5 WDxA0LBE7g46m12D58hp0ktoF0grVlFwm82HhX46oZrVOV8= X-Google-Smtp-Source: AKy350a4S191hSdiYJemUwJctHjJ54StTtW5grFleAkAGY51Nhly1g/+Ac9snBJOXzqOoufb4EFioa1VtCGEnuc9BUA= X-Received: by 2002:a17:903:2282:b0:1a2:1fd0:226c with SMTP id b2-20020a170903228200b001a21fd0226cmr5159958plh.8.1681313117361; Wed, 12 Apr 2023 08:25:17 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 12 Apr 2023 16:25:06 +0100 Message-ID: <CAGkQGiJJYwM1w_ECV-GgpoauKa8LT+08u3c4XAEpBGosZSxnkA@mail.gmail.com> Subject: [Patch, fortran] PR109451 - ICE in gfc_conv_expr_descriptor with ASSOCIATE and substrings To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org> Content-Type: multipart/mixed; boundary="0000000000001e5eb305f92537f4" X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, 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-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Paul Richard Thomas via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Paul Richard Thomas <paul.richard.thomas@gmail.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[fortran] PR109451 - ICE in gfc_conv_expr_descriptor with ASSOCIATE and substrings
|
|
Commit Message
Paul Richard Thomas
April 12, 2023, 3:25 p.m. UTC
Hi All, I think that the changelog says it all. OK for mainline? Paul Fortran: Fix some deferred character problems in associate [PR109451] 2023-04-07 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/109451 * trans-array.cc (gfc_conv_expr_descriptor): Guard expression character length backend decl before using it. Suppress the assignment if lhs equals rhs. * trans-io.cc (gfc_trans_transfer): Scalarize transfer of associate variables pointing to a variable. Add comment. gcc/testsuite/ PR fortran/109451 * gfortran.dg/associate_61.f90 : New test
Comments
Hi Paul, On 4/12/23 17:25, Paul Richard Thomas via Gcc-patches wrote: > Hi All, > > I think that the changelog says it all. OK for mainline? this looks almost fine, but still fails if one directly uses the dummy argument as the ASSOCIATE target, as in: program p implicit none character(4) :: c(2) = ["abcd","efgh"] call dcs0 (c) ! call dcs0 (["abcd","efgh"]) contains subroutine dcs0(a) character(len=*), intent(in) :: a(:) print *, size(a),len(a) associate (q => a(:)) print *, size(q),len(q) end associate associate (q => a(:)(:)) print *, size(q),len(q) end associate return end subroutine dcs0 end This prints e.g. 2 4 2 0 2 0 (sometimes I also get junk values for the character length). Can you please have another look? Thanks, Harald > Paul > > Fortran: Fix some deferred character problems in associate [PR109451] > > 2023-04-07 Paul Thomas <pault@gcc.gnu.org> > > gcc/fortran > PR fortran/109451 > * trans-array.cc (gfc_conv_expr_descriptor): Guard expression > character length backend decl before using it. Suppress the > assignment if lhs equals rhs. > * trans-io.cc (gfc_trans_transfer): Scalarize transfer of > associate variables pointing to a variable. Add comment. > > > gcc/testsuite/ > PR fortran/109451 > * gfortran.dg/associate_61.f90 : New test
Hi Harald, That's interesting - the string length '.q' is not set for either of the associate blocks. I'm onto it. Thanks Paul On Wed, 12 Apr 2023 at 20:26, Harald Anlauf <anlauf@gmx.de> wrote: > Hi Paul, > > On 4/12/23 17:25, Paul Richard Thomas via Gcc-patches wrote: > > Hi All, > > > > I think that the changelog says it all. OK for mainline? > > this looks almost fine, but still fails if one directly uses the > dummy argument as the ASSOCIATE target, as in: > > program p > implicit none > character(4) :: c(2) = ["abcd","efgh"] > call dcs0 (c) > ! call dcs0 (["abcd","efgh"]) > contains > subroutine dcs0(a) > character(len=*), intent(in) :: a(:) > print *, size(a),len(a) > associate (q => a(:)) > print *, size(q),len(q) > end associate > associate (q => a(:)(:)) > print *, size(q),len(q) > end associate > return > end subroutine dcs0 > end > > This prints e.g. > > 2 4 > 2 0 > 2 0 > > (sometimes I also get junk values for the character length). > > Can you please have another look? > > Thanks, > Harald > > > > Paul > > > > Fortran: Fix some deferred character problems in associate [PR109451] > > > > 2023-04-07 Paul Thomas <pault@gcc.gnu.org> > > > > gcc/fortran > > PR fortran/109451 > > * trans-array.cc (gfc_conv_expr_descriptor): Guard expression > > character length backend decl before using it. Suppress the > > assignment if lhs equals rhs. > > * trans-io.cc (gfc_trans_transfer): Scalarize transfer of > > associate variables pointing to a variable. Add comment. > > > > > > gcc/testsuite/ > > PR fortran/109451 > > * gfortran.dg/associate_61.f90 : New test > >
Hi Harald, The fix was trivial. An updated patch and testcase are attached. Thanks Paul Fortran: Fix some deferred character problems in associate [PR109451] 2023-04-14 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/109451 * trans-array.cc (gfc_conv_expr_descriptor): Guard expression character length backend decl before using it. Suppress the assignment if lhs equals rhs. * trans-io.cc (gfc_trans_transfer): Scalarize transfer of associate variables pointing to a variable. Add comment. * trans-stmt.cc (trans_associate_var): Remove requirement that the character length be deferred before assigning the value returned by gfc_conv_expr_descriptor. Also, guard the backend decl before testing with VAR_P. gcc/testsuite/ PR fortran/109451 * gfortran.dg/associate_61.f90 : New test On Thu, 13 Apr 2023 at 07:18, Paul Richard Thomas < paul.richard.thomas@gmail.com> wrote: > Hi Harald, > > That's interesting - the string length '.q' is not set for either of the > associate blocks. I'm onto it. > > Thanks > > Paul > > > On Wed, 12 Apr 2023 at 20:26, Harald Anlauf <anlauf@gmx.de> wrote: > >> Hi Paul, >> >> On 4/12/23 17:25, Paul Richard Thomas via Gcc-patches wrote: >> > Hi All, >> > >> > I think that the changelog says it all. OK for mainline? >> >> this looks almost fine, but still fails if one directly uses the >> dummy argument as the ASSOCIATE target, as in: >> >> program p >> implicit none >> character(4) :: c(2) = ["abcd","efgh"] >> call dcs0 (c) >> ! call dcs0 (["abcd","efgh"]) >> contains >> subroutine dcs0(a) >> character(len=*), intent(in) :: a(:) >> print *, size(a),len(a) >> associate (q => a(:)) >> print *, size(q),len(q) >> end associate >> associate (q => a(:)(:)) >> print *, size(q),len(q) >> end associate >> return >> end subroutine dcs0 >> end >> >> This prints e.g. >> >> 2 4 >> 2 0 >> 2 0 >> >> (sometimes I also get junk values for the character length). >> >> Can you please have another look? >> >> Thanks, >> Harald >> >> >> > Paul >> > >> > Fortran: Fix some deferred character problems in associate [PR109451] >> > >> > 2023-04-07 Paul Thomas <pault@gcc.gnu.org> >> > >> > gcc/fortran >> > PR fortran/109451 >> > * trans-array.cc (gfc_conv_expr_descriptor): Guard expression >> > character length backend decl before using it. Suppress the >> > assignment if lhs equals rhs. >> > * trans-io.cc (gfc_trans_transfer): Scalarize transfer of >> > associate variables pointing to a variable. Add comment. >> > >> > >> > gcc/testsuite/ >> > PR fortran/109451 >> > * gfortran.dg/associate_61.f90 : New test >> >> > > -- > "If you can't explain it simply, you don't understand it well enough" - > Albert Einstein >
Hi Paul, On 4/14/23 10:18, Paul Richard Thomas via Gcc-patches wrote: > Hi Harald, > > The fix was trivial. An updated patch and testcase are attached. great, this works, and I couldn't break it again this time ... Looks good! Thanks, Harald > Thanks > > Paul > > Fortran: Fix some deferred character problems in associate [PR109451] > > 2023-04-14 Paul Thomas <pault@gcc.gnu.org> > > gcc/fortran > PR fortran/109451 > * trans-array.cc (gfc_conv_expr_descriptor): Guard expression > character length backend decl before using it. Suppress the > assignment if lhs equals rhs. > * trans-io.cc (gfc_trans_transfer): Scalarize transfer of > associate variables pointing to a variable. Add comment. > * trans-stmt.cc (trans_associate_var): Remove requirement that > the character length be deferred before assigning the value > returned by gfc_conv_expr_descriptor. Also, guard the backend > decl before testing with VAR_P. > > gcc/testsuite/ > PR fortran/109451 > * gfortran.dg/associate_61.f90 : New test > > > On Thu, 13 Apr 2023 at 07:18, Paul Richard Thomas < > paul.richard.thomas@gmail.com> wrote: > >> Hi Harald, >> >> That's interesting - the string length '.q' is not set for either of the >> associate blocks. I'm onto it. >> >> Thanks >> >> Paul >> >> >> On Wed, 12 Apr 2023 at 20:26, Harald Anlauf <anlauf@gmx.de> wrote: >> >>> Hi Paul, >>> >>> On 4/12/23 17:25, Paul Richard Thomas via Gcc-patches wrote: >>>> Hi All, >>>> >>>> I think that the changelog says it all. OK for mainline? >>> >>> this looks almost fine, but still fails if one directly uses the >>> dummy argument as the ASSOCIATE target, as in: >>> >>> program p >>> implicit none >>> character(4) :: c(2) = ["abcd","efgh"] >>> call dcs0 (c) >>> ! call dcs0 (["abcd","efgh"]) >>> contains >>> subroutine dcs0(a) >>> character(len=*), intent(in) :: a(:) >>> print *, size(a),len(a) >>> associate (q => a(:)) >>> print *, size(q),len(q) >>> end associate >>> associate (q => a(:)(:)) >>> print *, size(q),len(q) >>> end associate >>> return >>> end subroutine dcs0 >>> end >>> >>> This prints e.g. >>> >>> 2 4 >>> 2 0 >>> 2 0 >>> >>> (sometimes I also get junk values for the character length). >>> >>> Can you please have another look? >>> >>> Thanks, >>> Harald >>> >>> >>>> Paul >>>> >>>> Fortran: Fix some deferred character problems in associate [PR109451] >>>> >>>> 2023-04-07 Paul Thomas <pault@gcc.gnu.org> >>>> >>>> gcc/fortran >>>> PR fortran/109451 >>>> * trans-array.cc (gfc_conv_expr_descriptor): Guard expression >>>> character length backend decl before using it. Suppress the >>>> assignment if lhs equals rhs. >>>> * trans-io.cc (gfc_trans_transfer): Scalarize transfer of >>>> associate variables pointing to a variable. Add comment. >>>> >>>> >>>> gcc/testsuite/ >>>> PR fortran/109451 >>>> * gfortran.dg/associate_61.f90 : New test >>> >>> >> >> -- >> "If you can't explain it simply, you don't understand it well enough" - >> Albert Einstein >> > >
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index e1725808033..3d90a02cdac 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -7934,8 +7934,12 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr) else tmp = se->string_length; - if (expr->ts.deferred && VAR_P (expr->ts.u.cl->backend_decl)) - gfc_add_modify (&se->pre, expr->ts.u.cl->backend_decl, tmp); + if (expr->ts.deferred && expr->ts.u.cl->backend_decl + && VAR_P (expr->ts.u.cl->backend_decl)) + { + if (expr->ts.u.cl->backend_decl != tmp) + gfc_add_modify (&se->pre, expr->ts.u.cl->backend_decl, tmp); + } else expr->ts.u.cl->backend_decl = tmp; } diff --git a/gcc/fortran/trans-io.cc b/gcc/fortran/trans-io.cc index 9b54d2f0d31..67658769b9e 100644 --- a/gcc/fortran/trans-io.cc +++ b/gcc/fortran/trans-io.cc @@ -2620,9 +2620,13 @@ gfc_trans_transfer (gfc_code * code) gcc_assert (ref && ref->type == REF_ARRAY); } + /* These expressions don't always have the dtype element length set + correctly, rendering them useless for array transfer. */ if (expr->ts.type != BT_CLASS && expr->expr_type == EXPR_VARIABLE && ((expr->symtree->n.sym->ts.type == BT_DERIVED && expr->ts.deferred) + || (expr->symtree->n.sym->assoc + && expr->symtree->n.sym->assoc->variable) || gfc_expr_attr (expr).pointer)) goto scalarize;