@@ -1831,9 +1831,13 @@ impl<'a> ConstantEvaluator<'a> {
1831
1831
_ => return Err ( ConstantEvaluatorError :: InvalidBinaryOpArgs ) ,
1832
1832
} ) ,
1833
1833
( Literal :: I32 ( a) , Literal :: U32 ( b) ) => Literal :: I32 ( match op {
1834
- BinaryOperator :: ShiftLeft => a
1835
- . checked_shl ( b)
1836
- . ok_or ( ConstantEvaluatorError :: ShiftedMoreThan32Bits ) ?,
1834
+ BinaryOperator :: ShiftLeft => {
1835
+ if ( if a. is_negative ( ) { !a } else { a } ) . leading_zeros ( ) <= b {
1836
+ return Err ( ConstantEvaluatorError :: Overflow ( "<<" . to_string ( ) ) ) ;
1837
+ }
1838
+ a. checked_shl ( b)
1839
+ . ok_or ( ConstantEvaluatorError :: ShiftedMoreThan32Bits ) ?
1840
+ }
1837
1841
BinaryOperator :: ShiftRight => a
1838
1842
. checked_shr ( b)
1839
1843
. ok_or ( ConstantEvaluatorError :: ShiftedMoreThan32Bits ) ?,
@@ -1859,8 +1863,11 @@ impl<'a> ConstantEvaluator<'a> {
1859
1863
BinaryOperator :: ExclusiveOr => a ^ b,
1860
1864
BinaryOperator :: InclusiveOr => a | b,
1861
1865
BinaryOperator :: ShiftLeft => a
1862
- . checked_shl ( b)
1863
- . ok_or ( ConstantEvaluatorError :: ShiftedMoreThan32Bits ) ?,
1866
+ . checked_mul (
1867
+ 1u32 . checked_shl ( b)
1868
+ . ok_or ( ConstantEvaluatorError :: ShiftedMoreThan32Bits ) ?,
1869
+ )
1870
+ . ok_or ( ConstantEvaluatorError :: Overflow ( "<<" . to_string ( ) ) ) ?,
1864
1871
BinaryOperator :: ShiftRight => a
1865
1872
. checked_shr ( b)
1866
1873
. ok_or ( ConstantEvaluatorError :: ShiftedMoreThan32Bits ) ?,
0 commit comments