From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20081 invoked by alias); 16 May 2013 15:59:59 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 20019 invoked by uid 48); 16 May 2013 15:59:55 -0000 From: "dhazeghi at yahoo dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/57303] New: struct miscompiled at -O1 and above Date: Thu, 16 May 2013 15:59:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dhazeghi at yahoo dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-05/txt/msg01122.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57303 Bug ID: 57303 Summary: struct miscompiled at -O1 and above Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: dhazeghi at yahoo dot com With current gcc trunk, the code below is miscompiled at -O1 and higher optimization levels on x86_64-linux-gnu, outputting '1' instead of '0' as expected. This behavior appears in gcc 4.8.x and 4.7.x as well, but not in 4.6.x or earlier. It occurs in both 32-bit and 64-bit compiles. $ gcc-trunk -v Target: x86_64-unknown-linux-gnu Configured with: ../gcc-trunk/configure --enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-checking --with-gmp=/usr/local/gcc-trunk --with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk --with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk Thread model: posix gcc version 4.9.0 20130516 (experimental) [trunk revision 198967] (GCC) $ gcc-trunk -O0 small.c $ ./a.out 0 $ gcc-4.6 -O1 small.c $ ./a.out 0 $ gcc-trunk -O1 small.c $ ./a.out 1 $ ----------------------------- int printf(const char *, ...); struct S0 { int f0; }; struct S1 { struct S0 f0; }; struct S1 x = { {0} }; struct S1 y = { {1} }; static void foo (struct S0 p) { struct S0 *l = &y.f0; *l = x.f0; if (p.f0) *l = *l; } int main () { foo(y.f0); printf("%d\n", y.f0.f0); return 0; }