Jakub Jelinek wrote:
This unfortunately only fixes some of the cases in the new testcase.

We indeed should drop the kind argument from what is passed to the
library, but need to do it not only when one uses the argument name
for it (so kind=4 etc.) but also when one passes all the arguments
to the intrinsics.

The following patch uses what gfc_conv_intrinsic_findloc uses,
which looks more efficient and cleaner, we already set automatic
vars to point to the kind and back actual arguments, so we can just
free/clear expr on the former and set name to "%VAL" on the latter.

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

LGTM – but it seems that we should do a minor cleanup while being there:

...

--- gcc/fortran/trans-intrinsic.cc.jj   2025-04-22 21:26:15.772920190 +0200
+++ gcc/fortran/trans-intrinsic.cc      2025-05-09 17:41:27.323962631 +0200
...
+  /* Remove kind.  */
+  if (kind_arg->expr)
      {
...
+      gfc_free_expr (kind_arg->expr);
+      kind_arg->expr = NULL;
      }
+ /* Pass BACK argument by value. */
+  back_arg->name = "%VAL";
+
...
        gfc_actual_arglist *a = actual;
-      strip_kind_from_actual (a);
        while (a)
        {
          if (a->name && strcmp (a->name, "dim") == 0)

Namely: Similar to above, we should be able to just do:

   if (dim_arg->expr)

I think the comment should be also updated and we
can also get rid of the 'actual' variable for cleanup.

Namely, something like the following on top of your patch (untested):
---------------------
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -4912 +4912 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, 
enum tree_code op)
-  gfc_actual_arglist *actual, *array_arg, *dim_arg, *mask_arg, *kind_arg;
+  gfc_actual_arglist *array_arg, *dim_arg, *mask_arg, *kind_arg;
@@ -4931,2 +4931 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, 
enum tree_code op)
-  actual = expr->value.function.actual;
-  array_arg = actual;
+  array_arg = expr->value.function.actual;
@@ -4972 +4971 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, 
enum tree_code op)
-  arrayexpr = actual->expr;
+  arrayexpr = array_arg->expr;
@@ -4974,2 +4973,2 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * 
expr, enum tree_code op)
-  /* Special case for character maxloc.  Remove unneeded actual
-     arguments, then call a library function.  */
+  /* Special case for character maxloc.  Remove unneeded "dim"
+     actual argument, then call the library function.  */
@@ -4980,3 +4979 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, 
enum tree_code op)
-
-      gfc_actual_arglist *a = actual;
-      while (a)
+      if (dim_arg->expr)
@@ -4984,6 +4981,2 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * 
expr, enum tree_code op)
-         if (a->name && strcmp (a->name, "dim") == 0)
-           {
-             gfc_free_expr (a->expr);
-             a->expr = NULL;
-           }
-         a = a->next;
+         gfc_free_expr (dim_arg->expr);
+         dim_arg->expr = NULL;
---------------------

Thanks to both of your for the patch and to Daniil additionally
for reporting and debugging this issue!

Tobias

Reply via email to