]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: Remove useless elements count variable
authorMikael Morin <morin-mikael@orange.fr>
Sun, 27 Jul 2025 12:47:14 +0000 (14:47 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Wed, 30 Jul 2025 08:35:12 +0000 (10:35 +0200)
The function gfc_array_init_size evaluates the number of array elements
to a variable from a caller, but the single caller providing the
variable actually doesn't use it.

This change removes the variable and the function arguments passing its
address down the call chain.

gcc/fortran/ChangeLog:

* trans-array.cc (gfc_array_init_size): Remove the nelems
argument.
(gfc_array_allocate): Update caller.  Remove the nelems
argument.
* trans-stmt.cc (gfc_trans_allocate): Update caller.  Remove the
nelems variable.
* trans-array.h (gfc_array_allocate): Update prototype.

gcc/fortran/trans-array.cc
gcc/fortran/trans-array.h
gcc/fortran/trans-stmt.cc

index 6b759d13f1a3ba934bc5efce54af3ee5be63ecad..0f7637dd535c36459525908088a6aab226b1329b 100644 (file)
@@ -6296,8 +6296,8 @@ static tree
 gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
                     gfc_expr ** lower, gfc_expr ** upper, stmtblock_t * pblock,
                     stmtblock_t * descriptor_block, tree * overflow,
-                    tree expr3_elem_size, tree *nelems, gfc_expr *expr3,
-                    tree expr3_desc, bool e3_has_nodescriptor, gfc_expr *expr,
+                    tree expr3_elem_size, gfc_expr *expr3, tree expr3_desc,
+                    bool e3_has_nodescriptor, gfc_expr *expr,
                     tree *element_size, bool explicit_ts)
 {
   tree type;
@@ -6573,7 +6573,6 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
   if (rank == 0)
     return *element_size;
 
-  *nelems = gfc_evaluate_now (stride, pblock);
   stride = fold_convert (size_type_node, stride);
 
   /* First check for overflow. Since an array of type character can
@@ -6662,9 +6661,8 @@ retrieve_last_ref (gfc_ref **ref_in, gfc_ref **prev_ref_in)
 bool
 gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg,
                    tree errlen, tree label_finish, tree expr3_elem_size,
-                   tree *nelems, gfc_expr *expr3, tree e3_arr_desc,
-                   bool e3_has_nodescriptor, gfc_omp_namelist *omp_alloc,
-                   bool explicit_ts)
+                   gfc_expr *expr3, tree e3_arr_desc, bool e3_has_nodescriptor,
+                   gfc_omp_namelist *omp_alloc, bool explicit_ts)
 {
   tree tmp;
   tree pointer;
@@ -6795,7 +6793,7 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree status, tree errmsg,
                              coarray ? ref->u.ar.as->corank : 0,
                              &offset, lower, upper,
                              &se->pre, &set_descriptor_block, &overflow,
-                             expr3_elem_size, nelems, expr3, e3_arr_desc,
+                             expr3_elem_size, expr3, e3_arr_desc,
                              e3_has_nodescriptor, expr, &element_size,
                              explicit_ts);
 
index 1bb3294b0749cfbb78b9127d77bb0bc9da137755..29098fd0ace4a573f4677d07c2e0c4c3f20d0dd9 100644 (file)
@@ -20,9 +20,8 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Generate code to initialize and allocate an array.  Statements are added to
    se, which should contain an expression for the array descriptor.  */
-bool gfc_array_allocate (gfc_se *, gfc_expr *, tree, tree, tree, tree,
-                        tree, tree *, gfc_expr *, tree, bool,
-                        gfc_omp_namelist *, bool);
+bool gfc_array_allocate (gfc_se *, gfc_expr *, tree, tree, tree, tree, tree,
+                        gfc_expr *, tree, bool, gfc_omp_namelist *, bool);
 
 /* Allow the bounds of a loop to be set from a callee's array spec.  */
 void gfc_set_loop_bounds_from_array_spec (gfc_interface_mapping *,
index f1054015862747024cf941d31405b1e0a5ab0557..b4ddf7592c9657f1d0aa9bb2cc2b280507a1d893 100644 (file)
@@ -6710,7 +6710,6 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist *omp_allocate)
   stmtblock_t block;
   stmtblock_t post;
   stmtblock_t final_block;
-  tree nelems;
   bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set, is_coarray;
   bool needs_caf_sync, caf_refs_comp;
   bool e3_has_nodescriptor = false;
@@ -7242,7 +7241,6 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist *omp_allocate)
         to handle the complete array allocation.  Only the element size
         needs to be provided, which is done most of the time by the
         pre-evaluation step.  */
-      nelems = NULL_TREE;
       if (expr3_len && (code->expr3->ts.type == BT_CHARACTER
                        || code->expr3->ts.type == BT_CLASS))
        {
@@ -7313,9 +7311,8 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist *omp_allocate)
 
        }
 
-      if (!gfc_array_allocate (&se, expr, stat, errmsg, errlen,
-                              label_finish, tmp, &nelems,
-                              e3rhs ? e3rhs : code->expr3,
+      if (!gfc_array_allocate (&se, expr, stat, errmsg, errlen, label_finish,
+                              tmp, e3rhs ? e3rhs : code->expr3,
                               e3_is == E3_DESC ? expr3 : NULL_TREE,
                               e3_has_nodescriptor, omp_alloc_item,
                               code->ext.alloc.ts.type != BT_UNKNOWN))