mirror of git://gcc.gnu.org/git/gcc.git
![]() As mentioned in the PR, _gfortran_{,m,s}findloc2_s{1,4} iterate too many
times in the back case if nothing is found.
For !back, the loops are for (i = 1; i <= extent; i++) so i is in the
body [1, extent] if nothing is found, but for back it is
for (i = extent; i >= 0; i--) so i is in the body [0, extent] and compares
one element before the start of the array.
Note, findloc1_s{1,4} uses
for (n = len; n > 0; n--, src -= delta * len_array)
for the back loop and
for (n = 1; n <= len; n++, src += delta * len_array)
for !back. This patch fixes that.
The testcase fails under valgrind without the libgfortran changes and
succeeds with those.
2025-05-13 Jakub Jelinek <jakub@redhat.com>
PR libfortran/120196
* m4/ifindloc2.m4 (header1, header2): For back use i > 0 rather than
i >= 0 as for condition.
* generated/findloc2_s1.c: Regenerate.
* generated/findloc2_s4.c: Regenerate.
* gfortran.dg/pr120196.f90: New test.
(cherry picked from commit
|
||
---|---|---|
.. | ||
all.m4 | ||
any.m4 | ||
bessel.m4 | ||
count.m4 | ||
cshift0.m4 | ||
cshift1.m4 | ||
cshift1a.m4 | ||
eoshift1.m4 | ||
eoshift3.m4 | ||
findloc0.m4 | ||
findloc0s.m4 | ||
findloc1.m4 | ||
findloc1s.m4 | ||
findloc2s.m4 | ||
head.m4 | ||
iall.m4 | ||
iany.m4 | ||
ifindloc0.m4 | ||
ifindloc1.m4 | ||
ifindloc2.m4 | ||
iforeach-s.m4 | ||
iforeach-s2.m4 | ||
iforeach.m4 | ||
ifunc.m4 | ||
ifunction-s.m4 | ||
ifunction-s2.m4 | ||
ifunction.m4 | ||
ifunction_logical.m4 | ||
in_pack.m4 | ||
in_unpack.m4 | ||
iparity.m4 | ||
iparm.m4 | ||
matmul.m4 | ||
matmul_internal.m4 | ||
matmulavx128.m4 | ||
matmull.m4 | ||
maxloc0.m4 | ||
maxloc0s.m4 | ||
maxloc1.m4 | ||
maxloc1s.m4 | ||
maxloc2s.m4 | ||
maxval.m4 | ||
maxval0s.m4 | ||
maxval1s.m4 | ||
minloc0.m4 | ||
minloc0s.m4 | ||
minloc1.m4 | ||
minloc1s.m4 | ||
minloc2s.m4 | ||
minval.m4 | ||
minval0s.m4 | ||
minval1s.m4 | ||
misc_specifics.m4 | ||
mtype.m4 | ||
norm2.m4 | ||
pack.m4 | ||
parity.m4 | ||
pow.m4 | ||
product.m4 | ||
reshape.m4 | ||
shape.m4 | ||
specific.m4 | ||
specific2.m4 | ||
spread.m4 | ||
sum.m4 | ||
types.m4 | ||
unpack.m4 |