https://gcc.gnu.org/g:52bc10e8e6015aee107373944b1197907f95e469
commit 52bc10e8e6015aee107373944b1197907f95e469 Author: Mikael Morin <[email protected]> Date: Thu Sep 17 21:12:13 2026 +0200 Essai correction select_type_53 Diff: --- gcc/fortran/trans-array.cc | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index d9b34a36a791..2605c641151a 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -496,8 +496,8 @@ is_pointer_array (tree expr) either a descriptor or the local decl of a descriptorless dummy array, which keeps the descriptor it was built from as the saved one. */ -static tree -span_addressed_array (tree expr) +static bool +is_span_addressed_array (tree expr) { if (is_pointer_array (expr)) { @@ -515,14 +515,14 @@ span_addressed_array (tree expr) case GFC_ARRAY_ASSUMED_RANK_POINTER_CONT: case GFC_ARRAY_ALLOCATABLE: case GFC_ARRAY_POINTER_CONT: - return NULL_TREE; + return false; default: break; } } - return expr; + return true; } if (VAR_P (expr) @@ -531,6 +531,23 @@ span_addressed_array (tree expr) && GFC_ARRAY_TYPE_P (TREE_TYPE (expr)) && DECL_LANG_SPECIFIC (expr) && GFC_DECL_SAVED_DESCRIPTOR (expr)) + return true; + + return false; +} + + +static tree +get_span_addressed_array (tree expr) +{ +#if 0 + /* For classes let build_array_ref handle it. */ + if (TREE_CODE (expr) == COMPONENT_REF + && GFC_CLASS_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 0)))) + return NULL_TREE; +#endif + + if (is_span_addressed_array (expr)) return expr; return NULL_TREE; @@ -680,7 +697,7 @@ gfc_get_array_span (tree desc, gfc_expr *expr) if (tree span = GFC_DECL_GET_SPAN (desc)) /* A span addressed dummy loaded its span on entry. */ tmp = span; - else if (span_addressed_array (desc) + else if (is_span_addressed_array (desc) || (get_CFI_desc (NULL, expr, &desc, NULL) && (POINTER_TYPE_P (TREE_TYPE (desc)) ? GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (TREE_TYPE (desc))) @@ -4085,7 +4102,7 @@ gfc_conv_scalarized_array_ref (gfc_se * se, gfc_array_ref * ar, /* A pointer array component can be detected from its field decl. Fix the descriptor, mark the resulting variable decl and pass it to gfc_build_array_ref. */ - if (span_addressed_array (info->descriptor) + if (is_span_addressed_array (info->descriptor) || (expr && expr->ts.deferred && info->descriptor && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (info->descriptor)))) { @@ -4172,6 +4189,10 @@ build_array_ref (tree desc, tree offset, tree decl, tree vptr) } } + if (decl == NULL_TREE + && is_span_addressed_array (desc)) + decl = get_span_addressed_array (desc); + tmp = gfc_conv_array_data (desc); tmp = build_fold_indirect_ref_loc (input_location, tmp); tmp = gfc_build_array_ref (tmp, offset, decl, @@ -4338,7 +4359,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_expr *expr, if (get_CFI_desc (sym, expr, &decl, ar)) decl = build_fold_indirect_ref_loc (input_location, decl); if (!expr->ts.deferred && !sym->attr.codimension - && span_addressed_array (se->expr)) + && is_span_addressed_array (se->expr)) { if (INDIRECT_REF_P (se->expr)) decl = TREE_OPERAND (se->expr, 0); @@ -7759,10 +7780,10 @@ gfc_get_dataptr_offset (stmtblock_t *block, tree parm, tree desc, tree offset, /* An array whose elements are spaced by the span needs pointer arithmetic to reference an element. */ - tmp = build_array_ref (desc, offset, span_addressed_array (desc), NULL); + tmp = build_array_ref (desc, offset, NULL, NULL); /* A spanned character element is referenced by a pointer. */ - if (POINTER_TYPE_P (TREE_TYPE (tmp)) && span_addressed_array (desc)) + if (POINTER_TYPE_P (TREE_TYPE (tmp)) && is_span_addressed_array (desc)) tmp = build_fold_indirect_ref_loc (input_location, tmp); /* Offset the data pointer for pointer assignments from arrays with
