http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768
Summary: C99 style union initializations does not work as expected with optimizations Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: vrahk...@gmail.com Created attachment 24779 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24779 Test code that fails with 4.6.1 and works with 4.5.3 It seems that union cannot be initialized with C99 style with 4.6.1. Attached example code works with GCC 4.5.3 but fails on assert when compiled with GCC 4.6.1. The GCC 4.6.1 seems to generate only the assert failure i.e. example compiled with -O3: 0000000000400500 <main>: 400500: 48 83 ec 08 sub $0x8,%rsp 400504: b9 2b 06 40 00 mov $0x40062b,%ecx 400509: ba 18 00 00 00 mov $0x18,%edx 40050e: be 0c 06 40 00 mov $0x40060c,%esi 400513: bf 13 06 40 00 mov $0x400613,%edi 400518: e8 cb fe ff ff callq 4003e8 <__assert_fail@plt> 40051d: 90 nop 40051e: 90 nop 40051f: 90 nop It seems that using -fno-tree-pre, -fno-tree-ccp and -fno-tree-fre with -O3 the code seems to work. Also setting the first bit in initialization seems to generate working code i.e. rest of initialization works if it's set and also setting the bits later seems to work too. ps. I'm not totally sure that if this is a regression or meant to be that way because the C-standard is not clear on this matter but following code works with GCC 4.5.3 and the assert fails with GCC 4.6.1.