Re: [PATCH] sha: prevent removal of memset as dead store in sha1_update()

Andi Kleen
2010-02-26T15:55:59Z

> Instead of barrier(), this works with gcc-3.2.3 up to gcc-4.4.3
> for the purpose of making the memset() not disappear:
>
> {
> struct s { char c[n]; };
> asm("" : : "m"(*(struct s *)p));
> }
>
> Every byte in the [p,p+n[ range must be used. If you only use the
> first byte, via e.g. asm("" :: "m"(*(char*)p)), then the compiler
> _will_ skip scrubbing bytes beyond the first.
>
> An explicit loop that uses each byte individually also works, but
> results in awful code with older compilers.

I suspect it would be worth asking for a __builtin for this.
iirc Visual C already has one.

BTW I remember finding a few more such cases in random user space
code in past code review.

-Andi
--
ak@linux.intel.com -- Speaking for myself only.