Hello,
Here is a small sample to repeat the case:
#include
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.00
>> 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.
--
Summary: Strange results with cast when using -O2 flag or not
under Linux ppc64
Product: gcc
Version: 3.4.4
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: fm at 4js dot com
GCC build triplet: powerpc64-linux RedHat 4.0
GCC host triplet: powerpc64-ibm
GCC target triplet: powerpc64-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25692