PR fortran/86470 - ICE with OpenMP, class(*) allocatable

gfc_call_malloc should malloc an area of size 1 if no size given.

gcc/fortran/ChangeLog:

	PR fortran/86470
	* trans.c (gfc_call_malloc): Allocate area of size 1 if passed
	size is NULL (as documented).

gcc/testsuite/ChangeLog:

	PR fortran/86470
	* gfortran.dg/gomp/pr86470.f90: New test.
This commit is contained in:
Harald Anlauf 2021-01-28 10:13:46 +01:00
parent c392d040f6
commit 33a7a93218
2 changed files with 15 additions and 0 deletions

View file

@ -689,6 +689,9 @@ gfc_call_malloc (stmtblock_t * block, tree type, tree size)
/* Call malloc. */
gfc_start_block (&block2);
if (size == NULL_TREE)
size = build_int_cst (size_type_node, 1);
size = fold_convert (size_type_node, size);
size = fold_build2_loc (input_location, MAX_EXPR, size_type_node, size,
build_int_cst (size_type_node, 1));

View file

@ -0,0 +1,12 @@
! { dg-do compile }
! PR fortran/86470 - ICE with OpenMP, class(*)
program p
implicit none
class(*), allocatable :: val
!$OMP PARALLEL private(val)
allocate(integer::val)
val = 1
deallocate(val)
!$OMP END PARALLEL
end