[Bug tree-optimization/19828] [4.0 Regression] LIM is pulling out a pure function even though there is something which can modify global memory

ian at airs dot com gcc-bugzilla@gcc.gnu.org
Mon Feb 14 08:52:00 GMT 2005


------- Additional Comments From ian at airs dot com  2005-02-13 20:27 -------
The definition of pure states that such a function may depend upon global
variables.  I guess you are saying that func_pure_2 is not pure because the
global variable a may not be a valid memory address?

I disagree.  If the programmer declares that func_pure_2 is pure, then the
programmer is promising the compiler that the variable a holds a valid memory
address.  The attribute is not a statement of something which the compiler can
deduce for itself; it is a promise by the programmer.

Given that promise, the compiler is fully entitled and expected to hoist
function calls out of loops which do not modify global variables, etc.  If that
causes a bug, it is a bug in the code, not in the compiler.

I agree that it would be nice if the compiler could do a better job of analyzing
whether a function is const/pure, but until then we should trust the programmer.

-- 


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



More information about the Gcc-bugs mailing list