[gcc(refs/users/mikael/heads/refactor_descriptor_v206.01)] fortran: array descriptor: Move scalar descriptor init 1/3 [PR122521]
Mikael Morin via Gcc-cvs <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:84e9937bcde0865251751cb4766a7e86ba45dc9f commit 84e9937bcde0865251751cb4766a7e86ba45dc9f Author: Mikael Morin <[email protected]> Date: Wed Jul 29 12:43:53 2026 +0200 fortran: array descriptor: Move scalar descriptor init 1/3 [PR122521] Fortran-tested on aarch64-unknown-linux-gnu. OK for mainline? -- >8 -- The function gfc_conv_class_to_class has some specific code to initialize an array descriptor when it represents a scalar value. Move that code to its own function in trans-descriptor.cc. PR fortran/122521 gcc/fortran/ChangeLog: * trans-expr.cc (gfc_conv_class_to_class): Move descriptor initialization... * trans-descriptor.cc (gfc_set_descriptor_from_scalar_class): ... here as a new function. * trans-descriptor.h (gfc_set_descriptor_from_scalar_class): New declaration. Diff: --- gcc/fortran/trans-descriptor.cc | 17 +++++++++++++++++ gcc/fortran/trans-descriptor.h | 2 ++ gcc/fortran/trans-expr.cc | 13 +------------ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 9c273bf10ea9..b2689605b284 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -844,6 +844,23 @@ gfc_create_null_actual_descriptor (stmtblock_t *block, gfc_typespec *ts, } +void +gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr, + tree scalar, gfc_expr *scalar_expr) +{ + tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar), + gfc_expr_attr (scalar_expr)); + gfc_conv_descriptor_dtype_set (block, descr, + gfc_get_dtype (type)); + + tree tmp = gfc_class_data_get (scalar); + if (!POINTER_TYPE_P (TREE_TYPE (tmp))) + tmp = gfc_build_addr_expr (NULL_TREE, tmp); + + gfc_conv_descriptor_data_set (block, descr, tmp); +} + + /* For an array descriptor, get the total number of elements. This is just the product of the extents along from_dim to to_dim. */ diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h index c7f3df02def6..e8bf5ba2ac45 100644 --- a/gcc/fortran/trans-descriptor.h +++ b/gcc/fortran/trans-descriptor.h @@ -73,6 +73,8 @@ tree gfc_create_unallocated_library_result_descriptor (stmtblock_t *, tree, tree gfc_create_null_actual_descriptor (stmtblock_t *, gfc_typespec *, symbol_attribute, int); +void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr *); + tree gfc_conv_descriptor_size (tree, int); tree gfc_conv_descriptor_cosize (tree, int, int); diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index ec25c68fa02b..f59c624dd86b 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -1371,18 +1371,7 @@ gfc_conv_class_to_class (gfc_se *parmse, gfc_expr *e, gfc_typespec class_ts, && e->rank != class_ts.u.derived->components->as->rank) { if (e->rank == 0) - { - tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (parmse->expr), - gfc_expr_attr (e)); - gfc_conv_descriptor_dtype_set (&block, ctree, - gfc_get_dtype (type)); - - tmp = gfc_class_data_get (parmse->expr); - if (!POINTER_TYPE_P (TREE_TYPE (tmp))) - tmp = gfc_build_addr_expr (NULL_TREE, tmp); - - gfc_conv_descriptor_data_set (&block, ctree, tmp); - } + gfc_set_descriptor_from_scalar_class (&block, ctree, parmse->expr, e); else gfc_class_array_data_assign (&block, ctree, parmse->expr, false); }