[Bug fortran/51218] [4.7 Regression] Potential optimization bug due to implicit_pure?

anlauf at gmx dot de gcc-bugzilla@gcc.gnu.org
Sat Nov 19 12:11:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51218

--- Comment #11 from Harald Anlauf <anlauf at gmx dot de> 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.



More information about the Gcc-bugs mailing list