use of memset and optimization

Ken Raeburn raeburn at MIT.EDU
Fri Nov 8 00:48:01 EST 2002

Sam Hartman <hartmans at MIT.EDU> writes:
> What puzzles me about this as why anyone would mark memset for removal
> with gcc.

Um, why not?  If the compiler figures out that you assign to some
stack variable, and then don't do anything with it before returning
(perhaps because there are no references, perhaps because the compiler
can prove that the references aren't reached), why not delete the
extra operations?  The compiler is worrying about C standard
compliance, and removing the memset in that case is just fine
according to the "as if" rule.  (Roughly, the program has to behave as
if it was executed as written in terms of its output, but otherwise,
the optimizer can do what it likes.)

> I don't think gcc does cross-function-call optimization except in
> special cases.  It seems like someone would have to go out of their
> way to make memset fail in this instance.

The issue is the memset right before returning -- the key point is
that the storage in question is automatic storage allocated by the
current function.  Cross-function-call optimization has nothing to do
with it.

I think Perry's right, the "volatile" keyword is probably the right

More information about the krbdev mailing list