Cleanup for cryptographic algorithms vs. compiler optimizations

Dag-Erling Smørgrav des at
Sat Jun 12 17:37:37 UTC 2010

Bernd Walter <ticso at> writes:
> I'm not sure when removing a memset is allowed.

Always, if the compiler can determine that the data will not be used

In more general terms, the compiler is allowed to make any changes it
likes to the program as long as the end result behaves exactly like it
would if it hadn't been changed.  This is called the "as if" rule.  For
instance, if you call printf() or fprintf() with a format string that
does not contain any conversion specifiers, gcc will call gets() or
fgets() instead.

> Maybe passing volatile pointers might be enough.

You can't pass a volatile pointer to memset.

Dag-Erling Smørgrav - des at

More information about the freebsd-current mailing list