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

--- Comment #15 from Harald Anlauf <anlauf at gcc dot gnu.org> ---
(In reply to Jerry DeLisle from comment #14)
> Created attachment 64639 [details]
> Potential fix for this PR
> 
> Harald, here is a tentative patch. Let me know any comments before I go any
> further on it.

Jerry, thank for attacking this!

Funnily I already had my own first attempts at this.
First thing is clarification of the argument passing conventions when VALUE
is specified.

For scalar dummies we mostly pass on the stack (gfortran manual, section
6.4.2).
For arrays and for assumed length scalar character we want to pass by
reference, right?

This means we want:

diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 5bccea960aa..c1aa528fd6c 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -2516,7 +2516,11 @@ gfc_sym_type (gfc_symbol * sym, bool is_bind_c)
   else
     type = gfc_typenode_for_spec (&sym->ts, sym->attr.codimension);

-  if (sym->attr.dummy && !sym->attr.function && !sym->attr.value
+  if (sym->attr.dummy && !sym->attr.function
+      && !(sym->attr.value
+          && sym->attr.dimension == 0
+          && !(sym->ts.type == BT_CHARACTER
+               && (!sym->ts.u.cl || !sym->ts.u.cl->length)))
       && !sym->pass_as_value)
     byref = 1;
   else


(We may need to verify in other places that the procedure's fndecl stays
consistent with this choice).

I wonder if we really want to add bloat to gfc_conv_procedure_call or simply
trigger the generation of a temporary the standard way for the cases where
we pass by reference.

Re testcase fortran.dg/value_5.f90: I would rather add a -std=f2003 to check
the old (F2003) behavior.  The F2008+ should be dealt with separately.

While at it, we can then see if we can also handle all the other basic types
passed by VALUE.

Reply via email to