public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vrahkone at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/49768] New: C99 style union initializations does not work as expected with optimizations
Date: Sun, 17 Jul 2011 10:41:00 -0000	[thread overview]
Message-ID: <bug-49768-4@http.gcc.gnu.org/bugzilla/> (raw)

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.


             reply	other threads:[~2011-07-17 10:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-17 10:41 vrahkone at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-49768-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).