This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Mar 2006 12:07:27 -0000
- Subject: [Bug c++/26534] [4.1/4.2 Regression] bitfield wrong optimize
- References: <bug-26534-10812@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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