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.

Reply via email to