public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26534]  New: bitfield wrong optimize
@ 2006-03-02 21:23 s__nakayama at infoseek dot jp
  2006-03-02 21:35 ` [Bug tree-optimization/26534] [4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: s__nakayama at infoseek dot jp @ 2006-03-02 21:23 UTC (permalink / raw)
  To: gcc-bugs

#include <stdio.h>
struct X
{
  unsigned a:4;
};

int main()
{
  struct X x = { 63u };
  printf("%u\n", x.a);
  return 0;
}
// end.

result:
g++    bug.cpp; ./a 
15

g++ -O bug.cpp; ./a
63
wrong result!!


-- 
           Summary: bitfield wrong optimize
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: s__nakayama at infoseek dot jp


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


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

* [Bug tree-optimization/26534] [4.1/4.2 Regression] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
@ 2006-03-02 21:35 ` pinskia at gcc dot gnu dot org
  2006-03-03 12:07 ` [Bug c++/26534] " rguenth at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-02 21:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-03-02 21:35 -------
Confirmed, I don't know if this really a front-end issue or a tree opt issue as
we get in cpp:
  x.a = 63;
  D.2483_3 = x.a;

And then in FRE:
  x.a = 63;
  D.2483_3 = 63;

But x.a is not a full integer (there should be an and somewhere).

Note this does not have a problem in 4.0.x because FRE did not exist (well it
did) and PRE did not do stuff based on loads.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
          Component|c++                         |tree-optimization
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2006-03-02 21:35:03
               date|                            |
            Summary|bitfield wrong optimize     |[4.1/4.2 Regression]
                   |                            |bitfield wrong optimize
   Target Milestone|---                         |4.1.1


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


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

* [Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
  2006-03-02 21:35 ` [Bug tree-optimization/26534] [4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
@ 2006-03-03 12:07 ` rguenth at gcc dot gnu dot org
  2006-04-08 18:56 ` pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-03-03 12:07 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1985 bytes --]



------- Comment #2 from rguenth at gcc dot gnu dot org  2006-03-03 12:07 -------
The C frontend warns:

t.c: In function ‘main’:
t.c:9: warning: large integer implicitly truncated to unsigned type


and has in .gimple:

main ()
{
  <unnamed type> D.1770;
  int D.1771;
  int D.1772;
  struct X x;

  x.a = 15;
  D.1770 = x.a;
  D.1771 = (int) D.1770;
  printf (&"%u\n"[0], D.1771);
  D.1772 = 0;
  return D.1772;
}

