regehr@home:~/volatile/bugs/tmp343$ current-gcc -O1 small.c -o small regehr@home:~/volatile/bugs/tmp343$ ./small Segmentation fault regehr@home:~/volatile/bugs/tmp343$ current-gcc -v Using built-in specs. COLLECT_GCC=current-gcc COLLECT_LTO_WRAPPER=/mnt/z/z/compiler-install/gcc-r168608-install/libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper Target: i686-pc-linux-gnu Configured with: ../configure --with-libelf=/usr/local --enable-lto --prefix=/mnt/z/z/compiler-install/gcc-r168608-install --program-prefix=r168608- --enable-languages=c,c++ Thread model: posix gcc version 4.6.0 20110109 (experimental) (GCC) regehr@home:~/volatile/bugs/tmp343$ cat small.c struct S4 { unsigned f0:24; } __attribute__((__packed__)); struct S4 g_10 = { 6210831 }; struct S4 func_2 (int x) { struct S4 l_8[2] = { {0}, {0} }; g_10 = l_8[1]; for (; x<2; x++) { struct S4 tmp = { 11936567 }; l_8[x] = tmp; } return g_10; } int main (void) { func_2 (0); return 0; }
Confirmed, fails also with -O2 -fno-inline (or marking func_2 as noinline/noclone). This is rather weird, the correct code (at the tree level even) is produced with -m64.
foo: subl $16, %esp ... ! no other esp modifications movl $11936567, 10(%esp,%ecx) #, MEM[(struct S[2] *)D.1998_9] overwrites part of the return value.
Caused by http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=164136
Yeah, clearly SRA fault, as it replaces b[x_1] = c; where both lhs and rhs is correctly type S, i.e. 3 byte packed BLKmode structure, with MEM_REF store which is SImode 4 byte.
OK, let me have a look at it then...
Created attachment 23137 [details] untested patch
Author: jamborm Date: Thu Jan 27 13:41:51 2011 New Revision: 169331 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169331 Log: 2011-01-27 Martin Jambor <mjambor@suse.cz> PR tree-optimization/47228 * tree-sra.c (sra_modify_assign): Use build_ref_for_model instead of build_ref_for_offset. * testsuite/gcc.dg/torture/pr47228.c: New test. Added: trunk/gcc/testsuite/gcc.dg/torture/pr47228.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-sra.c
Fixed.
Author: dnovillo Date: Wed Feb 2 17:57:01 2011 New Revision: 169648 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169648 Log: 2011-01-27 Martin Jambor <mjambor@suse.cz> PR tree-optimization/47228 * tree-sra.c (sra_modify_assign): Use build_ref_for_model instead of build_ref_for_offset. * testsuite/gcc.dg/torture/pr47228.c: New test. Added: branches/google/integration/gcc/testsuite/gcc.dg/torture/pr47228.c Modified: branches/google/integration/gcc/ChangeLog branches/google/integration/gcc/testsuite/ChangeLog branches/google/integration/gcc/tree-sra.c