Fortran: error recovery while simplifying intrinsic UNPACK [PR107054]

gcc/fortran/ChangeLog:

	PR fortran/107054
	* simplify.cc (gfc_simplify_unpack): Replace assert by condition
	that terminates simplification when there are not enough elements
	in the constructor of argument VECTOR.

gcc/testsuite/ChangeLog:

	PR fortran/107054
	* gfortran.dg/pr107054.f90: New test.
This commit is contained in:
Harald Anlauf 2022-09-27 20:54:28 +02:00
parent e73d9fcafb
commit 78bc6497fc
2 changed files with 23 additions and 3 deletions

View file

@ -8458,9 +8458,16 @@ gfc_simplify_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
{
if (mask_ctor->expr->value.logical)
{
gcc_assert (vector_ctor);
e = gfc_copy_expr (vector_ctor->expr);
vector_ctor = gfc_constructor_next (vector_ctor);
if (vector_ctor)
{
e = gfc_copy_expr (vector_ctor->expr);
vector_ctor = gfc_constructor_next (vector_ctor);
}
else
{
gfc_free_expr (result);
return NULL;
}
}
else if (field->expr_type == EXPR_ARRAY)
e = gfc_copy_expr (field_ctor->expr);

View file

@ -0,0 +1,13 @@
! { dg-do compile }
! PR fortran/107054 - ICE in gfc_simplify_unpack
! Contributed by G.Steinmetz
program p
type t
integer :: n = 0
end type
type(t), parameter :: a(4) = t(2)
type(t), parameter :: b(4) = reshape(a,[2]) ! { dg-error "Different shape" }
type(t), parameter :: c(2) = pack(b,[.false.,.true.,.false.,.true.]) ! { dg-error "Different shape" }
type(t), parameter :: d(4) = unpack(c,[.false.,.true.,.false.,.true.],a)
end