http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48197
Summary: possible wrong code bug at -O0 Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: reg...@cs.utah.edu CC: cheny...@cs.utah.edu Host: x86_64-unknown-linux-gnu Target: x86_64-unknown-linux-gnu Build: x86_64-unknown-linux-gnu Here gcc's output is the same at all optimization levels. We think the correct answer for this function is "x = 0" because all of the following statements are equivalent: x = (long)0 > ((unsigned int)0 ^ (signed short)y); x = (long)0 > ((unsigned int)0 ^ (signed short)((int)0x8000)); x = (long)0 > ((unsigned int)0 ^ (signed short)0x8000); x = (long)0 > ((unsigned)0 ^ (unsigned)0x8000); x = (long)0 > ((unsigned)0 ^ (unsigned)32768); x = (long)0 > (unsigned)32768; x = (long)0 > (long)32768; x = 0; [regehr@gamow ~]$ current-gcc -O0 small.c -o small [regehr@gamow ~]$ ./small x = 1 [regehr@gamow ~]$ cat small.c static int x = 0; static int y = 0x8000; int printf(const char *format, ...); int main (void) { x = (long)0 > ((unsigned int)0 ^ (signed short)y); printf("x = %d\n", x); return 0; } [regehr@gamow ~]$ current-gcc -v Using built-in specs. COLLECT_GCC=current-gcc COLLECT_LTO_WRAPPER=/uusoc/exports/scratch/regehr/z/compiler-install/gcc-r171139-install/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../configure --with-libelf=/usr/local --enable-lto --prefix=/home/regehr/z/compiler-install/gcc-r171139-install --program-prefix=r171139- --enable-languages=c,c++ Thread model: posix gcc version 4.7.0 20110318 (experimental) (GCC)