Clarification on Gcc's strict aliasing rules

Tim Prince
Mon Nov 8 13:05:00 GMT 2010

On 11/8/2010 1:07 AM, Francis Moreau wrote:
> Ian Lance Taylor<>  writes:
>> I think I would say this slightly differently.  The code is still
>> undefined according to the C/C++ language standards.  When you use
>> -fno-strict-aliasing, gcc is promising to avoid using a class of
>> optimizations based on those portions of the language standards.
>> Another way to say this is that gcc is promising to not optimize based
>> on the fact that memory locations are accessed using different types.
>> That is, the code is still incorrect; gcc is just avoiding a class of
>> optimizations which are known to cause trouble with real programs.
>> I also am having trouble understanding what the OP is asking for here.
> Clarification on GCC's strict aliasing rules.
> But I think I got it now, although I still don't know which exactly
> undefined behaviours are defined by GCC's -fno-strict-aliasing.
Ian just explained it well.  -fno-strict-aliasing avoids code movement 
optimizations which depend on compliance with -fstrict-aliasing.  If you 
mean you want incorrect code to give the same result as it does with 
other compilers which accept it, on the same architecture, that's not 
entirely the same thing, no one can recommend it, but I can't stop you 
from trying.

Tim Prince

More information about the Gcc-help mailing list