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: Jeffrey Walton <noloader at gmail dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 16 Jul 2015 05:40:27 -0400
- 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> <55A7729F dot 2090604 at redhat dot com>
- Reply-to: noloader at gmail dot com
>> 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.
OK, this appears to be creating a moving definition (or the definition
has changed since I took note of it). I took the last definition from
Ian Lance Taylor. See http://www.airs.com/blog/archives/154 and, for
example, https://gcc.gnu.org/ml/gcc-help/2012-03/msg00257.html.
> ...
> 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);
Perfect, thanks.
Jeff