Fortran: fix checking of arguments to UNPACK when MASK is a variable [PR105813]

gcc/fortran/ChangeLog:

	PR fortran/105813
	* check.cc (gfc_check_unpack): Try to simplify MASK argument to
	UNPACK so that checking of the VECTOR argument can work when MASK
	is a variable.

gcc/testsuite/ChangeLog:

	PR fortran/105813
	* gfortran.dg/unpack_vector_1.f90: New test.

(cherry picked from commit f21f17f95c)
This commit is contained in:
Harald Anlauf 2022-06-24 22:21:39 +02:00
parent 5cf7ffe3be
commit eb4336f546
2 changed files with 14 additions and 0 deletions

View File

@ -6353,6 +6353,8 @@ gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
if (!same_type_check (vector, 0, field, 2))
return false;
gfc_simplify_expr (mask, 0);
if (mask->expr_type == EXPR_ARRAY
&& gfc_array_size (vector, &vector_size))
{

View File

@ -0,0 +1,12 @@
! { dg-do compile }
! PR fortran/105813
! Fix checking of VECTOR argument to UNPACK when MASK is a variable.
! Contributed by G.Steinmetz
program p
logical, parameter :: mask(2,2) = reshape ([.true., .true., &
.false., .true.], &
shape (mask))
print *, unpack ([1,2,3], mask, 0) ! OK
print *, unpack ([1,2], mask, 0) ! { dg-error "must provide at least" }
end