https://gcc.gnu.org/g:063c0014407236e53fa5c3734cab2f3fec5fa03f

commit 063c0014407236e53fa5c3734cab2f3fec5fa03f
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Tue Dec 17 17:27:24 2024 +0100

    Déplacement shift descriptor vers gfc_conv_array_parameter
    
    Suppression variables inutilisées

Diff:
---
 gcc/fortran/trans-array.cc | 49 ++++++++++++++++++++++++++++++++++++++--------
 gcc/fortran/trans-array.h  |  2 +-
 gcc/fortran/trans-expr.cc  | 20 +------------------
 3 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 0370d10d9ebd..2fdd15962e49 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1151,6 +1151,43 @@ gfc_conv_shift_descriptor_lbound (stmtblock_t* block, 
tree desc,
 }
 
 
+static void
+conv_shift_descriptor (stmtblock_t* block, tree desc, int rank)
+{
+  /* Apply a shift of the lbound when supplied.  */
+  for (int dim = 0; dim < rank; ++dim)
+    gfc_conv_shift_descriptor_lbound (block, desc, dim,
+                                     gfc_index_one_node);
+}
+
+
+static bool
+keep_descriptor_lower_bound (gfc_expr *e)
+{
+  gfc_ref *ref;
+
+  /* Detect any array references with vector subscripts.  */
+  for (ref = e->ref; ref; ref = ref->next)
+    if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT
+       && ref->u.ar.type != AR_FULL)
+      {
+       int dim;
+       for (dim = 0; dim < ref->u.ar.dimen; dim++)
+         if (ref->u.ar.dimen_type[dim] == DIMEN_VECTOR)
+           break;
+       if (dim < ref->u.ar.dimen)
+         break;
+      }
+
+  /* Array references with vector subscripts and non-variable
+     expressions need be converted to a one-based descriptor.  */
+  if (ref || e->expr_type != EXPR_VARIABLE)
+    return false;
+
+  return true;
+}
+
+
 /* Obtain offsets for trans-types.cc(gfc_get_array_descr_info).  */
 
 void
@@ -9454,7 +9491,7 @@ is_pointer (gfc_expr *e)
 void
 gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, bool g77,
                          const gfc_symbol *fsym, const char *proc_name,
-                         tree *size, tree *lbshift, tree *packed)
+                         tree *size, bool maybe_shift, tree *packed)
 {
   tree ptr;
   tree desc;
@@ -9690,13 +9727,9 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, 
bool g77,
          stmtblock_t block;
 
          gfc_init_block (&block);
-         if (lbshift && *lbshift)
-           {
-             /* Apply a shift of the lbound when supplied.  */
-             for (int dim = 0; dim < expr->rank; ++dim)
-               gfc_conv_shift_descriptor_lbound (&block, se->expr, dim,
-                                                 *lbshift);
-           }
+         if (maybe_shift && !keep_descriptor_lower_bound (expr))
+           conv_shift_descriptor (&block, se->expr, expr->rank);
+
          tmp = gfc_class_data_get (ctree);
          if (expr->rank > 1 && CLASS_DATA (fsym)->as->rank != expr->rank
              && CLASS_DATA (fsym)->as->type == AS_EXPLICIT && !no_pack)
diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h
index 78646275b4ec..17e3d08fdba0 100644
--- a/gcc/fortran/trans-array.h
+++ b/gcc/fortran/trans-array.h
@@ -158,7 +158,7 @@ tree gfc_get_array_span (tree, gfc_expr *);
 void gfc_conv_expr_descriptor (gfc_se *, gfc_expr *);
 /* Convert an array for passing as an actual function parameter.  */
 void gfc_conv_array_parameter (gfc_se *, gfc_expr *, bool, const gfc_symbol *,
-                              const char *, tree *, tree * = nullptr,
+                              const char *, tree *, bool = false,
                               tree * = nullptr);
 
 /* These work with both descriptors and descriptorless arrays.  */
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 6978f83cdc8c..e8b229d853e3 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -991,8 +991,6 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
          stmtblock_t block;
          gfc_init_block (&block);
          gfc_ref *ref;
-         int dim;
-         tree lbshift = NULL_TREE;
 
          /* Array refs with sections indicate, that a for a formal argument
             expecting contiguous repacking needs to be done.  */
@@ -1005,25 +1003,9 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
              && (ref || e->rank != fsym->ts.u.derived->components->as->rank))
            fsym->attr.contiguous = 1;
 
-         /* Detect any array references with vector subscripts.  */
-         for (ref = e->ref; ref; ref = ref->next)
-           if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT
-               && ref->u.ar.type != AR_FULL)
-             {
-               for (dim = 0; dim < ref->u.ar.dimen; dim++)
-                 if (ref->u.ar.dimen_type[dim] == DIMEN_VECTOR)
-                   break;
-               if (dim < ref->u.ar.dimen)
-                 break;
-             }
-         /* Array references with vector subscripts and non-variable
-            expressions need be converted to a one-based descriptor.  */
-         if (ref || e->expr_type != EXPR_VARIABLE)
-           lbshift = gfc_index_one_node;
-
          parmse->expr = var;
          gfc_conv_array_parameter (parmse, e, false, fsym, proc_name, nullptr,
-                                   &lbshift, &packed);
+                                   true, &packed);
 
          if (derived_array && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (parmse->expr)))
            {

Reply via email to