This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/19828] [4.0 Regression] LIM is pulling out a pure function even though there is something which can modify global memory
- From: "ian at airs dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Feb 2005 20:27:09 -0000
- Subject: [Bug tree-optimization/19828] [4.0 Regression] LIM is pulling out a pure function even though there is something which can modify global memory
- References: <20050208190328.19828.pinskia@gcc.gnu.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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