I believe that the program below is well-formed and that it is miscompiled by
r148318 at -Os.

reg...@john-home:~$ cat foo.c
#include <stdio.h>

int foo(int y)
{
  return (((unsigned short)y*(unsigned short)-2)>=(y?0:y));
}

int main (void)
{
  printf ("%d\n", foo(-2));
  return 0;
}
reg...@john-home:~$ current-gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/home/regehr/z/tmp/gcc-r148318-install
--program-prefix=r148318- --enable-languages=c,c++
Thread model: posix
gcc version 4.5.0 20090609 (experimental) (GCC) 
reg...@john-home:~$ current-gcc -Os foo.c -o foo
reg...@john-home:~$ ./foo
1
reg...@john-home:~$ current-gcc -O0 foo.c -o foo
reg...@john-home:~$ ./foo
0
reg...@john-home:~$ gcc-4.1 -Os foo.c -o foo
reg...@john-home:~$ ./foo
0
reg...@john-home:~$ gcc-4.2 -Os foo.c -o foo
reg...@john-home:~$ ./foo
0
reg...@john-home:~$ icc -Os foo.c -o foo
reg...@john-home:~$ ./foo
0


-- 
           Summary: possible integer wrong code bug
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: regehr at cs dot utah dot edu
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40390

Reply via email to