public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3392] Fortran - improve error recovery determining array element from constructor
@ 2021-09-07 18:52 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2021-09-07 18:52 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:2a1537a19cb2fa85823cfa18ed40baa4b259b4e3
commit r12-3392-g2a1537a19cb2fa85823cfa18ed40baa4b259b4e3
Author: Harald Anlauf <anlauf@gmx.de>
Date: Tue Sep 7 20:51:49 2021 +0200
Fortran - improve error recovery determining array element from constructor
gcc/fortran/ChangeLog:
PR fortran/101327
* expr.c (find_array_element): When bounds cannot be determined as
constant, return error instead of aborting.
gcc/testsuite/ChangeLog:
PR fortran/101327
* gfortran.dg/pr101327.f90: New test.
Diff:
---
gcc/fortran/expr.c | 7 +++----
gcc/testsuite/gfortran.dg/pr101327.f90 | 11 +++++++++++
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 35563a78697..dfecc3012e1 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1337,7 +1337,9 @@ find_array_element (gfc_constructor_base base, gfc_array_ref *ar,
for (i = 0; i < ar->dimen; i++)
{
if (!gfc_reduce_init_expr (ar->as->lower[i])
- || !gfc_reduce_init_expr (ar->as->upper[i]))
+ || !gfc_reduce_init_expr (ar->as->upper[i])
+ || ar->as->upper[i]->expr_type != EXPR_CONSTANT
+ || ar->as->lower[i]->expr_type != EXPR_CONSTANT)
{
t = false;
cons = NULL;
@@ -1351,9 +1353,6 @@ find_array_element (gfc_constructor_base base, gfc_array_ref *ar,
goto depart;
}
- gcc_assert (ar->as->upper[i]->expr_type == EXPR_CONSTANT
- && ar->as->lower[i]->expr_type == EXPR_CONSTANT);
-
/* Check the bounds. */
if ((ar->as->upper[i]
&& mpz_cmp (e->value.integer,
diff --git a/gcc/testsuite/gfortran.dg/pr101327.f90 b/gcc/testsuite/gfortran.dg/pr101327.f90
new file mode 100644
index 00000000000..f4377aabe7a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr101327.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/101327 - ICE in find_array_element, at fortran/expr.c:1355
+
+subroutine s
+ integer, parameter :: n([2]) = [1, 2] ! { dg-error "must be scalar" }
+ type t
+ integer :: a(n(1):n(2))
+ end type
+end
+
+! { dg-error "cannot be automatic or of deferred shape" " " { target *-*-* } 5 }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-09-07 18:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 18:52 [gcc r12-3392] Fortran - improve error recovery determining array element from constructor Harald Anlauf
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).