From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27610 invoked by alias); 17 Feb 2011 23:45:23 -0000 Received: (qmail 27599 invoked by uid 22791); 17 Feb 2011 23:45:22 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Feb 2011 23:45:18 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/47775] Wrong code with allocatable function RESULT and GENERIC interfaces X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Thu, 17 Feb 2011 23:59:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg02089.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47775 --- Comment #5 from Tobias Burnus 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