From: Mikael Morin <[email protected]>
Fortran-tested on x86_64-pc-linux-gnu. OK for mainline?
-- >8 --
Factor to a common function the identical scalar descriptor initialization
parts between gfc_set_descriptor_from_scalar_class and
gfc_set_descriptor_from_scalar. The new function is mostly copied from
gfc_set_descriptor_from_scalar, with an extra type argument from which the
dtype initialization values are built. Only the cobounds copy remains out
of the factored function.
PR fortran/122521
gcc/fortran/ChangeLog:
* trans-descriptor.cc (gfc_set_descriptor_from_scalar_class,
gfc_set_descriptor_from_scalar): Factor common code...
(set_descriptor_from_scalar): ... to this new function.
---
gcc/fortran/trans-descriptor.cc | 38 ++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 743f2668e50..c77fda84e47 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -854,6 +854,28 @@ gfc_create_null_actual_descriptor (stmtblock_t *block,
gfc_typespec *ts,
}
+/* Add code to BLOCK initializing the zero-rank array descriptor DESCR. Guess
+ the dtype field initialization values using TYPE. If COND_PRESENCE is set,
+ make the value assigned to the data field either SCALAR or nullptr depending
+ on COND_PRESENCE; otherwise SCALAR unconditionally. */
+
+static void
+set_descriptor_from_scalar (stmtblock_t *block, tree descr, tree type,
+ tree scalar, tree cond_presence)
+{
+ gfc_conv_descriptor_dtype_set (block, descr,
+ gfc_get_dtype_rank_type (0, type));
+
+ if (cond_presence)
+ scalar = build3_loc (input_location, COND_EXPR,
+ TREE_TYPE (scalar),
+ cond_presence, scalar,
+ fold_convert (TREE_TYPE (scalar),
+ null_pointer_node));
+ gfc_conv_descriptor_data_set (block, descr, scalar);
+}
+
+
/* Add code to BLOCK initializing the zero-rank array descriptor DESCR, so that
it represents the same data as the pointer-typed middle-end expression
SCALAR
corresponding to the scalar front-end expression SCALAR_EXPR. If
@@ -870,17 +892,8 @@ gfc_set_descriptor_from_scalar (stmtblock_t *block, tree
descr,
tree etype = POINTER_TYPE_P (scalar_type)
? TREE_TYPE (scalar_type)
: scalar_type;
- gfc_conv_descriptor_dtype_set (block, descr,
- gfc_get_dtype_rank_type (0, etype));
-
+ set_descriptor_from_scalar (block, descr, etype, scalar, cond_presence);
gfc_copy_coarray_desc_part (block, descr, scalar);
- if (cond_presence)
- scalar = build3_loc (input_location, COND_EXPR,
- TREE_TYPE (scalar),
- cond_presence, scalar,
- fold_convert (TREE_TYPE (scalar),
- null_pointer_node));
- gfc_conv_descriptor_data_set (block, descr, scalar);
}
@@ -995,14 +1008,13 @@ gfc_set_descriptor_from_scalar_class (stmtblock_t
*block, tree descr,
tree val_ptr = nullptr;
bool is_class = is_polymorphic_ref (scalar, &class_ref, &val_ptr);
gcc_checking_assert (is_class);
- tree dtype_val = gfc_get_dtype_rank_type (0, TREE_TYPE (class_ref));
- gfc_conv_descriptor_dtype_set (block, descr, dtype_val);
tree tmp = val_ptr;
if (!POINTER_TYPE_P (TREE_TYPE (tmp)))
tmp = gfc_build_addr_expr (NULL_TREE, tmp);
- gfc_conv_descriptor_data_set (block, descr, tmp);
+ set_descriptor_from_scalar (block, descr, TREE_TYPE (class_ref), tmp,
+ NULL_TREE);
}
--
2.53.0