http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50235
Bug #: 50235 Summary: Wrong code with volatile bitfields and -Os Classification: Unclassified Product: gcc Version: 4.5.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: arthur.j.odw...@gmail.com Created attachment 25137 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25137 Output of "ajo-gcc -w -Os test.c -v" This failure reproduces for me with svn revision 178264 (2011-08-29), but it goes back at least as far as gcc-4.5. I'm on Ubuntu 10.10, x86-64. cat >test.c <<EOF struct S1 { unsigned f0, f1; unsigned short f2, f3; unsigned f4 : 16; unsigned f5, f6; volatile unsigned f7 : 28; }; static struct S1 g_76; static struct S1 g_245 = {0,0,0,0,0,0,0,1}; static signed char g_323 = 0x80; static void func_1(void) { g_245.f7 &= 1; for (g_323 = 0; g_323 <= -1; g_323 -= 2) { g_76 = g_76; g_76.f4 ^= 11; } } int main() { func_1(); printf("%x %x\n", (unsigned)g_323, (unsigned)g_245.f7); } EOF gcc -w -O3 test.c ; ./a.out gcc -w -Os test.c ; ./a.out With -O3, it correctly prints "0 1". With -Os, it incorrectly prints "7e 1". In trunk, -fstrict-volatile-bitfields fixes the bug --- but I don't see anything implementation-defined about this test case. It shouldn't need any special options to compile correctly. This test case is reduced from the output of Csmith 2.1.0 (git hash 01aa8b04, https://github.com/Quuxplusone/csmith/), using the following command line: csmith --no-paranoid --no-longlong --no-pointers --arrays --jumps --no-consts --volatiles --checksum --no-divs --no-muls --bitfields --no-packed-struct -s 1163880864