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

--- Comment #3 from anlauf at gcc dot gnu.org ---
Tentative patch:

diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index 3881370d947..366b00c28dd 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -8162,7 +8162,15 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mold,
gfc_expr *size)
      set even for array expressions, in order to pass this information into
      gfc_target_interpret_expr.  */
   if (result->ts.type == BT_CHARACTER && gfc_is_constant_expr (mold_element))
-    result->value.character.length = mold_element->value.character.length;
+    {
+      result->value.character.length = mold_element->value.character.length;
+
+      /* A zero-sized result array needs to inherit the string length.  */
+      if (result_length == 0)
+       result->ts.u.cl->length =
+         gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+                           mold_element->value.character.length);
+    }

   /* Set the number of elements in the result, and determine its size.  */


This fixes the ICE as well as now produces a correct result e.g. for

  print *, len (transfer('ab', 'xyz', size=0))

However, looking at the tree dump of comment#0 I see very similar multiple
temporaries being generated as for other empty array constructors being passed
to procedures (pr86277).

Reply via email to