This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33819] [4.2/4.3 Regression] Miscompiled shift of C++ bitfield
- 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: 11 Dec 2007 14:24:32 -0000
- Subject: [Bug c++/33819] [4.2/4.3 Regression] Miscompiled shift of C++ bitfield
- References: <bug-33819-1313@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from rguenth at gcc dot gnu dot org 2007-12-11 14:24 -------
The result needs to be truncated to a type with the bitfields precision.
"
5.8 Shift operators
... integral promotions are performed. The type of the result is that
of the promoted left operand.
...
If E1 has an unsigned type, the value of the result is E1 multiplied by
the quantity 2 raised to the power E2, reduced modulo ULONG_MAX+1 if E1
has type unsigned long, UINT_MAX+1 otherwise.
"
though the latter suggests that if a non-promoted bitfield is the result,
or E1 is signed, the behavior looks unspecified.
The C99 standard looks more sane here (6.5.7/4)
"If E1 has an usinged type, the value of the result is E1 x 2^E2, reduced
modulo on emore than the maximum value representable in the result type..."
which looks like a sane semantic for at least the middle-end to adopt.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33819