}
+/* Remove unneeded kind= argument from actual argument list when the
+ result conversion is dealt with in a different place. */
+
+static void
+strip_kind_from_actual (gfc_actual_arglist * actual)
+{
+ for (gfc_actual_arglist *a = actual; a; a = a->next)
+ {
+ gfc_actual_arglist *b = a->next;
+ if (b && b->name && strcmp (b->name, "kind") == 0)
+ {
+ a->next = b->next;
+ b->next = NULL;
+ gfc_free_actual_arglist (b);
+ }
+ }
+}
+
/* Emit code for minloc or maxloc intrinsic. There are many different cases
we need to handle. For performance reasons we sometimes create two
loops instead of one, where the second one is much simpler.
{
gfc_actual_arglist *a, *b;
a = actual;
+ strip_kind_from_actual (a);
while (a->next)
{
b = a->next;
--- /dev/null
+! { dg-do run }
+! PR fortran/97272 - Wrong answer from MAXLOC with character arg
+
+program test
+ implicit none
+ integer :: i, j, k, l = 10
+ character, allocatable :: a(:)
+ allocate (a(l))
+ a(:) = 'a'
+ l = l - 1
+ a(l) = 'b'
+ i = maxloc (a, dim=1)
+ j = maxloc (a, dim=1, kind=2)
+ k = maxloc (a, dim=1, kind=8, back=.true.)
+! print *, 'i = ', i, 'a(i) = ', a(i)
+! print *, 'j = ', j, 'a(j) = ', a(j)
+! print *, 'k = ', k, 'a(k) = ', a(k)
+ if (i /= l .or. j /= l .or. k /= l) stop 1
+end