https://gcc.gnu.org/g:78513360584874d7d4e81586ae0583da8c51bb0c
commit 78513360584874d7d4e81586ae0583da8c51bb0c Author: Mikael Morin <mik...@gcc.gnu.org> Date: Wed Aug 6 22:08:03 2025 +0200 Extraction gfc_conv_null_array_to_descriptor Diff: --- gcc/fortran/trans-descriptor.cc | 32 ++++++++++++++++++++++++++++++++ gcc/fortran/trans-descriptor.h | 1 + gcc/fortran/trans-expr.cc | 8 ++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 4f781f4976f7..5a3c38460d9d 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -858,6 +858,37 @@ gfc_nullify_descriptor (stmtblock_t *block, gfc_expr *expr, tree descr, } +tree +gfc_conv_null_array_to_descriptor (stmtblock_t *block, gfc_symbol *fsym) +{ + symbol_attribute attr = gfc_symbol_attr (fsym); + + enum gfc_array_kind akind; + + if (attr.pointer) + akind = GFC_ARRAY_POINTER_CONT; + else if (attr.allocatable) + akind = GFC_ARRAY_ALLOCATABLE; + else + akind = GFC_ARRAY_ASSUMED_SHAPE_CONT; + + tree etype = gfc_typenode_for_spec (&fsym->ts); + tree desc_type = gfc_get_array_type_bounds (etype, 1, 0, NULL, NULL, 1, + akind, !(attr.pointer || attr.target)); + + tree desc = gfc_create_var (desc_type, "desc"); + DECL_ARTIFICIAL (desc) = 1; + + int rank = fsym->as ? fsym->as->rank : 0; + gfc_conv_descriptor_dtype_set (block, desc, + gfc_get_dtype_rank_type (rank, etype)); + gfc_conv_descriptor_data_set (block, desc, null_pointer_node); + gfc_conv_descriptor_span_set (block, desc, + gfc_conv_descriptor_elem_len_get (desc)); + + return desc; +} + /* Modify a descriptor such that the lbound of a given dimension is the value specified. This also updates ubound and offset accordingly. */ @@ -2713,3 +2744,4 @@ gfc_set_empty_descriptor_bounds (stmtblock_t *block, tree descr, int rank) gfc_conv_descriptor_offset_set (block, descr, gfc_index_zero_node); } + diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h index e9724c052437..067913e81770 100644 --- a/gcc/fortran/trans-descriptor.h +++ b/gcc/fortran/trans-descriptor.h @@ -96,6 +96,7 @@ void gfc_conv_shift_descriptor (stmtblock_t *, tree, int); void gfc_conv_shift_descriptor (stmtblock_t *, tree, const gfc_array_ref &); /* Build a null array descriptor constructor. */ void gfc_nullify_descriptor (stmtblock_t *block, tree); +tree gfc_conv_null_array_to_descriptor (stmtblock_t *, gfc_symbol *); void gfc_copy_sequence_descriptor (stmtblock_t *, tree, tree, int); void gfc_conv_remap_descriptor (stmtblock_t *, tree, int, tree, int, gfc_array_ref *); diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 5cd936824452..e810bc755115 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6536,11 +6536,11 @@ conv_null_actual (gfc_se * parmse, gfc_expr * e, gfc_symbol * fsym) if ((fsym->attr.allocatable || fsym->attr.pointer) && fsym->attr.intent == INTENT_UNKNOWN) fsym->attr.intent = INTENT_IN; - tmp = gfc_conv_scalar_to_descriptor (parmse, tmp, fsym->attr); dummy_rank = fsym->as ? fsym->as->rank : 0; - if (dummy_rank > 0) - gfc_conv_descriptor_rank_set (&parmse->pre, tmp, dummy_rank); - gfc_conv_descriptor_data_set (&parmse->pre, tmp, null_pointer_node); + if (dummy_rank == 0) + tmp = gfc_conv_scalar_to_descriptor (parmse, tmp, fsym->attr); + else + tmp = gfc_conv_null_array_to_descriptor (&parmse->pre, fsym); parmse->expr = gfc_build_addr_expr (NULL_TREE, tmp); } }