From: Harald Anlauf Date: Tue, 7 Sep 2021 18:51:49 +0000 (+0200) Subject: Fortran - improve error recovery determining array element from constructor X-Git-Tag: basepoints/gcc-13~4921 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a1537a19cb2fa85823cfa18ed40baa4b259b4e3;p=thirdparty%2Fgcc.git 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 --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 35563a78697f..dfecc3012e19 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 000000000000..f4377aabe7a3 --- /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 }