From 2a1537a19cb2fa85823cfa18ed40baa4b259b4e3 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 7 Sep 2021 20:51:49 +0200 Subject: [PATCH] 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. --- gcc/fortran/expr.c | 7 +++---- gcc/testsuite/gfortran.dg/pr101327.f90 | 11 +++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr101327.f90 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 35563a7..dfecc30 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 0000000..f4377aa --- /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 } -- 2.7.4