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

--- Comment #3 from anlauf at gcc dot gnu.org ---
The apparent discrepancy between fndecl and the actual arguments in the call
may be a result from the following block in gfc_conv_procedure_call after:

7390          /* Deferred length dummies pass the character length by reference
7391             so that the value can be returned.  */
7392          if (parmse.string_length && fsym && fsym->ts.deferred)
...

The following patch fixes the testcase and regtests ok so far:

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 7017b652d6e..8ed812bff0d 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -7404,7 +7404,10 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
              tmp = parmse.string_length;
              if (!VAR_P (tmp) && TREE_CODE (tmp) != COMPONENT_REF)
                tmp = gfc_evaluate_now (parmse.string_length, &se->pre);
-             parmse.string_length = gfc_build_addr_expr (NULL_TREE, tmp);
+             if (fsym->attr.allocatable || fsym->attr.pointer)
+               parmse.string_length = gfc_build_addr_expr (NULL_TREE, tmp);
+             else
+               parmse.string_length = tmp;
            }

          if (e && e->expr_type == EXPR_VARIABLE

Needs more checking.

Reply via email to