This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/48197] New: possible wrong code bug at -O0
- From: "regehr at cs dot utah.edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 18 Mar 2011 19:52:51 +0000
- Subject: [Bug c/48197] New: possible wrong code bug at -O0
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: regehr@cs.utah.edu
CC: chenyang@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)