Skip to content

Commit 1d8ccd4

Browse files
committed
update for new bin_op APIs
1 parent 77d12bb commit 1d8ccd4

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/intrinsic.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::ty;
55
use rustc::mir::interpret::{EvalResult, PointerArithmetic};
66

77
use crate::{
8-
PlaceTy, OpTy, Immediate, Scalar, ScalarMaybeUndef, Borrow,
8+
PlaceTy, OpTy, ImmTy, Immediate, Scalar, ScalarMaybeUndef, Borrow,
99
OperatorEvalContextExt
1010
};
1111

@@ -80,11 +80,11 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
8080

8181
_ if intrinsic_name.starts_with("atomic_cxchg") => {
8282
let ptr = this.deref_operand(args[0])?;
83-
let expect_old = this.read_immediate(args[1])?; // read as immediate for the sake of `binary_op_imm()`
83+
let expect_old = this.read_immediate(args[1])?; // read as immediate for the sake of `binary_op()`
8484
let new = this.read_scalar(args[2])?;
85-
let old = this.read_immediate(ptr.into())?; // read as immediate for the sake of `binary_op_imm()`
86-
// binary_op_imm will bail if either of them is not a scalar
87-
let (eq, _) = this.binary_op_imm(mir::BinOp::Eq, old, expect_old)?;
85+
let old = this.read_immediate(ptr.into())?; // read as immediate for the sake of `binary_op()`
86+
// binary_op will bail if either of them is not a scalar
87+
let (eq, _) = this.binary_op(mir::BinOp::Eq, old, expect_old)?;
8888
let res = Immediate::ScalarPair(old.to_scalar_or_undef(), eq.into());
8989
this.write_immediate(res, dest)?; // old value is returned
9090
// update ptr depending on comparison
@@ -140,9 +140,9 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
140140
_ => bug!(),
141141
};
142142
// Atomics wrap around on overflow.
143-
let (val, _overflowed) = this.binary_op_imm(op, old, rhs)?;
143+
let (val, _overflowed) = this.binary_op(op, old, rhs)?;
144144
let val = if neg {
145-
this.unary_op(mir::UnOp::Not, val, old.layout)?
145+
this.unary_op(mir::UnOp::Not, ImmTy::from_scalar(val, old.layout))?
146146
} else {
147147
val
148148
};
@@ -239,7 +239,7 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
239239
let a = this.read_immediate(args[0])?;
240240
let b = this.read_immediate(args[1])?;
241241
// check x % y != 0
242-
if this.binary_op_imm(mir::BinOp::Rem, a, b)?.0.to_bits(dest.layout.size)? != 0 {
242+
if this.binary_op(mir::BinOp::Rem, a, b)?.0.to_bits(dest.layout.size)? != 0 {
243243
return err!(ValidationFailure(format!("exact_div: {:?} cannot be divided by {:?}", a, b)));
244244
}
245245
this.binop_ignore_overflow(mir::BinOp::Div, a, b, dest)?;

src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,10 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
379379
fn ptr_op(
380380
ecx: &rustc_mir::interpret::EvalContext<'a, 'mir, 'tcx, Self>,
381381
bin_op: mir::BinOp,
382-
left: Scalar<Borrow>,
383-
left_layout: TyLayout<'tcx>,
384-
right: Scalar<Borrow>,
385-
right_layout: TyLayout<'tcx>,
382+
left: ImmTy<'tcx, Borrow>,
383+
right: ImmTy<'tcx, Borrow>,
386384
) -> EvalResult<'tcx, (Scalar<Borrow>, bool)> {
387-
ecx.ptr_op(bin_op, left, left_layout, right, right_layout)
385+
ecx.ptr_op(bin_op, left, right)
388386
}
389387

390388
fn box_alloc(

src/operator.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ pub trait EvalContextExt<'tcx> {
77
fn ptr_op(
88
&self,
99
bin_op: mir::BinOp,
10-
left: Scalar<Borrow>,
11-
left_layout: TyLayout<'tcx>,
12-
right: Scalar<Borrow>,
13-
right_layout: TyLayout<'tcx>,
10+
left: ImmTy<'tcx, Borrow>,
11+
right: ImmTy<'tcx, Borrow>,
1412
) -> EvalResult<'tcx, (Scalar<Borrow>, bool)>;
1513

1614
fn ptr_int_arithmetic(
@@ -40,13 +38,16 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
4038
fn ptr_op(
4139
&self,
4240
bin_op: mir::BinOp,
43-
left: Scalar<Borrow>,
44-
left_layout: TyLayout<'tcx>,
45-
right: Scalar<Borrow>,
46-
right_layout: TyLayout<'tcx>,
41+
left: ImmTy<'tcx, Borrow>,
42+
right: ImmTy<'tcx, Borrow>,
4743
) -> EvalResult<'tcx, (Scalar<Borrow>, bool)> {
4844
use rustc::mir::BinOp::*;
4945

46+
let left_layout = left.layout;
47+
let left = left.to_scalar()?;
48+
let right_layout = right.layout;
49+
let right = right.to_scalar()?;
50+
5051
trace!("ptr_op: {:?} {:?} {:?}", left, bin_op, right);
5152
debug_assert!(left.is_ptr() || right.is_ptr() || bin_op == Offset);
5253

@@ -85,8 +86,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
8586
let layout = self.layout_of(self.tcx.types.usize)?;
8687
return self.binary_op(
8788
Sub,
88-
left_offset, layout,
89-
right_offset, layout,
89+
ImmTy::from_scalar(left_offset, layout),
90+
ImmTy::from_scalar(right_offset, layout),
9091
)
9192
}
9293
_ => bug!("We already established it has to be one of these operators."),

0 commit comments

Comments
 (0)