From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH, committed] PR fortran/104811 - maxloc/minloc cannot accept character arguments without `dim` optional argument
Date: Tue, 8 Mar 2022 21:59:03 +0100 [thread overview]
Message-ID: <trinity-2ee686f7-212c-49e0-9993-06dcbdffef8d-1646773143173@3c-app-gmx-bap36> (raw)
[-- 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
reply other threads:[~2022-03-08 20:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-2ee686f7-212c-49e0-9993-06dcbdffef8d-1646773143173@3c-app-gmx-bap36 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).