This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimising away memset() calls?
- From: Andrew Haley <aph at redhat dot com>
- To: Sandy Harris <sandyinchina at gmail dot com>, gcc-help at gcc dot gnu dot org
- Date: Wed, 08 Oct 2014 09:29:37 +0100
- Subject: Re: Optimising away memset() calls?
- Authentication-results: sourceware.org; auth=none
- References: <CACXcFm=c0kf-2M2V_D+L2PdEoD4qcqKNVmPGQkv8FRKEqw3Zmw at mail dot gmail dot com>
On 08/10/14 03:15, Sandy Harris wrote:
> As I see it, though, and wrote in one thread:
>
> " A real fix would make memset() do the right thing reliably; if the
> " programmer puts in memset( x, 0, nbytes) then the memory should
> " be cleared, no ifs or buts. I do not know or care if that means
> " changes in the compiler or in the library code or even both, but
> " the fix should make the standard library code work right, not
> " require adding a new function and expecting everyone to use it.
>
> It seemed worth tossing this out for comment here.
That's not going to happen, given that memset_s() is a standard
idiom for this operation.
As it stands, even a call to memset_s() isn't sufficient: another
thread may not observe the memset_s() until a barrier has been
executed (and maybe not even then!) but I suppose it's better than
nothing.
Andrew.