https://gcc.gnu.org/g:44c68260a83e87f02e645f56ceea92013700c1ed
commit 44c68260a83e87f02e645f56ceea92013700c1ed Author: Mikael Morin <[email protected]> Date: Sun Oct 25 18:19:27 2026 +0100 Création fonction déportée get_main_decl Diff: --- gcc/fortran/trans-array.cc | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 4978b94cac78..ea68396095cf 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -668,26 +668,53 @@ class_array_element_size (tree decl, bool unlimited) } -/* Return the span of an array. */ +/* Given a data reference EXPR, return the main underlying declaration + (variable, parameter, etc) if there is one, otherwise return NULL_TREE. + Having the declaration gives access to the additional metadata stored in + the lang-specific node. */ -tree -gfc_get_array_span (tree desc, gfc_expr *expr) +static tree +get_main_decl (tree expr) { - tree tmp; - gfc_symbol *sym = (expr && expr->expr_type == EXPR_VARIABLE) ? - expr->symtree->n.sym : NULL; - - tree decl = desc; + tree decl = expr; while (decl && !DECL_P (decl)) { if (TREE_CODE (decl) == ADDR_EXPR || INDIRECT_REF_P (decl) || CONVERT_EXPR_P (decl)) decl = TREE_OPERAND (decl, 0); + else if (TREE_CODE (decl) == COMPONENT_REF) + { + tree base = TREE_OPERAND (decl, 0); + tree field = TREE_OPERAND (decl, 1); + const char * field_name = IDENTIFIER_POINTER (DECL_NAME (field)); + if ((GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (base)) + && strcmp (field_name, "data") == 0) + || (GFC_CLASS_TYPE_P (TREE_TYPE (base)) + && strcmp (field_name, "_data") == 0)) + decl = base; + else + decl = NULL_TREE; + } else decl = NULL_TREE; } + return decl; +} + + +/* Return the span of an array. */ + +tree +gfc_get_array_span (tree desc, gfc_expr *expr) +{ + tree tmp; + gfc_symbol *sym = (expr && expr->expr_type == EXPR_VARIABLE) ? + expr->symtree->n.sym : NULL; + + tree decl = get_main_decl (desc); + if (tree span = GFC_DECL_GET_SPAN (decl ? decl : desc)) /* A span addressed dummy loaded its span on entry. */ tmp = span;
