https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53296

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jvdelisle at gcc dot 
gnu.org
                 CC|                            |jvdelisle at gcc dot gnu.org

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
I am testing this:

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index db33bcdd15d..2c24a6717f5 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -7046,6 +7046,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
   int arglen;
   unsigned int argc;
   tree arg1_cntnr = NULL_TREE;
+  bool call_needed_for_length = true;
   arglist = NULL;
   retargs = NULL;
   stringargs = NULL;
@@ -8767,6 +8768,10 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
                                 fold_convert (gfc_charlen_type_node, tmp),
                                 build_zero_cst (gfc_charlen_type_node));
          cl.backend_decl = tmp;
+
+         /* The length was fully computed above from the specification
+            expression, without needing the callee to actually run.  */
+         call_needed_for_length = false;
        }

       /* Set up a charlen structure for it.  */
@@ -9076,7 +9081,9 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
   if (byref)
     {
       /* Add the function call to the pre chain.  There is no expression.  */
-      gfc_add_expr_to_block (&se->pre, se->expr);
+      if (!se->no_function_call || call_needed_for_length)
+       gfc_add_expr_to_block (&se->pre, se->expr);
+
       se->expr = NULL_TREE;

       if (!se->direct_byref)

Reply via email to