https://gcc.gnu.org/g:89ee81befb324ed105ba40de81348c2128d81f68
commit 89ee81befb324ed105ba40de81348c2128d81f68 Author: Mikael Morin <mik...@gcc.gnu.org> Date: Mon Mar 31 12:05:26 2025 +0200 Replace span with elem_len Correction ISO_Fortran_binding_3.f90 Diff: --- gcc/fortran/trans-array.cc | 4 +- gcc/fortran/trans-descriptor.cc | 112 +++++++----------------------- gcc/fortran/trans-descriptor.h | 1 - gcc/fortran/trans-intrinsic.cc | 6 +- gcc/fortran/trans-openmp.cc | 6 +- gcc/fortran/trans-types.cc | 17 ++--- gcc/fortran/trans.cc | 8 +-- libgfortran/caf/single.c | 2 +- libgfortran/intrinsics/associated.c | 2 - libgfortran/libgfortran.h | 3 - libgfortran/runtime/ISO_Fortran_binding.c | 9 +-- 11 files changed, 45 insertions(+), 125 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 595ba97aa8ca..a48d0f4b8a4a 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -450,7 +450,7 @@ gfc_get_array_span (tree desc, gfc_expr *expr) desc = build_fold_indirect_ref_loc (input_location, desc); /* This will have the span field set. */ - tmp = gfc_conv_descriptor_span_get (desc); + tmp = gfc_conv_descriptor_elem_len_get (desc); } else if (expr->ts.type == BT_ASSUMED) { @@ -458,7 +458,7 @@ gfc_get_array_span (tree desc, gfc_expr *expr) desc = GFC_DECL_SAVED_DESCRIPTOR (desc); if (POINTER_TYPE_P (TREE_TYPE (desc))) desc = build_fold_indirect_ref_loc (input_location, desc); - tmp = gfc_conv_descriptor_span_get (desc); + tmp = gfc_conv_descriptor_elem_len_get (desc); } else if (TREE_CODE (desc) == COMPONENT_REF && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)) diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 7e709609435c..2bc47f646bbb 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -164,9 +164,8 @@ gfc_get_cfi_dim_sm (tree desc, tree idx) #define DATA_FIELD 0 #define OFFSET_FIELD 1 #define DTYPE_FIELD 2 -#define SPAN_FIELD 3 -#define DIMENSION_FIELD 4 -#define CAF_TOKEN_FIELD 5 +#define DIMENSION_FIELD 3 +#define CAF_TOKEN_FIELD 4 #define STRIDE_SUBFIELD 0 #define LBOUND_SUBFIELD 1 @@ -282,27 +281,6 @@ conv_dtype_set (stmtblock_t *block, tree desc, tree val) gfc_add_modify (block, t, val); } -tree -get_span (tree desc) -{ - tree field = get_component (desc, SPAN_FIELD); - gcc_assert (TREE_TYPE (field) == gfc_array_index_type); - return field; -} - -tree -conv_span_get (tree desc) -{ - return non_lvalue_loc (input_location, get_span (desc)); -} - -void -conv_span_set (stmtblock_t *block, tree desc, tree value) -{ - tree t = get_span (desc); - gfc_add_modify (block, t, fold_convert (TREE_TYPE (t), value)); -} - tree get_rank (tree desc) { @@ -715,18 +693,6 @@ gfc_conv_descriptor_dtype_set (stmtblock_t *block, tree desc, tree val) gfc_descriptor::conv_dtype_set (block, desc, val); } -tree -gfc_conv_descriptor_span_get (tree desc) -{ - return gfc_descriptor::conv_span_get (desc); -} - -static void -gfc_conv_descriptor_span_set (stmtblock_t *block, tree desc, tree value) -{ - return gfc_descriptor::conv_span_set (block, desc, value); -} - tree gfc_conv_descriptor_dimension_get (tree desc, tree dim) { @@ -932,10 +898,11 @@ tree gfc_conv_descriptor_sm_get (tree desc, tree dim) { tree stride = gfc_conv_descriptor_stride_get (desc, dim); - tree span = gfc_conv_descriptor_span_get (desc); + tree elem_len = gfc_conv_descriptor_elem_len_get (desc); + elem_len = fold_convert (gfc_array_index_type, elem_len); return fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, - stride, span); + stride, elem_len); } @@ -1111,31 +1078,6 @@ get_descr_data_value (const descr_change_info &info) } -static tree -get_descr_span (const descr_change_info &info) -{ - switch (info.type) - { - case UNKNOWN_CHANGE: - case EXPLICIT_NULLIFICATION: - case INITIALISATION: - case DEFAULT_INITIALISATION: - case NULL_INITIALISATION: - return NULL_TREE; - - case SCALAR_VALUE: - { - tree fields = TYPE_FIELDS (info.descriptor_type); - tree span_field = gfc_advance_chain (fields, SPAN_FIELD); - return build_zero_cst (TREE_TYPE (span_field)); - } - - default: - gcc_unreachable (); - } -} - - static tree get_descr_caf_token (const descr_change_info &info) { @@ -1357,14 +1299,6 @@ get_descriptor_init (tree type, gfc_typespec *ts, int rank, CONSTRUCTOR_APPEND_ELT (v, dtype_field, dtype_value); } - tree span_value = get_descr_span (change); - if (span_value != NULL_TREE) - { - tree span_field = gfc_advance_chain (fields, SPAN_FIELD); - tree span_value = build_zero_cst (TREE_TYPE (span_field)); - CONSTRUCTOR_APPEND_ELT (v, span_field, span_value); - } - if (flag_coarray == GFC_FCOARRAY_LIB && attr->codimension) { tree caf_token = get_descr_caf_token (change); @@ -2366,14 +2300,14 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src, tree span; if (VAR_P (src) && GFC_DECL_PTR_ARRAY_P (src)) - span = gfc_conv_descriptor_span_get (src); + span = gfc_conv_descriptor_elem_len_get (src); else { tmp = TREE_TYPE (src); tmp = TYPE_SIZE_UNIT (gfc_get_element_type (tmp)); span = fold_convert (gfc_array_index_type, tmp); } - gfc_conv_descriptor_span_set (block, dest, span); + gfc_conv_descriptor_elem_len_set (block, dest, span); /* Copy offset but adjust it such that it would correspond to a lbound of zero. */ @@ -2472,10 +2406,10 @@ gfc_copy_descriptor (stmtblock_t *block, tree dest, tree src, /* ....and set the span field. */ tree tmp2; if (src_expr->ts.type == BT_CHARACTER) - tmp2 = gfc_conv_descriptor_span_get (src); + tmp2 = gfc_conv_descriptor_elem_len_get (src); else tmp2 = gfc_get_array_span (src, src_expr); - gfc_conv_descriptor_span_set (block, dest, tmp2); + gfc_conv_descriptor_elem_len_set (block, dest, tmp2); } @@ -2487,7 +2421,7 @@ gfc_set_descriptor_with_shape (stmtblock_t *block, tree desc, /* Set the span field. */ tree tmp = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc))); tmp = fold_convert (gfc_array_index_type, tmp); - gfc_conv_descriptor_span_set (block, desc, tmp); + gfc_conv_descriptor_elem_len_set (block, desc, tmp); /* Set data value, dtype, and offset. */ tmp = GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (desc)); @@ -2610,8 +2544,8 @@ gfc_copy_sequence_descriptor (stmtblock_t &block, tree lhs_desc, tree rhs_desc, gfc_conv_descriptor_dtype_get (rhs_desc)); tree rank_value = build_int_cst (signed_char_type_node, lhs_rank); gfc_conv_descriptor_rank_set (&block, arr, rank_value); - gfc_conv_descriptor_span_set (&block, arr, - gfc_conv_descriptor_span_get (arr)); + gfc_conv_descriptor_elem_len_set (&block, arr, + gfc_conv_descriptor_elem_len_get (arr)); gfc_conv_descriptor_offset_set (&block, arr, gfc_index_zero_node); desc = arr; } @@ -2764,7 +2698,7 @@ gfc_set_gfc_from_cfi (stmtblock_t *unconditional_block, tmp = build3_loc (input_location, COND_EXPR, gfc_array_index_type, tmp, sm0, elem_len); } - gfc_conv_descriptor_span_set (conditional_block, gfc, tmp); + gfc_conv_descriptor_elem_len_set (conditional_block, gfc, tmp); /* Calculate offset + set lbound, ubound and stride. */ gfc_conv_descriptor_offset_set (conditional_block, gfc, gfc_index_zero_node); @@ -2856,7 +2790,7 @@ gfc_set_gfc_from_cfi (stmtblock_t *unconditional_block, void gfc_get_descriptor_offsets_for_info (const_tree desc_type, tree *data_off, - tree *dtype_off, tree *span_off, + tree *dtype_off, tree *elem_len_off, tree *dim_off, tree *dim_size, tree *stride_suboff, tree *lower_suboff, tree *upper_suboff) @@ -2869,8 +2803,11 @@ gfc_get_descriptor_offsets_for_info (const_tree desc_type, tree *data_off, *data_off = byte_position (field); field = gfc_advance_chain (TYPE_FIELDS (type), DTYPE_FIELD); *dtype_off = byte_position (field); - field = gfc_advance_chain (TYPE_FIELDS (type), SPAN_FIELD); - *span_off = byte_position (field); + field = gfc_advance_chain (TYPE_FIELDS (TREE_TYPE (field)), + GFC_DTYPE_ELEM_LEN); + *elem_len_off = fold_build2 (PLUS_EXPR, size_type_node, + fold_convert (size_type_node, *dtype_off), + fold_convert (size_type_node, byte_position (field))); field = gfc_advance_chain (TYPE_FIELDS (type), DIMENSION_FIELD); *dim_off = byte_position (field); type = TREE_TYPE (TREE_TYPE (field)); @@ -2889,7 +2826,6 @@ gfc_get_descriptor_offsets_for_info (const_tree desc_type, tree *data_off, #undef DATA_FIELD #undef OFFSET_FIELD #undef DTYPE_FIELD -#undef SPAN_FIELD #undef DIMENSION_FIELD #undef CAF_TOKEN_FIELD #undef STRIDE_SUBFIELD @@ -2941,7 +2877,7 @@ gfc_set_temporary_descriptor (stmtblock_t *block, tree desc, tree class_src, } } - gfc_conv_descriptor_span_set (block, desc, elemsize); + gfc_conv_descriptor_elem_len_set (block, desc, elemsize); gfc_conv_descriptor_data_set (block, desc, data_ptr); @@ -3014,11 +2950,11 @@ gfc_set_descriptor (stmtblock_t *block, tree dest, tree src, gfc_expr *src_expr, /* Set the span field. */ tree tmp = NULL_TREE; if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (src))) - tmp = gfc_conv_descriptor_span_get (src); + tmp = gfc_conv_descriptor_elem_len_get (src); else tmp = gfc_get_array_span (src, src_expr); if (tmp) - gfc_conv_descriptor_span_set (block, dest, tmp); + gfc_conv_descriptor_elem_len_set (block, dest, tmp); /* The following can be somewhat confusing. We have two descriptors, a new one and the original array. @@ -3439,7 +3375,7 @@ gfc_descr_init_count (tree descriptor, int rank, int corank, gfc_expr ** lower, offset = gfc_evaluate_now (offset, pblock); gfc_conv_descriptor_offset_set (descriptor_block, descriptor, offset); tmp = fold_convert (gfc_array_index_type, element_size); - gfc_conv_descriptor_span_set (descriptor_block, descriptor, tmp); + gfc_conv_descriptor_elem_len_set (descriptor_block, descriptor, tmp); return gfc_evaluate_now (stride, pblock); } @@ -3731,7 +3667,7 @@ gfc_set_descriptor_for_assign_realloc (stmtblock_t *block, gfc_loopinfo *loop, gfc_conv_descriptor_offset_set (block, desc, offset); if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc))) - gfc_conv_descriptor_span_set (block, desc, elemsize2); + gfc_conv_descriptor_elem_len_set (block, desc, elemsize2); /* For deferred character length, the 'size' field of the dtype might have changed so set the dtype. */ diff --git a/gcc/fortran/trans-descriptor.h b/gcc/fortran/trans-descriptor.h index b991d2a41895..0b95a90e05ed 100644 --- a/gcc/fortran/trans-descriptor.h +++ b/gcc/fortran/trans-descriptor.h @@ -40,7 +40,6 @@ void gfc_copy_descriptor (stmtblock_t *block, tree dest, tree src, tree gfc_conv_descriptor_data_get (tree); tree gfc_conv_descriptor_offset_get (tree); -tree gfc_conv_descriptor_span_get (tree); tree gfc_conv_descriptor_dtype_get (tree); tree gfc_conv_descriptor_rank_get (tree); tree gfc_conv_descriptor_elem_len_get (tree); diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc index f226f1b5f038..7c3fd4faaa40 100644 --- a/gcc/fortran/trans-intrinsic.cc +++ b/gcc/fortran/trans-intrinsic.cc @@ -1307,7 +1307,7 @@ gfc_conv_intrinsic_caf_get (gfc_se *se, gfc_expr *expr, tree lhs, : gfc_conv_descriptor_size (res_var, array_expr->rank)), fold_convert (size_type_node, - gfc_conv_descriptor_span_get (res_var))); + gfc_conv_descriptor_elem_len_get (res_var))); } opt_dest_desc = res_var; dest_data = gfc_conv_descriptor_data_get (res_var); @@ -1534,7 +1534,7 @@ conv_caf_send_to_remote (gfc_code *code) : gfc_conv_descriptor_size (rhs_se.expr, rhs_expr->rank)), fold_convert (size_type_node, - gfc_conv_descriptor_span_get (rhs_se.expr))); + gfc_conv_descriptor_elem_len_get (rhs_se.expr))); } rhs_data = gfc_build_addr_expr ( @@ -1759,7 +1759,7 @@ conv_caf_sendget (gfc_code *code) : gfc_conv_descriptor_size (rhs_se.expr, rhs_expr->rank)), fold_convert (size_type_node, - gfc_conv_descriptor_span_get (rhs_se.expr))); + gfc_conv_descriptor_elem_len_get (rhs_se.expr))); } opt_rhs_desc = gfc_build_addr_expr (NULL_TREE, opt_rhs_desc); diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 4ac7ea0893c1..43c98db9e0fd 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -785,7 +785,7 @@ gfc_omp_clause_default_ctor (tree clause, tree decl, tree outer) gfc_conv_descriptor_sm_get (decl, rank)); else { - tree esize = gfc_conv_descriptor_span_get (decl); + tree esize = gfc_conv_descriptor_elem_len_get (decl); esize = fold_convert_loc (input_location, gfc_array_index_type, esize); size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, size, esize); @@ -974,7 +974,7 @@ gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src) gfc_conv_descriptor_sm_get (dest, rank)); else { - tree esize = gfc_conv_descriptor_span_get (dest); + tree esize = gfc_conv_descriptor_elem_len_get (dest); esize = fold_convert_loc (input_location, gfc_array_index_type, esize); size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, size, esize); @@ -1095,7 +1095,7 @@ gfc_omp_clause_assign_op (tree clause, tree dest, tree src) gfc_conv_descriptor_sm_get (src, rank)); else { - tree esize = gfc_conv_descriptor_span_get (src); + tree esize = gfc_conv_descriptor_elem_len_get (src); esize = fold_convert_loc (input_location, gfc_array_index_type, esize); size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, size, esize); diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc index f3527694e800..451fc9c06f8c 100644 --- a/gcc/fortran/trans-types.cc +++ b/gcc/fortran/trans-types.cc @@ -2104,12 +2104,6 @@ gfc_get_array_descriptor_base (int dimen, int codimen, bool restricted) get_dtype_type_node (), &chain); suppress_warning (decl); - /* Add the span component. */ - decl = gfc_add_field_to_struct_1 (fat_type, - get_identifier ("span"), - gfc_array_index_type, &chain); - suppress_warning (decl); - /* Build the array type for the stride and bound components. */ if (dimen + codimen > 0) { @@ -3829,7 +3823,7 @@ gfc_get_array_descr_info (const_tree type, struct array_descr_info *info) int rank, dim; bool indirect = false; tree etype, ptype, t, base_decl; - tree data_off, span_off, dim_off, dtype_off, dim_size, elem_size; + tree data_off, elem_len_off, dim_off, dtype_off, dim_size, elem_size; tree lower_suboff, upper_suboff, stride_suboff; tree dtype, field, rank_off; @@ -3884,11 +3878,12 @@ gfc_get_array_descr_info (const_tree type, struct array_descr_info *info) if (indirect) base_decl = build1 (INDIRECT_REF, ptype, base_decl); - gfc_get_descriptor_offsets_for_info (type, &data_off, &dtype_off, &span_off, - &dim_off, &dim_size, &stride_suboff, - &lower_suboff, &upper_suboff); + gfc_get_descriptor_offsets_for_info (type, &data_off, &dtype_off, + &elem_len_off, &dim_off, &dim_size, + &stride_suboff, &lower_suboff, + &upper_suboff); - t = fold_build_pointer_plus (base_decl, span_off); + t = fold_build_pointer_plus (base_decl, elem_len_off); elem_size = build1 (INDIRECT_REF, gfc_array_index_type, t); t = base_decl; diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc index b4ba84964175..0af18d47420c 100644 --- a/gcc/fortran/trans.cc +++ b/gcc/fortran/trans.cc @@ -397,10 +397,10 @@ get_array_span (tree type, tree decl) conversion of a CFI descriptor or the hidden dummy descriptor. */ if (TREE_CODE (decl) == COMPONENT_REF && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) - return gfc_conv_descriptor_span_get (decl); + return gfc_conv_descriptor_elem_len_get (decl); else if (INDIRECT_REF_P (decl) && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) - return gfc_conv_descriptor_span_get (decl); + return gfc_conv_descriptor_elem_len_get (decl); /* Return the span for deferred character length array references. */ if (type @@ -410,7 +410,7 @@ get_array_span (tree type, tree decl) if (TREE_CODE (decl) == PARM_DECL) decl = build_fold_indirect_ref_loc (input_location, decl); if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) - span = gfc_conv_descriptor_span_get (decl); + span = gfc_conv_descriptor_elem_len_get (decl); else span = gfc_get_character_len_in_bytes (type); span = (span && !integer_zerop (span)) @@ -450,7 +450,7 @@ get_array_span (tree type, tree decl) { if (TREE_CODE (decl) == PARM_DECL) decl = build_fold_indirect_ref_loc (input_location, decl); - span = gfc_conv_descriptor_span_get (decl); + span = gfc_conv_descriptor_elem_len_get (decl); } else span = NULL_TREE; diff --git a/libgfortran/caf/single.c b/libgfortran/caf/single.c index 9c1c0c1bc8ca..103f22d30f1b 100644 --- a/libgfortran/caf/single.c +++ b/libgfortran/caf/single.c @@ -576,7 +576,7 @@ _gfortran_caf_get_from_remote ( if (opt_dst_desc && old_dst_data_ptr && !may_realloc_dst && opt_dst_desc->base_addr != old_dst_data_ptr) { - size_t dsize = opt_dst_desc->span; + size_t dsize = opt_dst_desc->dtype.elem_len; for (int i = 0; i < GFC_DESCRIPTOR_RANK (opt_dst_desc); ++i) dsize *= GFC_DESCRIPTOR_EXTENT (opt_dst_desc, i); memcpy (old_dst_data_ptr, opt_dst_desc->base_addr, dsize); diff --git a/libgfortran/intrinsics/associated.c b/libgfortran/intrinsics/associated.c index 592c84c097af..04b244749a4a 100644 --- a/libgfortran/intrinsics/associated.c +++ b/libgfortran/intrinsics/associated.c @@ -37,8 +37,6 @@ associated (const gfc_array_void *pointer, const gfc_array_void *target) return 0; if (GFC_DESCRIPTOR_DATA (pointer) != GFC_DESCRIPTOR_DATA (target)) return 0; - if (GFC_DESCRIPTOR_SPAN (pointer) != GFC_DESCRIPTOR_SPAN (target)) - return 0; if (GFC_DESCRIPTOR_DTYPE (pointer).type != GFC_DESCRIPTOR_DTYPE (target).type) return 0; rank = GFC_DESCRIPTOR_RANK (pointer); diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index 25c3cb6641c3..07559edf51ee 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -388,7 +388,6 @@ struct {\ type *base_addr;\ size_t offset;\ dtype_type dtype;\ - index_type span;\ descriptor_dimension dim[];\ } @@ -451,7 +450,6 @@ struct {\ type *base_addr;\ size_t offset;\ dtype_type dtype;\ - index_type span;\ descriptor_dimension dim[r];\ } @@ -462,7 +460,6 @@ typedef GFC_FULL_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_4) gfc_full_a #define GFC_DESCRIPTOR_SIZE(desc) ((desc)->dtype.elem_len) #define GFC_DESCRIPTOR_DATA(desc) ((desc)->base_addr) #define GFC_DESCRIPTOR_DTYPE(desc) ((desc)->dtype) -#define GFC_DESCRIPTOR_SPAN(desc) ((desc)->span) #define GFC_DIMENSION_LBOUND(dim) ((dim).lower_bound) #define GFC_DIMENSION_UBOUND(dim) ((dim)._ubound) diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c index 1057f37b7d42..f3271f4dd6b7 100644 --- a/libgfortran/runtime/ISO_Fortran_binding.c +++ b/libgfortran/runtime/ISO_Fortran_binding.c @@ -69,12 +69,7 @@ cfi_desc_to_gfc_desc (gfc_array_void *d, CFI_cdesc_t **s_ptr) d->dtype.attribute = (signed short)s->attribute; if (s->rank) - { - if ((size_t)s->dim[0].sm % s->elem_len) - d->span = (index_type)s->dim[0].sm; - else - d->span = (index_type)s->elem_len; - } + d->dtype.elem_len = (index_type)s->elem_len; d->offset = 0; if (GFC_DESCRIPTOR_DATA (d)) @@ -146,7 +141,7 @@ gfc_desc_to_cfi_desc (CFI_cdesc_t **d_ptr, const gfc_array_void *s) else d->dim[n].extent = (CFI_index_t)GFC_DESCRIPTOR_UBOUND(s, n) - (CFI_index_t)GFC_DESCRIPTOR_LBOUND(s, n) + 1; - d->dim[n].sm = (CFI_index_t)(GFC_DESCRIPTOR_STRIDE(s, n) * s->span); + d->dim[n].sm = (CFI_index_t)(GFC_DESCRIPTOR_STRIDE(s, n) * s->dtype.elem_len); } if (*d_ptr == NULL)