[cfe-dev] Does a inline assembly or a memory barrier disable optimizations in a function

Jeffrey Walton noloader at gmail.com
Sun Aug 2 09:24:51 PDT 2015


On Sun, Aug 2, 2015 at 11:49 AM, Reid Kleckner <rnk at google.com> wrote:
> That construct is just a memory barrier that applies to escaped objects.
> Dead stores to unescaped locals for example will be removed during SSA
> conversion.
>
OK, thanks. That should probably be documented because its different
behavior from GCC.

Its important information for someone writing a zeroizer for
compliance reasons, like FIPS 140. (it might even cause a security
related defect).

Jeff

> On Aug 1, 2015 9:29 PM, "Jeffrey Walton" <noloader at gmail.com> wrote:
>>
>> GCC disables optimizations in a function if it encounters inline
>> assembly. That means we can use a memory barrier to ensure dead stores
>> are not optimized out:
>>
>>     delete m_ptr;
>>     m_ptr = NULL:
>>
>>     __asm__ __volatile__ ("" ::: "memory");
>>
>> Clang defines __GNUC__, but its not clear to me if the same behavior
>> is present. Looking at Language Compatibility at
>> http://clang.llvm.org/compatibility.html, there is no discussion of
>> the behavior.
>>
>> Does inline assembly or a memory barrier tame the optimizer in a
>> function so that dead stores are not removed?
>>



More information about the cfe-dev mailing list