* [PATCH, committed] PR fortran/104811 - maxloc/minloc cannot accept character arguments without `dim` optional argument
@ 2022-03-08 20:59 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-03-08 20:59 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 621 bytes --]
Dear all,
frontend-optimization of MINLOC/MAXLOC tries to generate code for rank-1
arrays that may be expanded inline later and optimzed. Except when the
argument is a character array...
As there is even a comment in trans-intrinsic.cc that we will call a
library function for character arguments anyway, we better punt here.
The attached obvious patch does this and was pre-approved by Thomas in
the PR.
Regtested on x86_64-pc-linux-gnu and pushed to mainline as
https://gcc.gnu.org/g:e3e369dad6cbecb1b490b3f3b154c600fba5a6f3
As this is a wrong-code issue, I'd like to backport this to 11-branch.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr104811.diff --]
[-- Type: text/x-patch, Size: 2015 bytes --]
From e3e369dad6cbecb1b490b3f3b154c600fba5a6f3 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
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 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;
diff --git a/gcc/testsuite/gfortran.dg/minmaxloc_16.f90 b/gcc/testsuite/gfortran.dg/minmaxloc_16.f90
new file mode 100644
index 00000000000..099248df2e3
--- /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.34.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-08 20:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 20:59 [PATCH, committed] PR fortran/104811 - maxloc/minloc cannot accept character arguments without `dim` optional argument Harald Anlauf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).