[gcc(refs/users/mikael/heads/refactor_descriptor_v206.01)] fortran: array descriptor: Factor scalar descriptor init 1/2 [PR122521]
Mikael Morin via Gcc-cvs <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:c80bcc0191b550fe8e553f86fac81b503c45878d commit c80bcc0191b550fe8e553f86fac81b503c45878d Author: Mikael Morin <[email protected]> Date: Mon Aug 10 21:44:32 2026 +0200 fortran: array descriptor: Factor scalar descriptor init 1/2 [PR122521] TODO: FAIL unlimited_polymorphic_{1,32}.f03, intent_out_19.f90, associate_66.f90 -- >8 -- The two functions gfc_set_descriptor_from_scalar and gfc_set_descriptor_from_scalar_class have very similar code, except only the former has support for coarrays and absent optional variables, whereas only the latter has code to take the address if the scalar value isn't pointer-typed. Add the missing address taking to gfc_set_descriptor_from_scalar and make gfc_set_descriptor_from_scalar_class call it. PR fortran/122521 gcc/fortran/ChangeLog: * trans-descriptor.cc (gfc_set_descriptor_from_scalar): Take the address of the value if it's not a pointer. (gfc_set_descriptor_from_scalar_class): Replace inline code with a call to gfc_set_descriptor_from_scalar. Diff: --- gcc/fortran/trans-descriptor.cc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 3c832d2c56a0..f12e4733c6fd 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -858,6 +858,8 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, gfc_conv_descriptor_dtype_set (block, descr, gfc_get_dtype (type)); gfc_copy_coarray_desc_part (block, descr, scalar); + if (!POINTER_TYPE_P (TREE_TYPE (scalar))) + scalar = gfc_build_addr_expr (NULL_TREE, scalar); if (cond_presence) scalar = build3_loc (input_location, COND_EXPR, TREE_TYPE (scalar), @@ -889,16 +891,9 @@ 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); + gfc_set_descriptor_from_scalar (block, descr, tmp, scalar_expr, NULL_TREE, + NULL_TREE); }