public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/41919]  New: optimized code with -O2 or -O3 gives strange result
@ 2009-11-03  5:09 chenyang at cs dot utah dot edu
  2009-11-03 10:48 ` [Bug tree-optimization/41919] [4.5 Regression] " rguenth at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: chenyang at cs dot utah dot edu @ 2009-11-03  5:09 UTC (permalink / raw)
  To: gcc-bugs

Using r153799, got strange result with the code below. The expected result is
-104. 

yang@yang-working:~$ svngcc -O3 -o small3 small.c
yang@yang-working:~$ ./small3
2
yang@yang-working:~$ svngcc -O2 -o small2 small.c
yang@yang-working:~$ ./small2
2
yang@yang-working:~$ svngcc -O1 -o small1 small.c
yang@yang-working:~$ ./small1
-104
yang@yang-working:~$ cat small.c
#include <stdio.h>
#include <assert.h>

struct S1
{
  char f0;
};

int g_23 = 0;

static struct S1 foo (void)
{
  int *l_100 = &g_23;
  int **l_110 = &l_100;
  struct S1 l_128 = {
    1
  };
  assert (l_100 == &g_23);
  assert (l_100 == &g_23);
  assert (l_100 == &g_23);
  assert (l_100 == &g_23);
  assert (l_100 == &g_23);
  assert (l_100 == &g_23);
  assert (l_100 == &g_23);
  return l_128;
}

static char bar(char si1, char si2)
{
  return (si1 <= 0) ? si1 : (si2 * 2);
}

int main (void)
{
  struct S1 s = foo();
  printf("%d\n", bar(0x99 ^ (s.f0 && 1), 1));
  return 0;
}

yang@yang-working:~$ svngcc -v
Using built-in specs.
COLLECT_GCC=svngcc
COLLECT_LTO_WRAPPER=/home/yang/compilers/libexec/gcc/i686-pc-linux-gnu/4.5.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --enable-lto --prefix=/home/yang/compilers
--program-prefix=svn --enable-languages=c,c++
--with-libelf=/home/yang/compilers : (reconfigured) ../configure --enable-lto
--prefix=/home/yang/compilers --program-prefix=svn
--with-libelf=/home/yang/compilers --enable-languages=c,lto,c++ --no-create
--no-recursion : (reconfigured) ../configure --enable-lto
--prefix=/home/yang/compilers --program-prefix=svn
--with-libelf=/home/yang/compilers --enable-languages=c,c++,lto --no-create
--no-recursion
Thread model: posix
gcc version 4.5.0 20091102 (experimental) (GCC)


-- 
           Summary: optimized code with -O2 or -O3 gives strange result
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chenyang 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=41919


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

end of thread, other threads:[~2009-11-20 14:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-03  5:09 [Bug c/41919] New: optimized code with -O2 or -O3 gives strange result chenyang at cs dot utah dot edu
2009-11-03 10:48 ` [Bug tree-optimization/41919] [4.5 Regression] " rguenth at gcc dot gnu dot org
2009-11-03 16:06 ` rguenth at gcc dot gnu dot org
2009-11-03 16:26 ` rguenth at gcc dot gnu dot org
2009-11-03 16:41 ` rguenth at gcc dot gnu dot org
2009-11-04 10:19 ` rguenth at gcc dot gnu dot org
2009-11-04 10:24 ` rguenth at gcc dot gnu dot org
2009-11-04 10:35 ` rguenth at gcc dot gnu dot org
2009-11-20 14:52 ` hjl at gcc dot gnu dot 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).