public inbox for
 help / color / mirror / Atom feed
From: Harald Anlauf <>
To: fortran <>, gcc-patches <>
Subject: [PATCH, committed] Fortran: error recovery on invalid ARRAY argument to FINDLOC [PR106986]
Date: Tue, 20 Sep 2022 22:57:41 +0200	[thread overview]
Message-ID: <trinity-9e520054-06e7-4d11-b6b4-6effcb36b106-1663707461703@3c-app-gmx-bap12> (raw)

[-- Attachment #1: Type: text/plain, Size: 441 bytes --]

Dear all,

we ICE'd in the simplification of FINDLOC when the passed
ARRAY argument had an invalid declaration.  The reason was
a reference to array->shape which was NULL.

Obvious solution: then just don't attempt to simplify.

Regtested on x86_64-pc-linux-gnu and pushed to mainline as

The PR is marked as a 10/11/12/13 regression, thus I plan to


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr106986.diff --]
[-- Type: text/x-patch, Size: 1592 bytes --]

From 5976fbf9d5dd9542fcb82eebb2185886fd52d000 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <>
Date: Tue, 20 Sep 2022 22:41:48 +0200
Subject: [PATCH] Fortran: error recovery on invalid ARRAY argument to FINDLOC


	PR fortran/106986
	* (gfc_simplify_findloc): Do not try to simplify
	intrinsic FINDLOC when the ARRAY argument has a NULL shape.


	PR fortran/106986
	* gfortran.dg/pr106986.f90: New test.
 gcc/fortran/                | 1 +
 gcc/testsuite/gfortran.dg/pr106986.f90 | 8 ++++++++
 2 files changed, 9 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr106986.f90

diff --git a/gcc/fortran/ b/gcc/fortran/
index 140c17721a7..c0fbd0ed7c2 100644
--- a/gcc/fortran/
+++ b/gcc/fortran/
@@ -5895,6 +5895,7 @@ gfc_simplify_findloc (gfc_expr *array, gfc_expr *value, gfc_expr *dim,
   bool back_val = false;

   if (!is_constant_array_expr (array)
+      || array->shape == NULL
       || !gfc_is_constant_expr (dim))
     return NULL;

diff --git a/gcc/testsuite/gfortran.dg/pr106986.f90 b/gcc/testsuite/gfortran.dg/pr106986.f90
new file mode 100644
index 00000000000..a309b25d181
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr106986.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/106986 - ICE in simplify_findloc_nodim
+! Contributed by G.Steinmetz
+program p
+  integer, parameter :: a(:) = [1] ! { dg-error "deferred shape" }
+  print *, findloc (a, 1)

                 reply	other threads:[~2022-09-20 20:57 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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-9e520054-06e7-4d11-b6b4-6effcb36b106-1663707461703@3c-app-gmx-bap12 \ \ \ \

* 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).