]> git.ipfire.org Git - thirdparty/gcc.git/commit
fortran: Support optional dummy as BACK argument of MINLOC/MAXLOC.
authorMikael Morin <mikael@gcc.gnu.org>
Fri, 2 Aug 2024 12:24:34 +0000 (14:24 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Fri, 2 Aug 2024 16:38:51 +0000 (18:38 +0200)
commita10436a8404ad2f0cc5aa4d6a0cc850abe5ef49e
tree1529b1267ff4f46314e160580bb41795e5376ae4
parentda33ad53bcb57943fa671c745938a53f4de89a1b
fortran: Support optional dummy as BACK argument of MINLOC/MAXLOC.

Protect the evaluation of BACK with a check that the reference is non-null
in case the expression is an optional dummy, in the inline code generated
for MINLOC and MAXLOC.

This change contains a revert of the non-testsuite part of commit
r15-1994-ga55d24b3cf7f4d07492bb8e6fcee557175b47ea3, which factored the
evaluation of BACK out of the loop using the scalarizer.  It was a bad idea,
because delegating the argument evaluation to the scalarizer makes it
cumbersome to add a null pointer check next to the evaluation.

Instead, evaluate BACK at the beginning, before scalarization, add a check
that the argument is present if necessary, and evaluate the resulting
expression to a variable, before using the variable in the inline code.

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (maybe_absent_optional_variable): New function.
(gfc_conv_intrinsic_minmaxloc): Remove BACK from scalarization and
evaluate it before.  Add a check that BACK is not null if the
expression is an optional dummy.  Save the resulting expression to a
variable.  Use the variable in the generated inline code.

gcc/testsuite/ChangeLog:

* gfortran.dg/maxloc_6.f90: New test.
* gfortran.dg/minloc_7.f90: New test.
gcc/fortran/trans-intrinsic.cc
gcc/testsuite/gfortran.dg/maxloc_6.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/minloc_7.f90 [new file with mode: 0644]