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

Reply via email to