Dear all, the fix for this ICE is obvious: make gfc_call_malloc behave as documented. Apparently the special case in question was not exercised in the testsuite.
Regtested on x86_64-pc-linux-gnu. OK for master / backports? Should the testcase be moved to the gomp/ subdirectory? Thanks, Harald 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/pr86470.f90: New test.
diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c index a2376917635..ab53fc5f441 100644 --- a/gcc/fortran/trans.c +++ b/gcc/fortran/trans.c @@ -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)); diff --git a/gcc/testsuite/gfortran.dg/pr86470.f90 b/gcc/testsuite/gfortran.dg/pr86470.f90 new file mode 100644 index 00000000000..4021e5d655c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr86470.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! { dg-options "-fopenmp" } +! 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