use gcc4.1.2 on x86_64/linux, for example:
long long int a;
if using -O0/-O1 optimization, the result is 1.000000;
but if using -O2/-O3 optimization,the result is 0.000000.
i have try to close -fno-strict-aliasing in -O2/-O3, the result will be same as -O0/-O1.
so i think the strict-aliasing may have some bug!!!
No this is working as designed. GCC does warn about this case.
t.c:6: warning: dereferencing type-punned pointer will break strict-aliasing rules
Now in 4.4.0 and above, the same result will happen at -O1 and -O2 because of another optimization that allows for the compiler to remove the alias violation in the IR.
*** This bug has been marked as a duplicate of 21920 ***