Fortran: fix error recovery for invalid constructor

gcc/fortran/ChangeLog:

	PR fortran/102520
	* array.c (expand_constructor): Do not dereference NULL pointer.

gcc/testsuite/ChangeLog:

	PR fortran/102520
	* gfortran.dg/pr102520.f90: New test.
This commit is contained in:
Harald Anlauf 2021-09-29 20:11:53 +02:00
parent a672a22582
commit 5e2adfeed2
2 changed files with 15 additions and 0 deletions

View file

@ -1798,6 +1798,9 @@ expand_constructor (gfc_constructor_base base)
e = c->expr;
if (e == NULL)
return false;
if (empty_constructor)
empty_ts = e->ts;

View file

@ -0,0 +1,12 @@
! { dg-do compile }
! PR fortran/102520 - ICE in expand_constructor, at fortran/array.c:1802
program p
type t
end type
type(t), parameter :: a(4) = shape(1) ! { dg-error "Incompatible" }
type(t), parameter :: b(2,2) = reshape(a,[2,2]) ! { dg-error "Incompatible" }
type(t), parameter :: c(2,2) = transpose(b) ! { dg-error "Unclassifiable" }
end
! { dg-error "Different shape for array assignment" " " { target *-*-* } 7 }