From: Mikael Morin <morin-mikael@orange.fr>
To: Harald Anlauf <anlauf@gmx.de>, Mikael Morin <mikael@gcc.gnu.org>,
gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org
Subject: Re: [PATCH 1/2] libgfortran: Remove early return if extent is zero [PR112371]
Date: Mon, 6 Nov 2023 19:57:42 +0100 [thread overview]
Message-ID: <f4414e70-cd40-4866-95c2-036dd79c9077@orange.fr> (raw)
In-Reply-To: <8e65205b-fbe9-40fb-ba72-a77ab87ab688@gmx.de>
Le 06/11/2023 à 19:12, Harald Anlauf a écrit :
> Hi Mikael,
>
> Am 06.11.23 um 12:43 schrieb Mikael Morin:
>> Remove the early return present in function templates for
>> transformational
>> functions doing a (masked) reduction of an array along a dimension.
>> This early return, which triggered if the extent in the reduction
>> dimension
>> was zero, was wrong because even if the reduction operation
>> degenerates to
>> a constant value in that case, one has to loop anyway along the other
>> dimensions to initialize every element of the resulting array with that
>> constant value.
>>
>> The offending piece of code was present in several places, and this
>> removes
>> them all. Namely, the impacted m4 files are ifunction.m4 for regular
>> functions and types, ifunction-s.m4 for character minloc and maxloc, and
>> ifunction-s2.m4 for character minval and maxval.
>
> I wonder if the correct fix would be to replace (instead of deleting)
>
>> diff --git a/libgfortran/m4/ifunction.m4 b/libgfortran/m4/ifunction.m4
>> index c64217ec5db..480649cf691 100644
>> --- a/libgfortran/m4/ifunction.m4
>> +++ b/libgfortran/m4/ifunction.m4
>> @@ -232,8 +232,6 @@ m'name`'rtype_qual`_'atype_code` ('rtype` * const
>> restrict retarray,
>> }
>>
>> len = GFC_DESCRIPTOR_EXTENT(array,dim);
>> - if (len <= 0)
>> - return;
>>
>> mbase = mask->base_addr;
>>
>
> by the following:
>
> if (len < 0)
> len = 0;
>
> See ifunction.m4, lines 56ff, which check if the result of
>
> len = GFC_DESCRIPTOR_EXTENT(array,dim);
>
> is negative. I haven't tried to create a testcase, though.
>
> Similarly for the other templates.
>
Yes, you're right. I think I won't try to create a testcase and will
just pick your suggestion which seems safer.
next prev parent reply other threads:[~2023-11-06 18:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-06 11:43 [PATCH 0/2] libgfortran: empty array fixes [PR112371] Mikael Morin
2023-11-06 11:43 ` [PATCH 1/2] libgfortran: Remove early return if extent is zero [PR112371] Mikael Morin
2023-11-06 18:12 ` Harald Anlauf
2023-11-06 18:57 ` Mikael Morin [this message]
2023-11-06 11:43 ` [PATCH 2/2] libgfortran: Remove empty array descriptor first dimension overwrite [PR112371] Mikael Morin
2023-11-06 18:20 ` Harald Anlauf
2023-11-06 19:19 ` Mikael Morin
2023-11-06 20:03 ` Harald Anlauf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f4414e70-cd40-4866-95c2-036dd79c9077@orange.fr \
--to=morin-mikael@orange.fr \
--cc=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=mikael@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).