From e3e369dad6cbecb1b490b3f3b154c600fba5a6f3 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 8 Mar 2022 21:47:04 +0100 Subject: [PATCH] Fortran: do not frontend-optimize MINLOC/MAXLOC for character arrays gcc/fortran/ChangeLog: PR fortran/104811 * frontend-passes.cc (optimize_minmaxloc): Do not attempt frontend-optimization of MINLOC/MAXLOC for character arrays, as there is no suitable code yet for inline expansion. gcc/testsuite/ChangeLog: PR fortran/104811 * gfortran.dg/minmaxloc_16.f90: New test. --- gcc/fortran/frontend-passes.cc | 1 + gcc/testsuite/gfortran.dg/minmaxloc_16.f90 | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/minmaxloc_16.f90 diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc index 4033f27..5eba634 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; diff --git a/gcc/testsuite/gfortran.dg/minmaxloc_16.f90 b/gcc/testsuite/gfortran.dg/minmaxloc_16.f90 new file mode 100644 index 0000000..099248d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/minmaxloc_16.f90 @@ -0,0 +1,14 @@ +! { dg-do run } +! { dg-options "-fdump-tree-original" } +! PR fortran/104811 +! Frontend-optimization mis-optimized minloc/maxloc of character arrays + +program p + character(1) :: str(3) + str = ["a", "c", "a"] + if (any (maxloc (str) /= 2)) stop 1 + if (minloc (str,dim=1) /= 1) stop 2 +end + +! { dg-final { scan-tree-dump-times "_gfortran_maxloc0_4_s1" 1 "original" } } +! { dg-final { scan-tree-dump-times "_gfortran_minloc2_4_s1" 1 "original" } } -- 2.7.4