https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104811

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |anlauf at gcc dot gnu.org
   Last reconfirmed|                            |2022-03-07

--- Comment #2 from anlauf at gcc dot gnu.org ---
(In reply to kargl from comment #1)
> Compiles and executes without optimization or if -fno-frontend-optimize is
> used with optimization.

Good observation.

The inline expansion that may be helpful for integer and real arguments
will not even be done in trans-intrinsic.cc, as the following comment
explains:

  /* Special case for character maxloc.  Remove unneeded actual
     arguments, then call a library function.  */

The obvious solution is to punt on character array arguments:

diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 4033f27df99..5eba6345145 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -2276,6 +2276,7 @@ optimize_minmaxloc (gfc_expr **e)
   if (fn->rank != 1
       || fn->value.function.actual == NULL
       || fn->value.function.actual->expr == NULL
+      || fn->value.function.actual->expr->ts.type == BT_CHARACTER
       || fn->value.function.actual->expr->rank != 1)
     return;

Reply via email to