From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15368 invoked by alias); 19 Nov 2011 11:47:12 -0000 Received: (qmail 15358 invoked by uid 22791); 19 Nov 2011 11:47:11 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_GM 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; Sat, 19 Nov 2011 11:46:58 +0000 From: "anlauf at gmx dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/51218] [4.7 Regression] Potential optimization bug due to implicit_pure? Date: Sat, 19 Nov 2011 12:11:00 -0000 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: anlauf at gmx dot de X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.7.0 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 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-11/txt/msg01977.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51218 --- Comment #11 from Harald Anlauf 2011-11-19 11:46:28 UTC --- (In reply to comment #10) The code does memory management similar to that required by TR15581 for allocatable DT components and allocatable function results, but it also has to work for compilers that do not support TR15581. It does so by overloading everything needed. > If I understand your code, you are modifying the arguments of your > function and evaluating that function more than once in a single > expression. The expression xi*wi allocates a temporary, which needs to get deallocated after it was used to avoid a memory leak. All bookkeeping is done with the temporaries. Functions check whether they access a variable or a temporary. Using the temporaries is not a pure operation, which is consistent with the way the functions are declared. > This is illegal in Fortran, so gfortran could, in > principle, do anything with it. I thought that program variables are somewhat different from temporaries created from expressions. In Fortran 95 I do not see any standard-conforming way for a program to access that very temporary more than once. If the compiler decides to use it twice, bad things happen. (Same if a compiler decided to call deallocate twice.) > I would advise you to fix your code to > be standard-conforming. Do you have a suggestion without introducing a memory leak? > Because such code is unfortunately quite common, gfortran by default > does not do such optimizations unless directed to be. The fact that > it does here nonetheless is, indeed, a bug.