Hi Jakub,
Jakub Jelinek wrote:
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.
...
Tested on x86_64-linux and i686-linux, ok for trunk?
LGTM - Thanks for the patch.
(I think, I had used '>= 1' not '> 0' for symmetry with 'i = 1; ... i <=
extent'; however, the patch is fine as is – and it is really not
worthwhile to spend time on this for a tiny code symmetry improvement.)
2025-05-13 Jakub Jelinek <ja...@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.
Tobias