This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Disable optimizations on one function (was: 'pragma optimize' ...)
- From: Andrew Haley <aph at redhat dot com>
- To: noloader at gmail dot com, Markus Trippelsdorf <markus at trippelsdorf dot de>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 16 Jul 2015 10:00:15 +0100
- Subject: Re: Disable optimizations on one function (was: 'pragma optimize' ...)
- Authentication-results: sourceware.org; auth=none
- References: <CAH8yC8kU9JXSyFHrW9neztA4btnjXuxv+m3KyPWp84F=Y1Rv7A at mail dot gmail dot com>
On 16/07/15 06:58, Jeffrey Walton wrote:
> Many folks try and cast ptr to volatile, but that's an abuse because
> GCC considers volatile something for memory mapped hardware. Volatile
> should not be used in an attempt to tame the optimizer.
GCC does not consider volatile to be something for memory mapped
hardware. Volatile objects are simply those which may be modified in
ways unknown to the implementation or have other unknown side effects.
In other words, volatile is exactly the right thing use in the
ClearAndFree case. But passing a volatile pointer to memset() is
pointless because the volatile qualifier will be discarded at the
point of call: you'll have to write the memory yourself.
If you don't mind being nonportable, a memoryclobber should do it:
memset(ptr, 0x00, n);
asm volatile("": : : "memory");
or even:
memset(ptr, 0x00, n);
__atomic_thread_fence(__ATOMIC_RELAXED);
Andrew.