The C++ fronted does not warn and creates:

  unsigned int D.2483;
  int D.2484;

  {
    struct X x;

    x.a = 63;
    D.2483 = x.a;

where it should have truncated the constant, as the type as far as the
middle-end is concerned of x.a is

(gdb) call debug_tree(0x402474ac)
 <field_decl 0x402474ac a
    type <integer_type 0x4019e2e0 unsigned int public unsigned SI
        size <integer_cst 0x4018d3d8 constant invariant 32>
        unit size <integer_cst 0x4018d168 constant invariant 4>
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0x4018d450
0> max <integer_cst 0x4018d438 4294967295>>
    used unsigned external nonlocal bit-field nonaddressable decl_3 decl_4 SI
file t.C line 3
    size <integer_cst 0x40211af8 type <integer_type 0x4019e05c bit_size_type>
constant invariant 4>
    unit size <integer_cst 0x4018d1f8 type <integer_type 0x4019e000 unsigned
int> constant invariant 1>
    align 1 offset_align 128
    offset <integer_cst 0x4018d180 type <integer_type 0x4019e000 unsigned int>
constant invariant 0>
    bit offset <integer_cst 0x4018d948 type <integer_type 0x4019e05c
bit_size_type> constant invariant 0> context <record_type 0x40247450 X> chain
<type_decl 0x402149c0 X>>

i.e., only the FIELD_DECL knows about the correct precision.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |c++


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


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

* [Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
  2006-03-02 21:35 ` [Bug tree-optimization/26534] [4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
  2006-03-03 12:07 ` [Bug c++/26534] " rguenth at gcc dot gnu dot org
@ 2006-04-08 18:56 ` pinskia at gcc dot gnu dot org
  2006-04-16 18:41 ` mmitchel at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-08 18:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-04-08 18:56 -------
*** Bug 27083 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |falk at debian dot org


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


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

* [Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
                   ` (2 preceding siblings ...)
  2006-04-08 18:56 ` pinskia at gcc dot gnu dot org
@ 2006-04-16 18:41 ` mmitchel at gcc dot gnu dot org
  2006-04-18 15:27 ` bonzini at gnu dot org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-04-16 18:41 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1


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


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

* [Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
                   ` (3 preceding siblings ...)
  2006-04-16 18:41 ` mmitchel at gcc dot gnu dot org
@ 2006-04-18 15:27 ` bonzini at gnu dot org
  2006-04-19 17:12 ` mmitchel at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bonzini at gnu dot org @ 2006-04-18 15:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bonzini at gnu dot org  2006-04-18 15:27 -------
And is the precision only encoded in FIELD_DECLs, for the C front-end as well?


-- 

bonzini at gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bonzini at gnu dot org


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


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

* [Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
                   ` (4 preceding siblings ...)
  2006-04-18 15:27 ` bonzini at gnu dot org
@ 2006-04-19 17:12 ` mmitchel at gcc dot gnu dot org
  2006-04-22 22:14 ` mmitchel at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-04-19 17:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from mmitchel at gcc dot gnu dot org  2006-04-19 17:11 -------
In C++ the type of the FIELD_DECL should be "unsigned int", not "4-bit unsigned
int".  So, this is the usual problem that we don't quite know how "lowered" the
representation shared across the front-end and back-end should be.

What I would prefer to do is to fix the C++ front-end so that "x.a = y" becomes
"x.a = y & 0xf".  Would that work for the back-end, or will it still be
confused by the fact that we have bit-field with a type whose precision is
greater than that of the field?


-- 


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


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

* [Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
                   ` (5 preceding siblings ...)
  2006-04-19 17:12 ` mmitchel at gcc dot gnu dot org
@ 2006-04-22 22:14 ` mmitchel at gcc dot gnu dot org
  2006-04-23  3:16 ` mmitchel at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-04-22 22:14 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |mark at codesourcery dot com
                   |dot org                     |
             Status|NEW                         |ASSIGNED


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


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

* [Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
                   ` (6 preceding siblings ...)
  2006-04-22 22:14 ` mmitchel at gcc dot gnu dot org
@ 2006-04-23  3:16 ` mmitchel at gcc dot gnu dot org
  2006-04-23 18:04 ` mmitchel at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-04-23  3:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from mmitchel at gcc dot gnu dot org  2006-04-23 03:16 -------
Generating the explicit masking operations in the front end seems to be safe,
but suboptimal.  The middle-end will not optimize code like: 

  struct A {int i : 3; };
  struct A a;
  int f() { return a.i > 3; } // Always false

unless the type of the expression "a.i" has the correct precision.  When
compiled as C code, this function is optimized appropriately, because the C
front-end uses limited-precision types to represent bitfields.


-- 


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


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

* [Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
                   ` (7 preceding siblings ...)
  2006-04-23  3:16 ` mmitchel at gcc dot gnu dot org
@ 2006-04-23 18:04 ` mmitchel at gcc dot gnu dot org
  2006-04-23 18:05 ` [Bug c++/26534] [4.1] " mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-04-23 18:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from mmitchel at gcc dot gnu dot org  2006-04-23 18:04 -------
Subject: Bug 26534

Author: mmitchel
Date: Sun Apr 23 18:04:33 2006
New Revision: 113199

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113199
Log:
2006-04-23  Mark Mitchell  <mark@codesourcery.com>

        PR c++/26534
        * c-common.h (c_build_bitfield_integer_type): Declare.
        * c-decl.c (c_build_bitfield_integer_type): Move to ...
        * c-common.c (c_build_bitfield_integer_type): ... here.

2006-04-23  Mark Mitchell  <mark@codesourcery.com>

        PR c++/26534
        * cp-tree.h (is_bitfield_expr_with_lowered_type): New function.
        * typeck.c (is_bitfield_expr_with_lowered_type): New function.
        (decay_conversion): Convert bitfield expressions to the correct
        type.
        (build_modify_expr): Remove spurious conversions.
        * class.c (layout_class_type): Modify the type of bitfields to
        indicate a limited range. 
        * call.c (standard_conversion): Adjust the type of bitfield
        expressions used in an rvalue context.
        (build_conditional_expr): Likewise.

2006-04-23  Mark Mitchell  <mark@codesourcery.com>

        PR c++/26534
        * g++.dg/opt/bitfield1.C: New test.
        * g++.dg/compat/abi/bitfield1_main.C: Add -w.
        * g++.dg/compat/abi/bitfield1_x.C: Likewise.
        * g++.dg/compat/abi/bitfield1_y.C: Likewise.
        * g++.dg/compat/abi/bitfield2_main.C: Likewise.
        * g++.dg/compat/abi/bitfield2_x.C: Likewise.
        * g++.dg/compat/abi/bitfield2_y.C: Likewise.
        * g++.dg/abi/bitfield1.C: Add dg-warning markers.
        * g++.dg/abi/bitfield2.C: Likewise.
        * g++.dg/init/bitfield1.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/opt/bitfield1.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/c-common.h
    trunk/gcc/c-decl.c
    trunk/gcc/configure
    trunk/gcc/configure.ac
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/class.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/typeck.c
    trunk/gcc/print-tree.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/abi/bitfield1.C
    trunk/gcc/testsuite/g++.dg/abi/bitfield2.C
    trunk/gcc/testsuite/g++.dg/compat/abi/bitfield1_main.C
    trunk/gcc/testsuite/g++.dg/compat/abi/bitfield1_x.C
    trunk/gcc/testsuite/g++.dg/compat/abi/bitfield1_y.C
    trunk/gcc/testsuite/g++.dg/compat/abi/bitfield2_main.C
    trunk/gcc/testsuite/g++.dg/compat/abi/bitfield2_x.C
    trunk/gcc/testsuite/g++.dg/compat/abi/bitfield2_y.C
    trunk/gcc/testsuite/g++.dg/init/bitfield1.C


-- 


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


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

* [Bug c++/26534] [4.1] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
                   ` (8 preceding siblings ...)
  2006-04-23 18:04 ` mmitchel at gcc dot gnu dot org
@ 2006-04-23 18:05 ` mmitchel at gcc dot gnu dot org
  2006-05-01  2:18 ` mmitchel at gcc dot gnu dot org
  2006-05-01  2:18 ` mmitchel at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-04-23 18:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from mmitchel at gcc dot gnu dot org  2006-04-23 18:05 -------
Fixed in GCC 4.2.


-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[4.1/4.2 Regression]        |[4.1] bitfield wrong
                   |bitfield wrong optimize     |optimize


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


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

* [Bug c++/26534] [4.1] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
                   ` (9 preceding siblings ...)
  2006-04-23 18:05 ` [Bug c++/26534] [4.1] " mmitchel at gcc dot gnu dot org
@ 2006-05-01  2:18 ` mmitchel at gcc dot gnu dot org
  2006-05-01  2:18 ` mmitchel at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-05-01  2:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from mmitchel at gcc dot gnu dot org  2006-05-01 02:18 -------
Fixed in 4.1.1.


-- 

mmitchel at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/26534] [4.1] bitfield wrong optimize
  2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
                   ` (10 preceding siblings ...)
  2006-05-01  2:18 ` mmitchel at gcc dot gnu dot org
@ 2006-05-01  2:18 ` mmitchel at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-05-01  2:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from mmitchel at gcc dot gnu dot org  2006-05-01 02:18 -------
Subject: Bug 26534

Author: mmitchel
Date: Mon May  1 02:18:14 2006
New Revision: 113407

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113407
Log:
        PR c++/26534
        * cp-tree.h (adjust_bitfield_initializer): Declare.
        * typeck.c (build_modify_expr): Use it.
        * typeck2.c (adjust_bitfield_initializer): Define.
        (process_init_constructor_record): Use it.
        PR c++/26534
        * g++.dg/opt/bitfield1.C: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/opt/bitfield1.C
Modified:
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/cp-tree.h
    branches/gcc-4_1-branch/gcc/cp/typeck.c
    branches/gcc-4_1-branch/gcc/cp/typeck2.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog


-- 


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


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

end of thread, other threads:[~2006-05-01  2:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-02 21:23 [Bug c++/26534] New: bitfield wrong optimize s__nakayama at infoseek dot jp
2006-03-02 21:35 ` [Bug tree-optimization/26534] [4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-03-03 12:07 ` [Bug c++/26534] " rguenth at gcc dot gnu dot org
2006-04-08 18:56 ` pinskia at gcc dot gnu dot org
2006-04-16 18:41 ` mmitchel at gcc dot gnu dot org
2006-04-18 15:27 ` bonzini at gnu dot org
2006-04-19 17:12 ` mmitchel at gcc dot gnu dot org
2006-04-22 22:14 ` mmitchel at gcc dot gnu dot org
2006-04-23  3:16 ` mmitchel at gcc dot gnu dot org
2006-04-23 18:04 ` mmitchel at gcc dot gnu dot org
2006-04-23 18:05 ` [Bug c++/26534] [4.1] " mmitchel at gcc dot gnu dot org
2006-05-01  2:18 ` mmitchel at gcc dot gnu dot org
2006-05-01  2:18 ` mmitchel at gcc dot gnu dot org

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