From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by sourceware.org (Postfix) with ESMTPS id 6E3A23858417; Thu, 22 Feb 2024 20:22:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E3A23858417 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6E3A23858417 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.22 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708633369; cv=none; b=NCsuNsk3p4/mv1U0em2V7soqRnrwsUCNJuMT74aivbeNENQPzT33TkN+1jA2S7W5ODkmiTJ5ZCKtjTMLhwhdZX3E+XvZRUyWJ3CqXHaDQyme+Kp0eUX+LrCjzXAhZ/7CUkB7M3mmXfhOsZz+60YS/4445T2XVVF3YUGTcKeyaQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708633369; c=relaxed/simple; bh=XgeEKSjvMJKbC9KVZ1s3FW+VRAR6dOc8OJwbkkcs0ek=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=vo0MPu5+lG8j7vsIbV+kvbWzQbiaYg+69FYWrgzIT46kmMWuIDvHJuCpiC9td3AxgLtBZIryV2hCwkaljpKjob2RTcBe5XpuQe+YQz4KDrUzT7+nZLVUdZNf9+C92VXtEtWC6IrpYCM4zNdqZkbZutK6p8O2/U0urZp9abSAmwk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1708633361; x=1709238161; i=anlauf@gmx.de; bh=XgeEKSjvMJKbC9KVZ1s3FW+VRAR6dOc8OJwbkkcs0ek=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From: In-Reply-To; b=GfxnISlGM69+Izp7azqD0dkcfdl258zYKAF5hw3OgQZFfARi4gcd6idi5U7+kDR0 7lNkOEB3WK6fKs+aAetfqR9rM8WvVzJaoFlmjpGsPy2GfHTFT5kATxACFtyNqkWhE XJ6Ywo6R7VsFHXPSCLzM4Y/yXARzKOcYQl16ptZYAsoEp7lIkmotFXWpfD0Y12WD+ R7KcMhaoUsDGNN2lvXdulCA1MOSSXRVt4wr0EFtz6p5e0rVkAfF0a03blhxSYwt9T exiWHU1s7f3llQZarvDXKBC4ATx7fw104MnDVu+ig6edJ2DA6gjfQm++M653xw5yz ETQYQdzDNfxKz0b++A== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([79.232.149.200]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MUowb-1rUD453avR-00QjA9; Thu, 22 Feb 2024 21:22:40 +0100 Message-ID: <406c0c3a-f9a4-4f40-a44d-2db284060a59@gmx.de> Date: Thu, 22 Feb 2024 21:22:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Fix fortran/PR114024 To: sgk@troutmask.apl.washington.edu Cc: Jerry D , fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: <29ba08a7-8218-4591-8c3f-36c17090e497@gmail.com> <3444d912-2e79-4e16-a425-79810d161ebb@gmx.de> Content-Language: en-US From: Harald Anlauf In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:BM1WoSD8qRWAKE2EcvW06ZlcFn4DySbteHiyG4LBC2nuHdgNcqH GL8b6LKU/LH54Dxm3KhAoz5q/DU1j2mrNrWSeAj5YMdwKPDN2jYxIh6qnM8eFgJ4xcg1iP3 p3JueW3nLayzHqq3jqRWnlZjSugpyobKmiX9a+AfkOsHmsoOLmIZcq9Huu8Pf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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: Hi Steve! On 2/22/24 01:52, Steve Kargl wrote: > On Wed, Feb 21, 2024 at 01:42:32PM -0800, Steve Kargl wrote: >> On Wed, Feb 21, 2024 at 10:20:43PM +0100, Harald Anlauf wrote: >>> On 2/21/24 22:00, Steve Kargl wrote: >>>> memleak vs ICE. I think I'll take one over the other. >>>> Probably need to free code->expr3 before the copy. >>> >>> Yep. >>> >>>> I tried gfc_replace_expr in an earlier patch. It did not >>>> work. > > > I tried freeing code->expr3 before assigning the new expression. > That leads to > > % gfcx -c ~/gcc/gccx/gcc/testsuite/gfortran.dg/allocate_with_source_28.f= 90 > pid 69473 comm f951 has trashed its stack, killing > gfortran: internal compiler error: Illegal instruction signal terminated= program f951 Right. I also don't see what the lifetimes of the expressions are. But is the gfc_copy_expr really needed? Wouldn't the following suffice? code->expr3 =3D gfc_get_parentheses (code->expr3); > If I don't free code->expr3 but simply assign the new > expression from gfc_get_parentheses(), your example > now compiles are executes are expected. It now > allocate_with_source_28.f90. Caveat: I don't know > how to test the CLASS uu. > >>>>> - it still fails on the following code, because the traversal >>>>> of the refs is incomplete / wrong: >>>>> >>>>> program foo >>>>> implicit none >>>>> complex :: cmp(3) >>>>> real, pointer :: pp(:) >>>>> class(*), allocatable :: uu(:) >>>>> type t >>>>> real :: re >>>>> real :: im >>>>> end type t >>>>> type u >>>>> type(t) :: tt(3) >>>>> end type u >>>>> type(u) :: cc >>>>> >>>>> cmp =3D (3.45,6.78) >>>>> cc% tt% re =3D cmp% re >>>>> cc% tt% im =3D cmp% im >>>>> allocate (pp, source =3D cc% tt% im) ! ICE >>>> >>>> cc%tt%im isn't a complex-part-ref, so this seems to >>>> be a different (maybe related) issue. Does the code >>>> compile with 'source =3D (cc%tt%im)'? If so, perhaps, >>>> detecting a component reference and doing the simply >>>> wrapping with parentheses can be done. >>> >>> Yes, that's why I tried to make up the above example. >>> I think %re and %im are not too special, they work >>> here pretty much like component refs elsewhere. >>> >> >> I see. The %re and %im complex-part-ref correspond to >> ref->u.i =3D=3D INQUIRY_RE and INQUIRY_IM, respectively. >> A part-ref for a user-defined type doesn't have an >> INQUIRY_xxx, so we'll need to see if there is a way to >> easily identify, e.g., cc%tt%re from your testcase. > > The attach patch uses ref->type =3D=3D REF_COMPONENT to deal > with the above code. I actually wanted to draw your attention away from the real/complex stuff, because that is not really the point. When do we actually need to enforce the parentheses? I tried the following, and it seems to work: if (code->expr3->expr_type =3D=3D EXPR_VARIABLE && is_subref_array (code->expr3)) code->expr3 =3D gfc_get_parentheses (code->expr3); (Beware: this is not regtested!) On the positive side, it not only seems to fix the cases in question, but also substring references etc., like the following: program foo implicit none complex :: cmp(3) =3D (3.45,6.78) real, pointer :: pp(:) integer, allocatable :: aa(:) class(*), allocatable :: uu(:), vv(:) type t ! pseudo "complex" type real :: re real :: im end type t type ci ! "complex integer" type integer :: re integer :: im end type ci type u type(t) :: tt(3) type(ci) :: ii(3) end type u type(u) :: cc character(3) :: str(3) =3D ["abc","def","ghi"] character(:), allocatable :: ac(:) allocate (ac, source=3Dstr(1::2)(2:3)) print *, str(1::2)(2:3) call my_print (ac) cc% tt% re =3D cmp% re cc% tt% im =3D cmp% im cc% ii% re =3D nint (cmp% re) cc% ii% im =3D nint (cmp% im) print *, "re=3D", cc% tt% re print *, "im=3D", cc% tt% im allocate (pp, source =3D cc% tt% re) print *, pp allocate (uu, source =3D cc% tt% im) call my_print (uu) allocate (vv, source =3D cc% ii% im) call my_print (vv) contains subroutine my_print (x) class(*), intent(in) :: x(:) select type (x) type is (real) print *, "'real':", x type is (integer) print *, "'integer':", x type is (character(*)) print *, "'character':", x end select end subroutine my_print end Cheers, Harald