* [PATCH] PR fortran/104211 - ICE in find_array_section, at fortran/expr.cc:1720
@ 2022-02-10 20:28 Harald Anlauf
2022-02-14 17:27 ` Thomas Koenig
0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-02-10 20:28 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 275 bytes --]
Dear Fortranners,
when referencing a bad array section after an erroneous previous
declaration we might hit an assert. The assert can be replaced
by a more gracious error recovery. Reported by Gerhard.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-improve-error-recovery-on-bad-array-section.patch --]
[-- Type: text/x-patch, Size: 1851 bytes --]
From d0250b563eb51f5f5fba5a73a40451cedeb5900d Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Thu, 10 Feb 2022 21:22:48 +0100
Subject: [PATCH] Fortran: improve error recovery on bad array section
gcc/fortran/ChangeLog:
PR fortran/104211
* expr.cc (find_array_section): Replace assertion by error
recovery when encountering bad array constructor.
gcc/testsuite/ChangeLog:
PR fortran/104211
* gfortran.dg/pr104211.f90: New test.
---
gcc/fortran/expr.cc | 8 +++++++-
gcc/testsuite/gfortran.dg/pr104211.f90 | 11 +++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr104211.f90
diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index ed82a94022f..c9c0ba4cc2e 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -1718,7 +1718,13 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
}
cons = gfc_constructor_lookup (base, limit);
- gcc_assert (cons);
+ if (cons == NULL)
+ {
+ gfc_error ("Error in array constructor referenced at %L",
+ &ref->u.ar.where);
+ t = false;
+ goto cleanup;
+ }
gfc_constructor_append_expr (&expr->value.constructor,
gfc_copy_expr (cons->expr), NULL);
}
diff --git a/gcc/testsuite/gfortran.dg/pr104211.f90 b/gcc/testsuite/gfortran.dg/pr104211.f90
new file mode 100644
index 00000000000..21b0a26a17f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104211.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/104211 - ICE in find_array_section
+! Contributed by G.Steinmetz
+
+program p
+ type t
+ real :: n
+ end type
+ type(t), parameter :: a(3) = [t(2)] ! { dg-error "Different shape" }
+ type(t), parameter :: b(2) = a(2:3) ! { dg-error "Error in array constructor" }
+end
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PR fortran/104211 - ICE in find_array_section, at fortran/expr.cc:1720
2022-02-10 20:28 [PATCH] PR fortran/104211 - ICE in find_array_section, at fortran/expr.cc:1720 Harald Anlauf
@ 2022-02-14 17:27 ` Thomas Koenig
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Koenig @ 2022-02-14 17:27 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
Hi Harald,
> when referencing a bad array section after an erroneous previous
> declaration we might hit an assert. The assert can be replaced
> by a more gracious error recovery. Reported by Gerhard.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
OK.
Thanks for the patch!
Best regards
Thomas
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-14 17:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 20:28 [PATCH] PR fortran/104211 - ICE in find_array_section, at fortran/expr.cc:1720 Harald Anlauf
2022-02-14 17:27 ` Thomas Koenig
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).