This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Optimizing of explicit temporary storage
Mark Mitchell wrote:
The as-if rule says that the compiler can perform the optimization only
if the program can't tell the difference. I don't think it means "can't
tell the difference using functions from the ISO C standard library;"
instead, I think it means "can't tell the difference in the current
environment." Certainly, calling malloc has observable side effects on
most UNIX systems; I can see whether or not processes are calling malloc
by running "top".
Anything has observable effects in this respect, because it changes the
code generated, which changes the cache usage, size of external object
files etc etc. Indeed it is perfectly easy to observe all kinds of things
using tools like gdb, objdump etc.
When we are talking about standards conformance, we restrict our attention
strictly to the standard, and what we mean by the as-if rule is that we
cannot write a C program whose meaning is defined by the standard that
can tell the difference at the semantic level of description in the
standard.
That is why you often have to go beyond the standard in deciding when
it is appropriate to do transformations that may violate programmer
expectations, even if these expectations are not derivable from the
standard.