Skip to content

Commit

Permalink
Move check out of the match on the intrinsic name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim committed Sep 6, 2018
1 parent 58af73c commit 92dd526
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/librustc_mir/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,14 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
let r_ty = substs.type_at(0);
let r_layout_of = self.layout_of(r_ty)?;
let r_val = r.to_scalar()?.to_bits(r_layout_of.size)?;
if r_val >= bits {
return err!(Intrinsic(
format!("Overflowing shift by {} in {}", r_val, intrinsic_name),
));
}
let bin_op = match intrinsic_name {
"unchecked_shl" => {
if r_val >= bits {
return err!(Intrinsic(
format!("Overflowing shift by {} in unchecked_shl", r_val),
));
}
BinOp::Shl
},
"unchecked_shr" => {
if r_val >= bits {
return err!(Intrinsic(
format!("Overflowing shift by {} in unchecked_shr", r_val),
));
}
BinOp::Shr
},
"unchecked_shl" => BinOp::Shl,
"unchecked_shr" => BinOp::Shr,
_ => bug!("Already checked for int ops")
};
self.binop_ignore_overflow(bin_op, l, r, dest)?;
Expand Down

0 comments on commit 92dd526

Please sign in to comment.