diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 35bc953c9b4c..40ba659f9701 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -1025,9 +1025,15 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, gfc_ss * ss, if (eltype && GFC_CLASS_TYPE_P (eltype)) eltype = gfc_get_element_type (TREE_TYPE (TYPE_FIELDS (eltype))); - if (class_expr == NULL_TREE) + if (class_expr == NULL_TREE + && TYPE_SIZE_UNIT (eltype) != NULL_TREE) elemsize = fold_convert (gfc_array_index_type, TYPE_SIZE_UNIT (eltype)); + else if (class_expr == NULL_TREE) + { + gcc_assert (callee_alloc); + elemsize = NULL_TREE; + } else { /* Unlimited polymorphic entities are initialised with NULL vptr. They diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 2016b360eee7..894c9ff2dace 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -2921,7 +2921,8 @@ gfc_set_temporary_descriptor (stmtblock_t *block, tree descr, tree class_src, ubound[n], stride[n], &offset); } - gfc_conv_descriptor_span_set (block, descr, elemsize); + if (elemsize != NULL_TREE) + gfc_conv_descriptor_span_set (block, descr, elemsize); gfc_conv_descriptor_offset_set (block, descr, offset);