public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/49768] New: C99 style union initializations does not work as expected with optimizations
@ 2011-07-17 10:41 vrahkone at gmail dot com
  2011-07-17 12:47 ` [Bug c/49768] " mikpe at it dot uu.se
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: vrahkone at gmail dot com @ 2011-07-17 10:41 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: vrahkone@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.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-08-24 10:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-17 10:41 [Bug c/49768] New: C99 style union initializations does not work as expected with optimizations vrahkone at gmail dot com
2011-07-17 12:47 ` [Bug c/49768] " mikpe at it dot uu.se
2011-07-17 18:23 ` mikpe at it dot uu.se
2011-07-17 22:01 ` [Bug c/49768] [4.6/4.7 Regression] " jakub at gcc dot gnu.org
2011-07-17 22:11 ` jakub at gcc dot gnu.org
2011-07-18  8:48 ` rguenth at gcc dot gnu.org
2011-07-18 12:48 ` [Bug tree-optimization/49768] " jakub at gcc dot gnu.org
2011-07-19  9:24 ` jakub at gcc dot gnu.org
2011-07-19  9:41 ` jakub at gcc dot gnu.org
2011-07-19  9:42 ` jakub at gcc dot gnu.org
2011-08-04 13:45 ` vrahkone at gmail dot com
2011-08-24 10:37 ` sebastian.huber@embedded-brains.de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).