Permalink
Browse files

Shift ops have LHS' type after int promotion.

It was a bug to treat left-shift and right-shift operators as if they
followed the usual arithmetic conversions.

Found with csmith and creduce.
  • Loading branch information...
jameysharp committed Jul 14, 2016
1 parent 8d32882 commit 3fd904058abe334b0a9e0e106011c843cf1b0eb7
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/Language/Rust/Corrode/C.md
@@ -1881,8 +1881,8 @@ binop expr op lhs rhs = fmap wrapping $ case op of
(IsPtr _ _, IsPtr _ _) -> unimplemented expr
(IsPtr _ _, _) -> return lhs { result = Rust.MethodCall (result lhs) (Rust.VarName "offset") [Rust.Neg (castTo (IsInt Signed WordWidth) rhs)] }
_ -> promote expr Rust.Sub lhs rhs
CShlOp -> promote expr Rust.ShiftL lhs rhs
CShrOp -> promote expr Rust.ShiftR lhs rhs
CShlOp -> shift Rust.ShiftL
CShrOp -> shift Rust.ShiftR
CLeOp -> comparison Rust.CmpLT
CGrOp -> comparison Rust.CmpGT
CLeqOp -> comparison Rust.CmpLE
@@ -1895,6 +1895,14 @@ binop expr op lhs rhs = fmap wrapping $ case op of
CLndOp -> return Result { resultType = IsBool, isMutable = Rust.Immutable, result = Rust.LAnd (toBool lhs) (toBool rhs) }
CLorOp -> return Result { resultType = IsBool, isMutable = Rust.Immutable, result = Rust.LOr (toBool lhs) (toBool rhs) }
where
shift op' = return Result
{ resultType = lhsTy
, isMutable = Rust.Immutable
, result = op' (castTo lhsTy lhs) (castTo rhsTy rhs)
}
where
lhsTy = intPromote (resultType lhs)
rhsTy = intPromote (resultType rhs)
comparison op' = case (resultType lhs, resultType rhs) of
(IsPtr _ _, IsPtr _ _) -> return (promotePtr op' lhs rhs)
_ -> do

0 comments on commit 3fd9040

Please sign in to comment.