[Bug fortran/47775] Wrong code with allocatable function RESULT and GENERIC interfaces
burnus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Feb 17 23:59:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47775
--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-02-17 23:45:14 UTC ---
If one looks closer at "se->direct_byref" in gfc_conv_procedure_call, one sees
that in the generic case "se->direct_byref" is 1 while in the specific-call
case it is 0. (Thus, in the specific case, always a temporary is generated.)
There might be no need for a temporary, if the LHS is allocatable without the
TARGET attribute.
I am not sure how far automatic realloc is properly handled for
allocatable-returning functions, but there might be room for optimization if
the size changes or the LHS is not TARGET.
Untested patch:
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -5373,8 +5373,9 @@ arrayfunc_assign_needs_temporary (gfc_expr * expr1,
gfc_expr * expr2)
return true;
/* Functions returning pointers need temporaries. */
- if (expr2->symtree->n.sym->attr.pointer
- || expr2->symtree->n.sym->attr.allocatable)
+ if (expr2->value.function.esym
+ && (expr2->value.function.esym->attr.pointer
+ expr2->value.function.esym->attr.allocatable))
return true;
/* Character array functions need temporaries unless the
More information about the Gcc-bugs
mailing list