First is slightly confusing as there are three patches for PR120191.

In particular, two which look almost identical - one for loc2 (this one)
and one for loc1 (the one sent one our later). Jakub pointed out that
the remarks after "ok for trunk?" for this patch are obsoleted by
the follow up patch (i.e. loc1 one).

Jakub Jelinek wrote:

One dealt with in this patch are _gfortran_s{max,min}loc2_{4,8,16}_s{1,4}
functions.  Those are trivial wrappers around
_gfortrani_{max,min}loc2_{4,8,16}_s{1,4} which should call those functions
if the scalar mask is true and just return 0 otherwise.
The two bugs I see there is that the back, len arguments are swapped,
which means that it always acts as back=.true. and for len will use
character length of 1 or 0 instead of the desired one.
...
The other problem is that it was just testing if (mask).  In my limited
Fortran understanding that means that the optional argument mask was
supplied but nothing about its actual value.  Other scalar mask generated
routines use if (mask == NULL || *mask) as the condition when to call the
non-masked function, i.e. when mask is not supplied (then it should act like
.true. mask) or when it is supplied and evaluates to .true.).

Fortran 2023 states:

"MASK (optional) shall be of type logical and shall be conformable with ARRAY."

and "conformable - having the same shape, or one being an array and the
other being scalar"

Thus, the change makes sense.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

LGTM. Thanks!

Tobias

2025-05-12 Jakub Jelinek <ja...@redhat.com>

        PR fortran/120191
        * m4/maxloc2s.m4: For smaxloc2 call maxloc2 if mask is NULL or *mask.
        Swap back and len arguments.
        * m4/minloc2s.m4: Likewise.
        * generated/maxloc2_4_s1: Regenerate.
        * generated/maxloc2_4_s4: Regenerate.
        * generated/maxloc2_8_s1: Regenerate.
        * generated/maxloc2_8_s4: Regenerate.
        * generated/maxloc2_16_s1: Regenerate.
        * generated/maxloc2_16_s4: Regenerate.
        * generated/minloc2_4_s1: Regenerate.
        * generated/minloc2_4_s4: Regenerate.
        * generated/minloc2_8_s1: Regenerate.
        * generated/minloc2_8_s4: Regenerate.
        * generated/minloc2_16_s1: Regenerate.
        * generated/minloc2_16_s4: Regenerate.

        * gfortran.dg/pr120191_2.f90: New test.

Reply via email to