From: Mikael Morin <morin-mikael@orange.fr>
To: gfortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] fortran: Explicitly set name for *LOC default BACK argument [PR108450]
Date: Sun, 29 Jan 2023 17:21:36 +0100 [thread overview]
Message-ID: <673726a8-fdce-6c8a-0814-3d0ad666fa2c@orange.fr> (raw)
[-- Attachment #1: Type: text/plain, Size: 574 bytes --]
Hello,
this is a fix for a gcc-12 ICE regression.
This ICE rings a bell to me, and I think the change by Tobias which
triggers it only uncovers a bug that can also happen independently in
other cases.
The problem is resolution of maxloc expressions is not idempotent, that
is resolution changes the expression in such a way that it can't be
successfully resolved again.
I have not tried to prevent multiple resolutions, and fixed instead the
way the expression is changed. The patch explains the details.
No regression on x86_64-pc-linux-gnu.
OK for master and 12?
[-- Attachment #2: 0001-fortran-Set-name-for-LOC-default-BACK-argument-PR108.patch --]
[-- Type: text/x-patch, Size: 3027 bytes --]
From e61e2a51e1859f884125670010337f34265997b8 Mon Sep 17 00:00:00 2001
From: Mikael Morin <mikael@gcc.gnu.org>
Date: Sun, 29 Jan 2023 14:38:08 +0100
Subject: [PATCH] fortran: Set name for *LOC default BACK argument [PR108450]
This change fixes an ICE caused by the double resolution of MINLOC,
MAXLOC and FINDLOC expressions which get a default value for the BACK
argument at resolution time. That argument is added without name,
and argument reordering code is not prepared to handle unnamed arguments
coming after named ones, so the second resolution causes a NULL pointer
dereference.
The problem is fixed by explicitly setting the argument name.
PR fortran/108450
gcc/fortran/ChangeLog:
* check.cc (gfc_check_minloc_maxloc): Explicitly set argument name.
(gfc_check_findloc): Ditto.
gcc/testsuite/ChangeLog:
* gfortran.dg/gomp/minmaxloc_1.f90: New test.
---
gcc/fortran/check.cc | 2 ++
.../gfortran.dg/gomp/minmaxloc_1.f90 | 32 +++++++++++++++++++
2 files changed, 34 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/gomp/minmaxloc_1.f90
diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index ebcb8f39852..8c1ae8c2f00 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -3888,6 +3888,7 @@ gfc_check_minloc_maxloc (gfc_actual_arglist *ap)
{
b = gfc_get_logical_expr (gfc_logical_4_kind, NULL, 0);
ap->next->next->next->next->expr = b;
+ ap->next->next->next->next->name = gfc_get_string ("back");
}
if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
@@ -3969,6 +3970,7 @@ gfc_check_findloc (gfc_actual_arglist *ap)
{
b = gfc_get_logical_expr (gfc_logical_4_kind, NULL, 0);
ap->next->next->next->next->next->expr = b;
+ ap->next->next->next->next->next->name = gfc_get_string ("back");
}
if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL
diff --git a/gcc/testsuite/gfortran.dg/gomp/minmaxloc_1.f90 b/gcc/testsuite/gfortran.dg/gomp/minmaxloc_1.f90
new file mode 100644
index 00000000000..b3691f774de
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/minmaxloc_1.f90
@@ -0,0 +1,32 @@
+! { dg-do compile }
+!
+! PR fortran/108450
+! This program used to cause an ICE because of the double resolution
+! of the maxloc expression and the addition of a hidden unnamed argument
+! during the first resolution.
+!
+! Original testcase from G. Steinmetz
+
+subroutine s1
+ integer :: a(8) = 0
+ integer :: l
+ integer :: n
+ !$omp atomic
+ n = maxloc(a, mask=l) ! { dg-error ".mask. argument of .maxloc. intrinsic at .1. must be LOGICAL" }
+end
+
+subroutine s2
+ integer :: a(8) = 0
+ integer :: l
+ integer :: n
+ !$omp atomic
+ n = minloc(a, mask=l) ! { dg-error ".mask. argument of .minloc. intrinsic at .1. must be LOGICAL" }
+end
+
+subroutine s3
+ integer :: a(8) = 0
+ integer :: l
+ integer :: n
+ !$omp atomic
+ n = findloc(a, 3, mask=l) ! { dg-error ".mask. argument of .findloc. intrinsic at .1. must be LOGICAL" }
+end
--
2.39.0
next reply other threads:[~2023-01-29 16:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-29 16:21 Mikael Morin [this message]
2023-01-29 19:36 ` Harald Anlauf
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=673726a8-fdce-6c8a-0814-3d0ad666fa2c@orange.fr \
--to=morin-mikael@orange.fr \
--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).