Skip to content

Commit

Permalink
Use binary_op_val instead of doing the check manually.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim committed Sep 6, 2018
1 parent 92dd526 commit 43eb925
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/librustc_mir/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,22 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
}
}
"unchecked_shl" | "unchecked_shr" => {
let bits = dest.layout.size.bytes() as u128 * 8;
let l = self.read_value(args[0])?;
let r = self.read_value(args[1])?;
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" => BinOp::Shl,
"unchecked_shr" => BinOp::Shr,
_ => bug!("Already checked for int ops")
};
self.binop_ignore_overflow(bin_op, l, r, dest)?;
let (val, overflowed) = self.binary_op_val(bin_op, l, r)?;
if overflowed {
let layout = self.layout_of(substs.type_at(0))?;
let r_val = r.to_scalar()?.to_bits(layout.size)?;
return err!(Intrinsic(
format!("Overflowing shift by {} in {}", r_val, intrinsic_name),
));
}
self.write_scalar(val, dest)?;
}
"transmute" => {
// Go through an allocation, to make sure the completely different layouts
Expand Down

0 comments on commit 43eb925

Please sign in to comment.