[gcc(refs/users/mikael/heads/refactor_descriptor_v08)] Factorisation build_spanned_array_ref
Mikael Morin
mikael@gcc.gnu.org
Wed Sep 17 10:45:23 GMT 2025
https://gcc.gnu.org/g:c11ae827dd133dd6014c2c4abd7956b195714593
commit c11ae827dd133dd6014c2c4abd7956b195714593
Author: Mikael Morin <mikael@gcc.gnu.org>
Date: Tue Sep 16 11:25:02 2025 +0200
Factorisation build_spanned_array_ref
Correction nom fonction gfc_build_spanned_array_ref
Diff:
---
gcc/fortran/trans.cc | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index 66c0bf28f06b..b35e31ec0e49 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -462,8 +462,9 @@ get_array_span (tree type, tree decl)
}
-tree
-gfc_build_spanned_array_ref (tree base, tree offset, tree span)
+static tree
+build_spanned_array_ref (tree base, tree offset, tree span,
+ bool dereference_pointer)
{
tree type;
tree tmp;
@@ -474,13 +475,23 @@ gfc_build_spanned_array_ref (tree base, tree offset, tree span)
tmp = gfc_build_addr_expr (pvoid_type_node, base);
tmp = fold_build_pointer_plus_loc (input_location, tmp, offset);
tmp = fold_convert (build_pointer_type (type), tmp);
- if ((TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != ARRAY_TYPE)
- || !TYPE_STRING_FLAG (type))
+ if (dereference_pointer)
tmp = build_fold_indirect_ref_loc (input_location, tmp);
return tmp;
}
+tree
+gfc_build_spanned_array_ref (tree base, tree offset, tree span)
+{
+ tree type = TREE_TYPE (TREE_TYPE (base));
+ return build_spanned_array_ref (base, offset, span,
+ !((TREE_CODE (type) == INTEGER_TYPE
+ && TREE_CODE (type) == ARRAY_TYPE)
+ || TYPE_STRING_FLAG (type)));
+}
+
+
/* Build an ARRAY_REF with its natural type.
NON_NEGATIVE_OFFSET indicates if it’s true that OFFSET can’t be negative,
and thus that an ARRAY_REF can safely be generated. If it’s false, we
@@ -557,16 +568,8 @@ gfc_build_array_ref (tree base, tree offset, bool non_negative_offset,
tree elt_size = fold_convert (gfc_array_index_type,
TYPE_SIZE_UNIT (type));
- tree offset_bytes = fold_build2_loc (input_location, MULT_EXPR,
- gfc_array_index_type,
- zero_based_index, elt_size);
-
- tree base_addr = gfc_build_addr_expr (pvoid_type_node, base);
-
- tree ptr = fold_build_pointer_plus_loc (input_location, base_addr,
- offset_bytes);
- return build1_loc (input_location, INDIRECT_REF, type,
- fold_convert (build_pointer_type (type), ptr));
+ return build_spanned_array_ref (base, zero_based_index, elt_size,
+ true);
}
}
More information about the Gcc-cvs
mailing list