Fortran: fix error recovery on invalid array section

gcc/fortran/ChangeLog:

	PR fortran/105230
	* expr.c (find_array_section): Correct logic to avoid NULL
	pointer dereference on invalid array section.

gcc/testsuite/ChangeLog:

	PR fortran/105230
	* gfortran.dg/pr105230.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
(cherry picked from commit 0acdbe29f6)
This commit is contained in:
Harald Anlauf 2022-05-10 23:41:57 +02:00
parent 6b8cd1fb40
commit a9717558aa
2 changed files with 10 additions and 2 deletions

View File

@ -1553,8 +1553,8 @@ 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)
|| (!begin && !lower)
|| (!finish && !upper))
|| !lower
|| !upper)
{
t = false;
goto cleanup;

View File

@ -0,0 +1,8 @@
! { dg-do compile }
! PR fortran/105230 - ICE in find_array_section
! Contributed by G.Steinmetz
program p
integer, parameter :: a(:) = [1, 2] ! { dg-error "deferred shape" }
print *, reshape([3, 4], a(1:2))
end