Fortran: MOLD argument to TRANSFER intrinsic having storage size zero

gcc/fortran/ChangeLog:

	PR fortran/104227
	* check.cc (gfc_calculate_transfer_sizes): Fix checking of arrays
	passed as MOLD argument to the TRANSFER intrinsic for having
	storage size zero.

gcc/testsuite/ChangeLog:

	PR fortran/104227
	* gfortran.dg/transfer_check_6.f90: New test.
This commit is contained in:
Harald Anlauf 2022-01-25 21:56:39 +01:00
parent 34e8dafb76
commit ec543c9833
2 changed files with 12 additions and 1 deletions

View file

@ -6151,7 +6151,7 @@ gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
* If SIZE is present, the result is an array of rank one and size SIZE.
*/
if (result_elt_size == 0 && *source_size > 0 && !size
&& mold->expr_type == EXPR_ARRAY)
&& (mold->expr_type == EXPR_ARRAY || mold->rank))
{
gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L is an "
"array and shall not have storage size 0 when %<SOURCE%> "

View file

@ -0,0 +1,11 @@
! { dg-do compile }
! PR fortran/104227 - ICE virtual memory exhausted
! Contributed by G.Steinmetz
program p
type t
end type
type(t) :: x(2)
print *, transfer(1, x) ! { dg-error "shall not have storage size 0" }
x = transfer(1, x) ! { dg-error "shall not have storage size 0" }
end