This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Possible bug in optimization


Here is a simple prog that I think might illustrate a bug in gcc-3.2.1/2
optimization:

#include <stdio.h>
int main(int argc, char **argv)
{
  long long val = 0x4000000000000001;
  (((int*) &val)[1]) &= 0x0;
  printf("%lld\n", val);
  return 1;
}

This bit wise operation shows two different results when run with/out
optimization as follows:

gcc -O0 -static -save-temps toto2.c -o toto2-O0
gcc -O2 -static -save-temps toto2.c -o toto2-O2
gcc -O1 -static -save-temps toto2.c -o toto2-O1
gcc -g -static -save-temps toto2.c -o toto2-g

[~]$ ./toto2-O0
1
[~]$ ./toto2-O1
1
[~]$ ./toto2-O2
4611686018427387905
[~]$ ./toto2-g
1 

Using gcc 3.2.2 and gcc3.2.1 (release) on AMD Athlon and Xeon (i686).
Built using: --enable-languages=c,c++ --prefix=/usr/local/gcc322

If someone tell me what I have done wrong, I would really appreciate it.

TIA,
Chris
 


-- 
Chris Croswhite <ccroswhite@get2chip.com>
Get2Chip, Inc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]