File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -258,8 +258,10 @@ pub fn trans_checked_int_binop<'tcx>(
258
258
}
259
259
BinOp :: Shl => {
260
260
let val = fx. bcx . ins ( ) . ishl ( lhs, rhs) ;
261
- // TODO: check for overflow
262
- let has_overflow = fx. bcx . ins ( ) . bconst ( types:: B1 , false ) ;
261
+ let ty = fx. bcx . func . dfg . value_type ( val) ;
262
+ let max_shift = i64:: from ( ty. bits ( ) ) - 1 ;
263
+ let has_overflow =
264
+ fx. bcx . ins ( ) . icmp_imm ( IntCC :: UnsignedGreaterThan , rhs, max_shift) ;
263
265
( val, has_overflow)
264
266
}
265
267
BinOp :: Shr => {
@@ -268,8 +270,10 @@ pub fn trans_checked_int_binop<'tcx>(
268
270
} else {
269
271
fx. bcx . ins ( ) . sshr ( lhs, rhs)
270
272
} ;
271
- // TODO: check for overflow
272
- let has_overflow = fx. bcx . ins ( ) . bconst ( types:: B1 , false ) ;
273
+ let ty = fx. bcx . func . dfg . value_type ( val) ;
274
+ let max_shift = i64:: from ( ty. bits ( ) ) - 1 ;
275
+ let has_overflow =
276
+ fx. bcx . ins ( ) . icmp_imm ( IntCC :: UnsignedGreaterThan , rhs, max_shift) ;
273
277
( val, has_overflow)
274
278
}
275
279
_ => bug ! (
You can’t perform that action at this time.
0 commit comments