GCC 4.9.0 for x86_64 miscompiles the following code. $ cat error.c struct S0 { short m0; short m1; }; struct S1 { unsigned m0 : 1; char m1[2][2]; struct S0 m2[2]; }; struct S1 x = {1,{{1,1},{1,1}},{{1,1},{1,1}}}; struct S1 func(void) { return x; } int main(void) { struct S1 ret = func(); if( ret.m2[1].m1 != 1 ) { __builtin_abort(); } return 0; } $ gcc-4.9 error.c $ ./a.out Abort trap: 6 The value of ret.m2[1].m1 was 32767 instead of 1. There was no problem with an i686 target. $ gcc-4.9 -v Using built-in specs. COLLECT_GCC=gcc-4.9 COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc49/4.9-20140126/gcc/libexec/gcc/x86_64-apple-darwin13.0.0/4.9.0/lto-wrapper Target: x86_64-apple-darwin13.0.0 Configured with: ../configure --build=x86_64-apple-darwin13.0.0 --prefix=/usr/local/Cellar/gcc49/4.9-20140126/gcc --datarootdir=/usr/local/Cellar/gcc49/4.9-20140126/share --bindir=/usr/local/Cellar/gcc49/4.9-20140126/bin --enable-languages=c --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-plugin --enable-lto --disable-werror --disable-nls --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk Thread model: posix gcc version 4.9.0 20140126 (experimental) (GCC)
Started with r142059.
I have a patch.
Patch at [1]. [1] http://gcc.gnu.org/ml/gcc-patches/2014-02/msg00027.html
Author: uros Date: Sun Feb 2 15:35:53 2014 New Revision: 207399 URL: http://gcc.gnu.org/viewcvs?rev=207399&root=gcc&view=rev Log: PR target/60017 * config/i386/i386.c (classify_argument): Fix handling of bit_offset when calculating size of integer atomic types. testsuite/ChangeLog: PR target/60017 * gcc.c-torture/execute/pr60017.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr60017.c Modified: trunk/gcc/ChangeLog trunk/gcc/config/i386/i386.c trunk/gcc/testsuite/ChangeLog
Author: uros Date: Tue Feb 4 16:43:00 2014 New Revision: 207475 URL: http://gcc.gnu.org/viewcvs?rev=207475&root=gcc&view=rev Log: Backport from mainline 2014-02-02 Uros Bizjak <ubizjak@gmail.com> PR target/60017 * config/i386/i386.c (classify_argument): Fix handling of bit_offset when calculating size of integer atomic types. testsuite/ChangeLog: Backport from mainline 2014-02-02 Uros Bizjak <ubizjak@gmail.com> PR target/60017 * gcc.c-torture/execute/pr60017.c: New test. Added: branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr60017.c Modified: branches/gcc-4_8-branch/gcc/ChangeLog branches/gcc-4_8-branch/gcc/config/i386/i386.c branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
Author: uros Date: Tue Feb 4 16:46:06 2014 New Revision: 207476 URL: http://gcc.gnu.org/viewcvs?rev=207476&root=gcc&view=rev Log: Backport from mainline 2014-02-02 Uros Bizjak <ubizjak@gmail.com> PR target/60017 * config/i386/i386.c (classify_argument): Fix handling of bit_offset when calculating size of integer atomic types. testsuite/ChangeLog Backport from mainline 2014-02-02 Uros Bizjak <ubizjak@gmail.com> PR target/60017 * gcc.c-torture/execute/pr60017.c: New test. Added: branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr60017.c Modified: branches/gcc-4_7-branch/gcc/ChangeLog branches/gcc-4_7-branch/gcc/config/i386/i386.c branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Fixed everywhere.