[gcc(refs/users/mikael/heads/refactor_descriptor_v206.01)] fortran: array descriptor: Simplify scalar dtype initialization [PR122521]
Mikael Morin via Gcc-cvs <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:ec48d0a34f8103c1b6360c68210d2ebe2ff498a4 commit ec48d0a34f8103c1b6360c68210d2ebe2ff498a4 Author: Mikael Morin <[email protected]> Date: Thu Aug 20 11:43:34 2026 +0200 fortran: array descriptor: Simplify scalar dtype initialization [PR122521] Fortran-tested on aarch64-unknown-linux-gnu. OK for mainline? -- >8 -- The function gfc_set_descriptor_from_scalar creates a new scalar descriptor type that is only used as argument to gfc_get_dtype, to get the dtype initialization value. gfc_get_dtype extracts two pieces of information from that descriptor type: the rank, and the element type. As the rank is known to be zero, and the element type was part of the input to create the descriptor type, we can avoid the roundtrip through the descriptor type creation, and use directly the zero rank and the element type. This change does that. It permits the removal of one argument from gfc_set_descriptor_from_scalar. With the call to the descriptor type creation function removed, the pointer unwrapping of the element type the function was doing is removed as well. Add it back to the gfc_set_descriptor_from_scalar code. PR fortran/122521 gcc/fortran/ChangeLog: * trans-descriptor.h (gfc_set_descriptor_from_scalar, gfc_set_descriptor_from_scalar_class): Remove expression argument. * trans-descriptor.cc (gfc_set_descriptor_from_scalar_class): (gfc_set_descriptor_from_scalar): Ditto. Explicitly unwrap element type if it's pointer-typed. Use gfc_get_dtype_rank_type instead of gfc_get_dtype. Remove scalar descriptor type creation. * trans-expr.cc (gfc_conv_derived_to_class, gfc_conv_class_to_class): Update callers. Revert "Retour en arrière partiel" This reverts commit e5227c6660731b31a9da1b61da83f734d9df5e1e. Sauvegarde Correction supplémentaire class_optional_2 PASS Sauvegarde Correction ICE Correction ICE Correction ICE Correction segfault Correction segfault Revert "Correction segfault" This reverts commit 9c0ec50e4b249cde43fe556aff2b4f02e7c21776. Revert "Correction segfault" This reverts commit a2d85db24f94bc62ebdf61c84f8f0ef80dbd6bfd. Revert "Correction ICE" This reverts commit a1b17393126265b381066fe8bf21b9d9dd3e742e. Revert "Correction ICE" This reverts commit 5e9266797d34bff4be305634b571144bc4b2b2ba. Revert "Correction ICE" This reverts commit d3dc8d2c5971ed6d99816534a382efd6c8333dc6. Revert "Sauvegarde" This reverts commit 60713dd792a1b083eac564da1dc13b1fd0998ff7. Revert "Correction supplémentaire class_optional_2 PASS" This reverts commit c4df985b51ce93797d3ef9ab013422a9e4ce370b. Revert "Sauvegarde" This reverts commit d2fcbd441201eb0e450d08ac657b7e2ccbb033d1. Modifs Diff: --- gcc/fortran/trans-descriptor.cc | 23 ++++++++++++----------- gcc/fortran/trans-descriptor.h | 5 ++--- gcc/fortran/trans-expr.cc | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 70e8e703535d..0b6da8d9231c 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -857,14 +857,14 @@ gfc_create_null_actual_descriptor (stmtblock_t *block, gfc_typespec *ts, void gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, - tree scalar, gfc_expr *scalar_expr, - tree cond_presence) + tree scalar, tree cond_presence) { - tree type; - type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar), - gfc_expr_attr (scalar_expr)); + tree scalar_type = TREE_TYPE (scalar); + tree etype = POINTER_TYPE_P (scalar_type) + ? TREE_TYPE (scalar_type) + : scalar_type; gfc_conv_descriptor_dtype_set (block, descr, - gfc_get_dtype (type)); + gfc_get_dtype_rank_type (0, etype)); gfc_copy_coarray_desc_part (block, descr, scalar); if (cond_presence) scalar = build3_loc (input_location, COND_EXPR, @@ -906,13 +906,14 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree scalar) void gfc_set_descriptor_from_scalar_class (stmtblock_t *block, tree descr, - tree scalar, gfc_expr *scalar_expr) + tree scalar) { - tree type = gfc_get_scalar_to_descriptor_type (TREE_TYPE (scalar), - gfc_expr_attr (scalar_expr)); + tree scalar_type = TREE_TYPE (scalar); + tree etype = POINTER_TYPE_P (scalar_type) + ? TREE_TYPE (scalar_type) + : scalar_type; gfc_conv_descriptor_dtype_set (block, descr, - gfc_get_dtype (type)); - + gfc_get_dtype_rank_type (0, etype)); tree tmp = gfc_class_data_get (scalar); if (!POINTER_TYPE_P (TREE_TYPE (tmp))) tmp = gfc_build_addr_expr (NULL_TREE, tmp); diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h index 2ca4e40b4c52..8b342dd7c010 100644 --- a/gcc/fortran/trans-descriptor.h +++ b/gcc/fortran/trans-descriptor.h @@ -73,10 +73,9 @@ 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 (stmtblock_t *, tree, tree, gfc_expr *, - tree); +void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree, tree); void gfc_set_descriptor_from_scalar (stmtblock_t *, tree, tree); -void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree, gfc_expr *); +void gfc_set_descriptor_from_scalar_class (stmtblock_t *, tree, tree); 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 3d12e119dd09..bf7dc9a1bb1a 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -890,7 +890,7 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, gfc_symbol *fsym, /* Scalar to an assumed-rank array. */ if (fsym->ts.u.derived->components->as) gfc_set_descriptor_from_scalar (&parmse->pre, ctree, - parmse->expr, e, cond_optional); + parmse->expr, cond_optional); else { tmp = fold_convert (TREE_TYPE (ctree), parmse->expr); @@ -1318,7 +1318,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) - gfc_set_descriptor_from_scalar_class (&block, ctree, parmse->expr, e); + gfc_set_descriptor_from_scalar_class (&block, ctree, parmse->expr); else gfc_class_array_data_assign (&block, ctree, parmse->expr, false); }