]> git.lizzy.rs Git - rust.git/blobdiff - src/operator.rs
rename track-raw-pointers flag to tag-raw-pointers
[rust.git] / src / operator.rs
index 5b86b9a76f6b48125906a9fdbd5fac091b9c9008..59099469a332261520773b0ddec9caee728d83b3 100644 (file)
@@ -8,8 +8,8 @@ pub trait EvalContextExt<'tcx> {
     fn binary_ptr_op(
         &self,
         bin_op: mir::BinOp,
-        left: ImmTy<'tcx, Tag>,
-        right: ImmTy<'tcx, Tag>,
+        left: &ImmTy<'tcx, Tag>,
+        right: &ImmTy<'tcx, Tag>,
     ) -> InterpResult<'tcx, (Scalar<Tag>, bool, Ty<'tcx>)>;
 
     fn ptr_eq(&self, left: Scalar<Tag>, right: Scalar<Tag>) -> InterpResult<'tcx, bool>;
@@ -19,8 +19,8 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
     fn binary_ptr_op(
         &self,
         bin_op: mir::BinOp,
-        left: ImmTy<'tcx, Tag>,
-        right: ImmTy<'tcx, Tag>,
+        left: &ImmTy<'tcx, Tag>,
+        right: &ImmTy<'tcx, Tag>,
     ) -> InterpResult<'tcx, (Scalar<Tag>, bool, Ty<'tcx>)> {
         use rustc_middle::mir::BinOp::*;
 
@@ -30,7 +30,7 @@ fn binary_ptr_op(
             Eq | Ne => {
                 // This supports fat pointers.
                 #[rustfmt::skip]
-                let eq = match (*left, *right) {
+                let eq = match (**left, **right) {
                     (Immediate::Scalar(left), Immediate::Scalar(right)) => {
                         self.ptr_eq(left.check_init()?, right.check_init()?)?
                     }
@@ -45,9 +45,8 @@ fn binary_ptr_op(
 
             Lt | Le | Gt | Ge => {
                 // Just compare the integers.
-                // TODO: Do we really want to *always* do that, even when comparing two live in-bounds pointers?
-                let left = self.force_bits(left.to_scalar()?, left.layout.size)?;
-                let right = self.force_bits(right.to_scalar()?, right.layout.size)?;
+                let left = left.to_scalar()?.to_bits(left.layout.size)?;
+                let right = right.to_scalar()?.to_bits(right.layout.size)?;
                 let res = match bin_op {
                     Lt => left < right,
                     Le => left <= right,
@@ -62,11 +61,11 @@ fn binary_ptr_op(
                 let pointee_ty =
                     left.layout.ty.builtin_deref(true).expect("Offset called on non-ptr type").ty;
                 let ptr = self.ptr_offset_inbounds(
-                    left.to_scalar()?,
+                    self.scalar_to_ptr(left.to_scalar()?),
                     pointee_ty,
                     right.to_scalar()?.to_machine_isize(self)?,
                 )?;
-                (ptr, false, left.layout.ty)
+                (Scalar::from_maybe_pointer(ptr, self), false, left.layout.ty)
             }
 
             _ => bug!("Invalid operator on pointers: {:?}", bin_op),
@@ -76,9 +75,8 @@ fn binary_ptr_op(
     fn ptr_eq(&self, left: Scalar<Tag>, right: Scalar<Tag>) -> InterpResult<'tcx, bool> {
         let size = self.pointer_size();
         // Just compare the integers.
-        // TODO: Do we really want to *always* do that, even when comparing two live in-bounds pointers?
-        let left = self.force_bits(left, size)?;
-        let right = self.force_bits(right, size)?;
+        let left = left.to_bits(size)?;
+        let right = right.to_bits(size)?;
         Ok(left == right)
     }
 }