https://gcc.gnu.org/g:0e10631d947fe736a841d1f6b2275bc76f4da79a
commit 0e10631d947fe736a841d1f6b2275bc76f4da79a Author: Mikael Morin <mik...@gcc.gnu.org> Date: Tue Apr 22 19:10:58 2025 +0200 Correction régression simpleif_1 Diff: --- gcc/fortran/trans-array.cc | 3 ++- gcc/fortran/trans-descriptor.cc | 24 +++--------------------- gcc/fortran/trans-types.cc | 37 +++++++++++++++++++++++++++++++++++++ gcc/fortran/trans-types.h | 2 ++ 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 652649953a24..483cf5d473aa 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -3763,7 +3763,8 @@ add_array_offset (stmtblock_t *pblock, gfc_loopinfo *loop, gfc_ss *ss, tree tmp = build_array_ref_dim (ss, index, info->lbound[array_dim], info->spacing[array_dim]); tmp = gfc_build_addr_expr (NULL_TREE, tmp); - tmp = fold_convert_loc (input_location, type, tmp); + tree fixed_type = gfc_get_unbounded_array_type (type); + tmp = fold_convert_loc (input_location, fixed_type, tmp); info->data = gfc_evaluate_now (tmp, pblock); } diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc index 6df34b7bb28a..4c3df7b646c4 100644 --- a/gcc/fortran/trans-descriptor.cc +++ b/gcc/fortran/trans-descriptor.cc @@ -3887,27 +3887,9 @@ gfc_grow_array (stmtblock_t * pblock, tree desc, tree extra) /* Reset array type upper bound if known. */ tree dataptr_type = GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (desc)); - gcc_assert (TREE_CODE (dataptr_type) == POINTER_TYPE); - tree array_type = TREE_TYPE (dataptr_type); - gcc_assert (TREE_CODE (array_type) == ARRAY_TYPE); - tree index_type = TYPE_DOMAIN (array_type); - if (index_type != NULL_TREE - && (TYPE_MAX_VALUE (index_type) != NULL_TREE - || TYPE_SIZE (array_type) != NULL_TREE - || TYPE_SIZE_UNIT (array_type) != NULL_TREE)) - { - tree fixed_index_type = build_distinct_type_copy (index_type); - TYPE_MAX_VALUE (fixed_index_type) = NULL_TREE; - - tree fixed_array_type = build_distinct_type_copy (array_type); - TYPE_DOMAIN (fixed_array_type) = fixed_index_type; - TYPE_SIZE (fixed_array_type) = NULL_TREE; - TYPE_SIZE_UNIT (fixed_array_type) = NULL_TREE; - layout_type (fixed_array_type); - - tree fixed_ptr_type = build_pointer_type (fixed_array_type); - GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (desc)) = fixed_ptr_type; - } + tree fixed_ptr_type = gfc_get_unbounded_array_type (dataptr_type); + if (fixed_ptr_type != dataptr_type) + GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (desc)) = fixed_ptr_type; /* Call the realloc() function. */ tmp = gfc_call_realloc (pblock, arg0, arg1); diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc index 4b48b46fc966..74f922ffc2d3 100644 --- a/gcc/fortran/trans-types.cc +++ b/gcc/fortran/trans-types.cc @@ -4297,4 +4297,41 @@ gfc_build_incomplete_array_type (tree elt_type, tree index_type) } +tree +gfc_get_unbounded_array_type (tree type) +{ + bool ptr_wrapper = TREE_CODE (type) == POINTER_TYPE; + + tree array_type; + if (ptr_wrapper) + array_type = TREE_TYPE (type); + else + array_type = type; + + gcc_assert (TREE_CODE (array_type) == ARRAY_TYPE); + tree index_type = TYPE_DOMAIN (array_type); + if (TYPE_MAX_VALUE (index_type) == NULL_TREE + && TYPE_SIZE (array_type) == NULL_TREE + && TYPE_SIZE_UNIT (array_type) == NULL_TREE) + return type; + + tree modified_index_type = build_distinct_type_copy (index_type); + TYPE_MAX_VALUE (modified_index_type) = NULL_TREE; + + tree modified_array_type = build_distinct_type_copy (array_type); + TYPE_DOMAIN (modified_array_type) = modified_index_type; + TYPE_SIZE (modified_array_type) = NULL_TREE; + TYPE_SIZE_UNIT (modified_array_type) = NULL_TREE; + layout_type (modified_array_type); + + tree modified_type; + if (ptr_wrapper) + modified_type = build_pointer_type (modified_array_type); + else + modified_type = modified_array_type; + + return modified_type; +} + + #include "gt-fortran-trans-types.h" diff --git a/gcc/fortran/trans-types.h b/gcc/fortran/trans-types.h index 5f4da9202d78..6c981ad2f3d7 100644 --- a/gcc/fortran/trans-types.h +++ b/gcc/fortran/trans-types.h @@ -125,4 +125,6 @@ tree gfc_get_caf_reference_type (); tree gfc_build_incomplete_array_type (tree, tree); +tree gfc_get_unbounded_array_type (tree); + #endif