Skip to content
/ miri Public
forked from rust-lang/miri

Commit

Permalink
build: Fix build after rust-lang/rust#60951
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Jul 24, 2019
1 parent b269bb0 commit b282c3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
assert!(right.layout.ty.is_integral());
let l_bits = self.force_bits(left.imm.to_scalar()?, left.layout.size)?;
let r_bits = self.force_bits(right.imm.to_scalar()?, right.layout.size)?;

let left = ImmTy::from_scalar(Scalar::from_uint(l_bits, left.layout.size), left.layout);
let right = ImmTy::from_scalar(Scalar::from_uint(r_bits, left.layout.size), right.layout);

return self.binary_op(bin_op, left, right);
}
}

// Operations that support fat pointers
match bin_op {
Expand Down Expand Up @@ -391,11 +391,12 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
pointee_ty: Ty<'tcx>,
offset: i64,
) -> InterpResult<'tcx, Scalar<Tag>> {
use rustc::mir::interpret::InterpError::Panic;
// FIXME: assuming here that type size is less than `i64::max_value()`.
let pointee_size = self.layout_of(pointee_ty)?.size.bytes() as i64;
let offset = offset
.checked_mul(pointee_size)
.ok_or_else(|| InterpError::Overflow(mir::BinOp::Mul))?;
.ok_or_else(|| Panic(PanicMessage::Overflow(mir::BinOp::Mul)))?;
// Now let's see what kind of pointer this is.
let ptr = if offset == 0 {
match ptr {
Expand Down
3 changes: 2 additions & 1 deletion src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
dest: Option<PlaceTy<'tcx, Tag>>,
ret: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
use rustc::mir::interpret::InterpError::Panic;
let this = self.eval_context_mut();
let attrs = this.tcx.get_attrs(def_id);
let link_name = match attr::first_attr_value_str_by_name(&attrs, sym::link_name) {
Expand Down Expand Up @@ -167,7 +168,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
"calloc" => {
let items = this.read_scalar(args[0])?.to_usize(this)?;
let len = this.read_scalar(args[1])?.to_usize(this)?;
let size = items.checked_mul(len).ok_or_else(|| InterpError::Overflow(mir::BinOp::Mul))?;
let size = items.checked_mul(len).ok_or_else(|| Panic(PanicMessage::Overflow(mir::BinOp::Mul)))?;
let res = this.malloc(size, /*zero_init:*/ true, MiriMemoryKind::C);
this.write_scalar(res, dest)?;
}
Expand Down

0 comments on commit b282c3f

Please sign in to comment.