[cfe-dev] mixed types with BO_Sh[rl]
Chris Lattner
clattner at apple.com
Thu Jan 27 10:06:13 PST 2011
On Jan 27, 2011, at 3:19 AM, Roman Divacky wrote:
> hi,
>
> in a simple expression like:
>
> unsigned int _x;
>
> return (_x >> 30);
>
> the BinaryOperator is formed like this:
>
> (BinaryOperator 0x8018dc1a0 'unsigned int' '>>'
> (DeclRefExpr 0x8018dc140 'unsigned int' lvalue Var='_x' 0x80188ff70)
> (IntegerLiteral 0x8018dc170 'int' 30))
>
> note the mixed operands with 'unsigned int' and 'int' types.
>
> Is this by design or by mistake? I guess there should be IntegralCast
> for the 'int' 30, right? This happens only for Shr/Shl operators,
> all others have the IntegralCast I would expect here.
Hi Roman,
This is actually by design. C doesn't constrain the shift amount to be the same type as the LHS of the shift.
-Chris
More information about the cfe-dev
mailing list