From efbf7392079222ef00db2d39998faf5513055181 Mon Sep 17 00:00:00 2001 From: Linus Koenig Date: Mon, 13 Apr 2020 16:30:44 +0200 Subject: [PATCH] ICE on wrong code [PR94192]. The idea is not have another resolution of a pointer if an error has occurred previously. 2020-04-13 Linus Koenig PR fortran/94192 * resolve.c (resolve_fl_var_and_proc): Set flag "error" to 1 if pointer is found to not have an assumed rank or a deferred shape. * simplify.c (simplify_bound): If an error has been issued for a given pointer, one should not attempt to find its bounds. 2020-04-13 Linus Koenig PR fortran/94192 * gfortran.dg/bound_resolve_after_error_1.f90: New test. --- gcc/fortran/ChangeLog | 8 ++++++++ gcc/fortran/resolve.c | 1 + gcc/fortran/simplify.c | 4 ++++ gcc/testsuite/ChangeLog | 5 +++++ .../gfortran.dg/bound_resolve_after_error_1.f90 | 13 +++++++++++++ 5 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/bound_resolve_after_error_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e2ebb96d799..96835dea4bf 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2020-04-13 Linus Koenig + + PR fortran/94192 + * resolve.c (resolve_fl_var_and_proc): Set flag "error" to 1 if + pointer is found to not have an assumed rank or a deferred shape. + * simplify.c (simplify_bound): If an error has been issued for a + given pointer, one should not attempt to find its bounds. + 2020-04-09 Fritz Reese PR fortran/87923 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index ccd2a5e3b7d..9b95200c241 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -12622,6 +12622,7 @@ resolve_fl_var_and_proc (gfc_symbol *sym, int mp_flag) { gfc_error ("Array pointer %qs at %L must have a deferred shape or " "assumed rank", sym->name, &sym->declared_at); + sym->error = 1; return false; } } diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index f63f63c9ef6..807565b4e80 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4159,6 +4159,10 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) gfc_array_spec *as; int d; + /* Do not attempt to resolve if error has already been issued. */ + if (array->symtree && array->symtree->n.sym->error) + return NULL; + if (array->ts.type == BT_CLASS) return NULL; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9f644531306..3c3352f5c8b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-13 Linus Koenig + + PR fortran/94192 + * gfortran.dg/bound_resolve_after_error_1.f90: New test. + 2020-04-13 Nathan Sidwell PR c++/94426 diff --git a/gcc/testsuite/gfortran.dg/bound_resolve_after_error_1.f90 b/gcc/testsuite/gfortran.dg/bound_resolve_after_error_1.f90 new file mode 100644 index 00000000000..35cc2405a8d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bound_resolve_after_error_1.f90 @@ -0,0 +1,13 @@ +! Testcase for bound check after issued error +! See PR 94192 +! { dg-do compile } +program bound_for_illegal + +contains + + subroutine bnds(a) ! { dg-error "must have a deferred shape or assumed rank" } + integer, pointer, intent(in) :: a(1:2) + print *,lbound(a) + end subroutine bnds + +end program bound_for_illegal -- 2.30.2