* [PATCH] Fortran: error recovery with references of bad array constructors [PR105633]
@ 2022-10-19 20:49 Harald Anlauf
2022-10-20 19:02 ` Mikael Morin
0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-10-19 20:49 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 298 bytes --]
Dear Fortranners,
here's another patch that improves error receovery with references
of bad array constructors leading to an ICE after a NULL pointer
dereference.
Original patch by Steve, which I amended with a logic cleanup.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr105633.diff --]
[-- Type: text/x-patch, Size: 2146 bytes --]
From 0da12c71a6ccbefa1456be5759974a4b450c78e6 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 19 Oct 2022 22:37:56 +0200
Subject: [PATCH] Fortran: error recovery with references of bad array
constructors [PR105633]
gcc/fortran/ChangeLog:
PR fortran/105633
* expr.cc (find_array_section): Move check for NULL pointers so
that both subscript triplets and vector subscripts are covered.
gcc/testsuite/ChangeLog:
PR fortran/105633
* gfortran.dg/pr105633.f90: New test.
Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
---
gcc/fortran/expr.cc | 10 +++++++---
gcc/testsuite/gfortran.dg/pr105633.f90 | 8 ++++++++
2 files changed, 15 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr105633.f90
diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 290ddf360c8..69d0b57c688 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -1552,6 +1552,12 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
lower = ref->u.ar.as->lower[d];
upper = ref->u.ar.as->upper[d];
+ if (!lower || !upper)
+ {
+ t = false;
+ goto cleanup;
+ }
+
if (ref->u.ar.dimen_type[d] == DIMEN_VECTOR) /* Vector subscript. */
{
gfc_constructor *ci;
@@ -1594,9 +1600,7 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
{
if ((begin && begin->expr_type != EXPR_CONSTANT)
|| (finish && finish->expr_type != EXPR_CONSTANT)
- || (step && step->expr_type != EXPR_CONSTANT)
- || !lower
- || !upper)
+ || (step && step->expr_type != EXPR_CONSTANT))
{
t = false;
goto cleanup;
diff --git a/gcc/testsuite/gfortran.dg/pr105633.f90 b/gcc/testsuite/gfortran.dg/pr105633.f90
new file mode 100644
index 00000000000..f2dbc5e742a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr105633.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/105633 - ICE in find_array_section
+! Contributed by G.Steinmetz
+
+program p
+ integer, parameter :: a(:) = [1,2] ! { dg-error "deferred shape" }
+ print *, [a([1,2])]
+end
--
2.35.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fortran: error recovery with references of bad array constructors [PR105633]
2022-10-19 20:49 [PATCH] Fortran: error recovery with references of bad array constructors [PR105633] Harald Anlauf
@ 2022-10-20 19:02 ` Mikael Morin
0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2022-10-20 19:02 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
Le 19/10/2022 à 22:49, Harald Anlauf via Fortran a écrit :
> Dear Fortranners,
>
> here's another patch that improves error receovery with references
> of bad array constructors leading to an ICE after a NULL pointer
> dereference.
>
> Original patch by Steve, which I amended with a logic cleanup.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
Yes, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-20 19:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 20:49 [PATCH] Fortran: error recovery with references of bad array constructors [PR105633] Harald Anlauf
2022-10-20 19:02 ` Mikael Morin
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).