public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/48197] New: possible wrong code bug at -O0
@ 2011-03-18 19:57 regehr at cs dot utah.edu
  2011-03-18 20:09 ` [Bug c/48197] " pinskia at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: regehr at cs dot utah.edu @ 2011-03-18 19:57 UTC (permalink / raw)
  To: gcc-bugs

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)


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-05-05 10:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-18 19:57 [Bug c/48197] New: possible wrong code bug at -O0 regehr at cs dot utah.edu
2011-03-18 20:09 ` [Bug c/48197] " pinskia at gcc dot gnu.org
2011-03-18 20:12 ` jakub at gcc dot gnu.org
2011-03-18 20:12 ` regehr at cs dot utah.edu
2011-03-18 20:20 ` regehr at cs dot utah.edu
2011-03-18 20:20 ` regehr at cs dot utah.edu
2011-03-18 22:23 ` regehr at cs dot utah.edu
2011-03-18 22:37 ` jakub at gcc dot gnu.org
2011-03-19 12:09 ` jakub at gcc dot gnu.org
2011-03-19 12:35 ` jakub at gcc dot gnu.org
2011-03-19 14:22 ` rguenth at gcc dot gnu.org
2011-03-19 15:16 ` jakub at gcc dot gnu.org
2011-03-19 15:35 ` jakub at gcc dot gnu.org
2011-03-21 18:20 ` jakub at gcc dot gnu.org
2011-03-26 10:49 ` jakub at gcc dot gnu.org
2011-05-05 10:47 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).