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

* [Bug c/49768] C99 style union initializations does not work as expected with optimizations
  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 ` mikpe at it dot uu.se
  2011-07-17 18:23 ` mikpe at it dot uu.se
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mikpe at it dot uu.se @ 2011-07-17 12:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

--- Comment #1 from Mikael Pettersson <mikpe at it dot uu.se> 2011-07-17 12:47:17 UTC ---
Created attachment 24780
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24780
reduced test case

This reduced test case doesn't use any union, just a struct with two one-bit
fields, and fails at -O1 and above with 4.6 and 4.7 on i686-linux.  Looking at
the generated code, gcc has removed all runtime checks and just inserted a call
to abort.

/* pr49768.c */

int main(void)
{
    static struct {
        unsigned int :1;
        unsigned int test_bit2:1;
    } test = {
        .test_bit2 = 1,
    };

    if (test.test_bit2 != 1)
        __builtin_abort();

    return 0;
}


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

* [Bug c/49768] C99 style union initializations does not work as expected with optimizations
  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
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mikpe at it dot uu.se @ 2011-07-17 18:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

Mikael Pettersson <mikpe at it dot uu.se> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |mikpe at it dot uu.se

--- Comment #2 from Mikael Pettersson <mikpe at it dot uu.se> 2011-07-17 18:22:21 UTC ---
It started with r164688:

Author: hubicka
Date: Tue Sep 28 16:28:39 2010
New Revision: 164688

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=164688
Log:
    * tree-ssa-ccp.c (fold_ctor_reference): New function.
    (fold_const_aggregate_ref): Use it.
    * fold-const.c (canonicalize_constructor_val): Check that we don't fold
    into external static.

The dumps from r164687 and r164688 start to differ in pr49768.c.061t.ccp2, when
r164688 removes the runtime check and the static object, and makes the abort()
call unconditional.

Removing the unused initial padding bit field unbreaks the test case.


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

* [Bug c/49768] [4.6/4.7 Regression] C99 style union initializations does not work as expected with optimizations
  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 ` jakub at gcc dot gnu.org
  2011-07-17 22:11 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-17 22:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.07.17 22:00:08
                 CC|                            |jakub at gcc dot gnu.org
   Target Milestone|---                         |4.6.2
            Summary|C99 style union             |[4.6/4.7 Regression] C99
                   |initializations does not    |style union initializations
                   |work as expected with       |does not work as expected
                   |optimizations               |with optimizations
     Ever Confirmed|0                           |1

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-17 22:00:08 UTC ---
Confirmed.


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

* [Bug c/49768] [4.6/4.7 Regression] C99 style union initializations does not work as expected with optimizations
  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
                   ` (2 preceding siblings ...)
  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
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-17 22:11 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |jakub at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-17 22:10:40 UTC ---
fold_nonarray_ctor_reference is buggy, it seems to consider only fields where
offset is within bitoffset .. bitoffset_end range.  But here offset is 0, size
is 8 and bitoffset is 1 and bitoffset_end 2.  These overlap, thus either
fold_nonarray_ctor_reference should give up (return NULL), or it should try to
reconstruct it from multiple fields.


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

* [Bug c/49768] [4.6/4.7 Regression] C99 style union initializations does not work as expected with optimizations
  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
                   ` (3 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-07-18  8:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-18 08:47:01 UTC ---
I suppose fold produces some BIT_FIELD_REF here, giving up probably is
easiest for now.


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

* [Bug tree-optimization/49768] [4.6/4.7 Regression] C99 style union initializations does not work as expected with optimizations
  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
                   ` (4 preceding siblings ...)
  2011-07-18  8:48 ` rguenth at gcc dot gnu.org
@ 2011-07-18 12:48 ` jakub at gcc dot gnu.org
  2011-07-19  9:24 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-18 12:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-18 12:47:36 UTC ---
Created attachment 24787
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24787
gcc47-pr49768.patch

The easier fix attached.  The more complicated would probably mean if we see
possible overlaps keeping recurding on all overlapping feelds and if the result
from them is INTEGER_CST, shift, mask and or them together.


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

* [Bug tree-optimization/49768] [4.6/4.7 Regression] C99 style union initializations does not work as expected with optimizations
  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
                   ` (5 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-19  9:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-19 09:24:31 UTC ---
Author: jakub
Date: Tue Jul 19 09:24:28 2011
New Revision: 176437

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176437
Log:
    PR tree-optimization/49768
    * gimple-fold.c (fold_nonarray_ctor_reference): Return NULL
    if offset is smaller than bitoffset, but offset+size is bigger
    than bitoffset.

    * gcc.c-torture/execute/pr49768.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr49768.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-fold.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug tree-optimization/49768] [4.6/4.7 Regression] C99 style union initializations does not work as expected with optimizations
  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
                   ` (6 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-19  9:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-19 09:40:57 UTC ---
Fixed.


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

* [Bug tree-optimization/49768] [4.6/4.7 Regression] C99 style union initializations does not work as expected with optimizations
  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
                   ` (7 preceding siblings ...)
  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
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-19  9:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-19 09:40:05 UTC ---
Author: jakub
Date: Tue Jul 19 09:40:03 2011
New Revision: 176438

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176438
Log:
    PR tree-optimization/49768
    * tree-ssa-ccp.c (fold_nonarray_ctor_reference): Return NULL
    if offset is smaller than bitoffset, but offset+size is bigger
    than bitoffset.

    * gcc.c-torture/execute/pr49768.c: New test.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.c-torture/execute/pr49768.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/gcc/tree-ssa-ccp.c


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

* [Bug tree-optimization/49768] [4.6/4.7 Regression] C99 style union initializations does not work as expected with optimizations
  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
                   ` (8 preceding siblings ...)
  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
  10 siblings, 0 replies; 12+ messages in thread
From: vrahkone at gmail dot com @ 2011-08-04 13:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

--- Comment #10 from Valtteri Rahkonen <vrahkone at gmail dot com> 2011-08-04 13:44:38 UTC ---
I tested latest gcc 4.6.1 from Debian unstable containing the patch and it
seems to work. I'm not going to dare to mark this as verified though because I
don't know your bugzilla policies ;).

Thanks.


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

* [Bug tree-optimization/49768] [4.6/4.7 Regression] C99 style union initializations does not work as expected with optimizations
  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
                   ` (9 preceding siblings ...)
  2011-08-04 13:45 ` vrahkone at gmail dot com
@ 2011-08-24 10:37 ` sebastian.huber@embedded-brains.de
  10 siblings, 0 replies; 12+ messages in thread
From: sebastian.huber@embedded-brains.de @ 2011-08-24 10:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49768

Sebastian Huber <sebastian.huber@embedded-brains.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sebastian.huber@embedded-br
                   |                            |ains.de

--- Comment #11 from Sebastian Huber <sebastian.huber@embedded-brains.de> 2011-08-24 10:34:05 UTC ---
*** Bug 49119 has been marked as a duplicate of this bug. ***


^ 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).