From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by sourceware.org (Postfix) with ESMTPS id 751643858C50; Mon, 6 Nov 2023 18:20:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 751643858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 751643858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699294836; cv=none; b=gPZl83FwZxfroAGj9xYbpLzvZ9jDBXUvuU7pER9M7cms4Pi+mV1bngW8HM0Z5utV/9evnARE0VRtNswWQrdMBKaTt9DZc4HrtcdaghqO1/yVKEwv/VdHXpEqkYL+vlr8PWj7ro02MUMhNo6JFm8NLxw8u5cFQ5eLKGX2ybiwhF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699294836; c=relaxed/simple; bh=TiAdmAniXsNl/8WJFZOCH9VPFZID6pOyd1TOwn1EtbY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=ETxL8a4MxFpup5oSVOkY4SF3baC9x21nfV5K+uzcOhYLrKoHH6M1hULeZnGvWKu9tDGYZjIyFGC4UiJZKDUDp4obI0DYDIuI5upVUUsa9yT1hLmbGzSelXBYayki6nFLGKGn9n1icFvQuEJaSfZZTIXsYMKqHTI7s22C1E+fgyk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1699294833; x=1699899633; i=anlauf@gmx.de; bh=TiAdmAniXsNl/8WJFZOCH9VPFZID6pOyd1TOwn1EtbY=; h=X-UI-Sender-Class:Date:Subject:To:References:From:In-Reply-To; b=Trw+iMou7qLWt6ZnsE4IlFIhe7LbgDumntPTZRTqXM9DDRwUELv0to5MnlsZiz/K +t4zNEQyBkkJqSuvqBnEsYyL69E9G1GMByhgqsbVtp9e0qeooaa3JD7+QUfqrnmgF 5HFw/VHZsEsny24wRazxg0pUT+cCeqFMIQTLXYCvA4kGfrLLT/Go8QKx0ppxHWX2b unwNF6zbhEHLKNU881SSbuTL9zi8k9QNgJ3udg6ll8YeEPvMQFsmRKw+H6EkodtRo 2IN1pjScR8wNzMZPfexvLDTela8PlZJPFxPBwTKmr5lWrZlRnBBoc+H9FBsducfCD 0GcS0ycEpMFUh0IwNg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([79.232.146.236]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MPGRp-1qlZCG0nEr-00PgvG; Mon, 06 Nov 2023 19:20:33 +0100 Message-ID: <5562f6b7-1b0d-4ff7-9797-8f1f58edc1f5@gmx.de> Date: Mon, 6 Nov 2023 19:20:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] libgfortran: Remove empty array descriptor first dimension overwrite [PR112371] Content-Language: en-US To: Mikael Morin , gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: <20231106114325.828968-1-mikael@gcc.gnu.org> <20231106114325.828968-3-mikael@gcc.gnu.org> From: Harald Anlauf In-Reply-To: <20231106114325.828968-3-mikael@gcc.gnu.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:X9+K0SWFbnmYmDQeMS7BEkNSl/1evbPUggjbmRBYmd5KsjCY1aV ZHyc35oi7y9xQcuizQChUkzfXlJziKXqwhK+M+KL5dzX46XVPylCGu1S27RhcgLQsKx/evv nEgnwjR/RGkfwEX7uv6vVUI7iEkYInwt1xGJjLWAaFUS6benc+6ctZV5Nlqr1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: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 Mikael, Am 06.11.23 um 12:43 schrieb Mikael Morin: > Remove the forced overwrite of the first dimension of the result array > descriptor to set it to zero extent, in the function templates for > transformational functions doing an array reduction along a dimension. = This > overwrite, which happened before early returning in case the result arra= y > was empty, was wrong because an array may have a non-zero extent in the > first dimension and still be empty if it has a zero extent in a higher > dimension. Overwriting the dimension was resulting in wrong array resul= t > upper bound for the first dimension in that case. > > The offending piece of code was present in several places, and this remo= ves > them all. More precisely, there is only one case to fix for logical > reduction functions, and there are three cases for other reduction > functions, corresponding to non-masked reduction, reduction with array m= ask, > and reduction with scalar mask. The impacted m4 files are > ifunction_logical.m4 for logical reduction functions, ifunction.m4 for > regular functions and types, ifunction-s.m4 for character minloc and max= loc, > ifunction-s2.m4 for character minval and maxval, and ifindloc1.m4 for > findloc. while your fix seems mechanical and correct, I wonder if you looked at the following pre-existing irregularity which can be seen in this snippet: > diff --git a/libgfortran/m4/ifunction.m4 b/libgfortran/m4/ifunction.m4 > index 480649cf691..abc15b430ab 100644 > --- a/libgfortran/m4/ifunction.m4 > +++ b/libgfortran/m4/ifunction.m4 > @@ -96,12 +96,7 @@ name`'rtype_qual`_'atype_code` ('rtype` * const restr= ict retarray, > > retarray->base_addr =3D xmallocarray (alloc_size, sizeof (rtype_= name)); > if (alloc_size =3D=3D 0) > - { > - /* Make sure we have a zero-sized array. */ > - GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1); > - return; > - > - } > + return; > } > else > { This is all enclosed in a block which has if (retarray->base_addr =3D=3D NULL) but allocates and sets retarray->base_addr, while > @@ -290,11 +285,7 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const r= estrict retarray, > retarray->dtype.rank =3D rank; > > if (alloc_size =3D=3D 0) > - { > - /* Make sure we have a zero-sized array. */ > - GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1); > - return; > - } > + return; > else > retarray->base_addr =3D xmallocarray (alloc_size, sizeof (rtype_name)= ); > and > @@ -454,11 +445,7 @@ void > alloc_size =3D GFC_DESCRIPTOR_STRIDE(retarray,rank-1) * extent[r= ank-1]; > > if (alloc_size =3D=3D 0) > - { > - /* Make sure we have a zero-sized array. */ > - GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1); > - return; > - } > + return; > else > retarray->base_addr =3D xmallocarray (alloc_size, sizeof (rtype_name)= ); > } do not set retarray->base_addr to non-NULL for alloc_size =3D=3D 0. Do you know if the first snippet can be safely rewritten to avoid the (hopefully pointless) xmallocarray for alloc_size =3D=3D 0? Thanks, Harald