Hello, Here is a small sample to repeat the case: ------------ #include <stdio.h> main() { double d1, *pd1; char *c = (char*)&d1; pd1 = &d1; ((int*)pd1)[0] = -1; ((int*)pd1)[1] = -1; fprintf(stderr,">> d1 = %lf\n", d1); fprintf(stderr,">> int: %d %d\n", ((int*)pd1)[0], ((int*)pd1)[1]); fprintf(stderr,">> c1 = %02x\n", c[0]); fprintf(stderr,">> c2 = %02x\n", c[1]); fprintf(stderr,">> c3 = %02x\n", c[2]); fprintf(stderr,">> c4 = %02x\n", c[3]); fprintf(stderr,">> c5 = %02x\n", c[4]); fprintf(stderr,">> c6 = %02x\n", c[5]); fprintf(stderr,">> c7 = %02x\n", c[6]); fprintf(stderr,">> c8 = %02x\n", c[7]); } ------------ When I compile with `gcc -m64 -o b64 b64.c`, the output is correct: >> d1 = nan >> int: -1 -1 >> c1 = ff >> c2 = ff >> c3 = ff >> c4 = ff >> c5 = ff >> c6 = ff >> c7 = ff >> c8 = ff But when I use the optimise flag, `gcc -O2 -m64 -o b64 b64.c`, and run again the sample, there is a problem with the results. See bellow: >> d1 = 0.000000 >> int: -1 -1 >> c1 = ff >> c2 = ff >> c3 = ff >> c4 = ff >> c5 = ff >> c6 = ff >> c7 = ff >> c8 = ff Gcc release: Using built-in specs. Target: ppc64-redhat-linux Configured with: ../gcc-4.0.0/configure --prefix=/home/comp/gcctest4.0.0 --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --host=ppc64-redhat-linux --build=ppc64-redhat-linux --target=ppc64-redhat-linux --with-cpu=default32 --enable-languages=c,c++ Thread model: posix gcc version 4.0.0 Environment: Linux 2.6.9-11.EL #1 SMP Fri May 20 18:18:48 EDT 2005 ppc64 ppc64 ppc64 GNU/Linux Best regards.
Created attachment 10589 [details] Small sample to illustrate the problem How to repeat sample
You are violating C aliasing rules as you acess d1 via an int. *** This bug has been marked as a duplicate of 21920 ***
Maybe... But I made some tests under Linux X86 and some AIX 64 bits. This code works as expected everywhere... So, I wonder why gcc behaviour is différent under this Linux PPC64 ?
(In reply to comment #3) > Maybe... > > But I made some tests under Linux X86 and some AIX 64 bits. This code works as > expected everywhere... > So, I wonder why gcc behaviour is différent under this Linux PPC64 ? Because PPC 64 schedules code more aggressively. Anyways the code is undefined so anything can happen.