From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by sourceware.org (Postfix) with ESMTPS id 679083858D3C; Sun, 12 May 2024 20:57:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 679083858D3C 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 679083858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715547456; cv=none; b=rHDSACSWZWuXVLWMHx7GcsQiIpknVA9oC44LPSPc2XWiP34zkPc0cGStiyDYq4LOFV4obvPaNQ+mTZPrbyYzN3Zpto/oUvEXvWBCJ4h9u2cJgBBGsMrGYPfdpypVc9csGePNX3MMkitQEdTt/z6ymS+ScAMUg8KWRStXoxLo0fE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715547456; c=relaxed/simple; bh=ZGf/8G2PoGgndwz7ZtUMRwB0Aw2X+fT/3awyPTuwaRc=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=bYfa6CYVrQ28tueSOT0Nfi5ka93L4OboeQST2RbC19yQwMMjl4VghzteY5pCgpXxF9BIKxgdY0K91g+2BA0zhupSCfrFOP6t1ZleohKvA6JYpdYtbeQjbv0GU0mR6nmtn+3SiVPQU95MbHwYHnFLUEzmGRn3cv2/QQEW9tYeNY4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1715547452; x=1716152252; i=anlauf@gmx.de; bh=Aj5WVajDrtZrf6yF9VaCfpHEoQElrLou2yOp3Go3ORg=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To:Cc: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=LaILG9tfMdvAqaj8eOdBRk3TAOm3OVRmK/ckC3VrdEMODLHsiN4/9peIZJGklDxx qsyVMPE/ErheL61ebuantET84CpfOeDhFSv1d5IGPwsl2Muyb0LcYmEf3aZh+tpUi +sDeDTGUicACbxybcPYipuUSF4chD+3WSQWtAyACrM2gZpvwK8vQNaA1OeEhkKGK1 U3936PFok6sr8gqI1j3x0N8xS0ZsP0v3ydmpp6nJN/3Ya6HWyu8Y7tOtfb+uzXH58 ki0OUJmaoXWz7e7BEVmXzdkA1aHxreqOyL4o/ke/Z9rf9Rhb2yglnYH7M/LL+fOhg QVmd/KCi1qlXckhdiw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([93.207.82.27]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MXXuB-1s5TZz0sAx-00Z1pb; Sun, 12 May 2024 22:57:32 +0200 Message-ID: Date: Sun, 12 May 2024 22:57:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [Patch, fortran] PR113363 - ICE on ASSOCIATE and unlimited polymorphic function To: Paul Richard Thomas Cc: "fortran@gcc.gnu.org" , gcc-patches Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: <1c17a1be-7c40-451d-baa1-652cc40a16b4@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:t2qAwvy1fHAQSqc64nMlld5I3wc7pBq4w9DQWHa4bm4s2YxoU9q Q3h3CGSP9ueyJ8sG8U9NNc/TlzulUEOPkK9DWrgTTdO3mQaqdEn9j6kRS3S2XaEdhCWM5z8 gP0PlmGw9vrRcXmjRey7eR+SFXyhHKZ0WFqkn/Pp2cptAZgwozR3epiws5T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CVD_IN_MSPIKE_H2,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 List-Id: Hi Paul, this looks all good now, and is OK for mainline as well as backporting! *** While playing with the testcase, I found 3 remaining smaller issues that are pre-existing, so they should not delay your present work. To make it clear: these are not regressions. When "maliciously" perturbing the testcase by adding parentheses in the right places, I see the following: Replacing associate (var =3D> foo ()) ! OK after r14-9489-g3fd46d859cda10 by associate (var =3D> (foo ())) gives an ICE here with 14-branch and 15-mainline. Similarly replacing allocate (y, source =3D x(1)) ! Gave zero length here by allocate (y, source =3D (x(1))) Furthermore, replacing allocate(x, source =3D foo ()) by allocate(x, source =3D (foo ())) gives a runtime segfault with both 14-branch and 15-mainline. So this is something for another day... Thanks for the patch! Harald Am 12.05.24 um 13:27 schrieb Paul Richard Thomas: > Hi Harald, > > Please find attached my resubmission for pr113363. The changes are as > follows: > (i) The chunk in gfc_conv_procedure_call is new. This was the source of = one > of the memory leaks; > (ii) The incorporation of the _len field in trans_class_assignment was d= one > for the pr84006 patch; > (iii) The source of all the invalid memory accesses and so on was down t= o > the use of realloc. I tried all sorts of workarounds such as testing the > vptrs and the sizes but only free followed by malloc worked. I have no i= dea > at all why this is the case; and > (iv) I took account of your remarks about the chunk in trans-array.cc by > removing it and that the chunk in trans-stmt.cc would leak frontend memo= ry. > > OK for mainline (and -14 branch after a few-weeks)? > > Regards > > Paul > > Fortran: Fix wrong code in unlimited polymorphic assignment [PR113363] > > 2024-05-12 Paul Thomas > > gcc/fortran > PR fortran/113363 > * trans-array.cc (gfc_array_init_size): Use the expr3 dtype so > that the correct element size is used. > * trans-expr.cc (gfc_conv_procedure_call): Remove restriction > that ss and ss->loop be present for the finalization of class > array function results. > (trans_class_assignment): Use free and malloc, rather than > realloc, for character expressions assigned to unlimited poly > entities. > * trans-stmt.cc (gfc_trans_allocate): Build a correct rhs for > the assignment of an unlimited polymorphic 'source'. > > gcc/testsuite/ > PR fortran/113363 > * gfortran.dg/pr113363.f90: New test. > > >>> The first chunk in trans-array.cc ensures that the array dtype is set = to >>> the source dtype. The second chunk ensures that the lhs _len field doe= s >> not >>> default to zero and so is specific to dynamic types of character. >>> >> >> Why the two gfc_copy_ref? valgrind pointed my to the tail >> of gfc_copy_ref which already has: >> >> dest->next =3D gfc_copy_ref (src->next); >> >> so this looks redundant and leaks frontend memory? >> >> *** >> >> Playing with the testcase, I find several invalid writes with >> valgrind, or a heap buffer overflow with -fsanitize=3Daddress . >> >> >> >