]> git.lizzy.rs Git - rust.git/commitdiff
adjust for typed binary/unary_op
authorRalf Jung <post@ralfj.de>
Sat, 10 Aug 2019 19:19:25 +0000 (21:19 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 18 Aug 2019 05:42:15 +0000 (07:42 +0200)
src/machine.rs
src/operator.rs
src/shims/intrinsics.rs

index b4aac147f94fb184dde74ae8469955877f8e08e5..9d50c77c7c4c4ef8a16040826f00ec25e383245e 100644 (file)
@@ -10,7 +10,7 @@
 use syntax::attr;
 use syntax::symbol::sym;
 use rustc::hir::def_id::DefId;
-use rustc::ty::{self, layout::{Size, LayoutOf}, TyCtxt};
+use rustc::ty::{self, Ty, TyCtxt, layout::{Size, LayoutOf}};
 use rustc::mir;
 
 use crate::*;
@@ -191,7 +191,7 @@ fn binary_ptr_op(
         bin_op: mir::BinOp,
         left: ImmTy<'tcx, Tag>,
         right: ImmTy<'tcx, Tag>,
-    ) -> InterpResult<'tcx, (Scalar<Tag>, bool)> {
+    ) -> InterpResult<'tcx, (Scalar<Tag>, bool, Ty<'tcx>)> {
         ecx.binary_ptr_op(bin_op, left, right)
     }
 
index acf1db2977b798f2cbe33dcc514119c3dddba1f2..45bf1e453744cb26f723495b989b6934537889b9 100644 (file)
@@ -14,7 +14,7 @@ fn binary_ptr_op(
         bin_op: mir::BinOp,
         left: ImmTy<'tcx, Tag>,
         right: ImmTy<'tcx, Tag>,
-    ) -> InterpResult<'tcx, (Scalar<Tag>, bool)>;
+    ) -> InterpResult<'tcx, (Scalar<Tag>, bool, Ty<'tcx>)>;
 
     fn ptr_eq(
         &self,
@@ -43,7 +43,7 @@ fn binary_ptr_op(
         bin_op: mir::BinOp,
         left: ImmTy<'tcx, Tag>,
         right: ImmTy<'tcx, Tag>,
-    ) -> InterpResult<'tcx, (Scalar<Tag>, bool)> {
+    ) -> InterpResult<'tcx, (Scalar<Tag>, bool, Ty<'tcx>)> {
         use rustc::mir::BinOp::*;
 
         trace!("ptr_op: {:?} {:?} {:?}", *left, bin_op, *right);
@@ -59,7 +59,7 @@ fn binary_ptr_op(
                         self.ptr_eq(left2.not_undef()?, right2.not_undef()?)?,
                     _ => bug!("Type system should not allow comparing Scalar with ScalarPair"),
                 };
-                (Scalar::from_bool(if bin_op == Eq { eq } else { !eq }), false)
+                (Scalar::from_bool(if bin_op == Eq { eq } else { !eq }), false, self.tcx.types.bool)
             }
 
             Lt | Le | Gt | Ge => {
@@ -74,7 +74,7 @@ fn binary_ptr_op(
                     Ge => left >= right,
                     _ => bug!("We already established it has to be one of these operators."),
                 };
-                (Scalar::from_bool(res), false)
+                (Scalar::from_bool(res), false, self.tcx.types.bool)
             }
 
             Offset => {
@@ -87,7 +87,7 @@ fn binary_ptr_op(
                     pointee_ty,
                     right.to_scalar()?.to_isize(self)?,
                 )?;
-                (ptr, false)
+                (ptr, false, left.layout.ty)
             }
 
             _ => bug!("Invalid operator on pointers: {:?}", bin_op)
index 4e957f792b7513721902d334d126f742c76d28d8..8656962761713c08e11d7a0ff9a223d98554e6ce 100644 (file)
@@ -5,7 +5,7 @@
 use rustc::ty;
 
 use crate::{
-    PlaceTy, OpTy, ImmTy, Immediate, Scalar, Tag,
+    PlaceTy, OpTy, Immediate, Scalar, Tag,
     OperatorEvalContextExt
 };
 
@@ -120,7 +120,7 @@ fn call_intrinsic(
                 this.memory().check_ptr_access(place.ptr, place.layout.size, align)?;
 
                 // binary_op will bail if either of them is not a scalar
-                let (eq, _) = this.binary_op(mir::BinOp::Eq, old, expect_old)?;
+                let eq = this.overflowing_binary_op(mir::BinOp::Eq, old, expect_old)?.0;
                 let res = Immediate::ScalarPair(old.to_scalar_or_undef(), eq.into());
                 this.write_immediate(res, dest)?; // old value is returned
                 // update ptr depending on comparison
@@ -183,13 +183,13 @@ fn call_intrinsic(
                     _ => bug!(),
                 };
                 // Atomics wrap around on overflow.
-                let (val, _overflowed) = this.binary_op(op, old, rhs)?;
+                let val = this.binary_op(op, old, rhs)?;
                 let val = if neg {
-                    this.unary_op(mir::UnOp::Not, ImmTy::from_scalar(val, old.layout))?
+                    this.unary_op(mir::UnOp::Not, val)?
                 } else {
                     val
                 };
-                this.write_scalar(val, place.into())?;
+                this.write_immediate(*val, place.into())?;
             }
 
             "breakpoint" => unimplemented!(), // halt miri
@@ -312,7 +312,7 @@ fn call_intrinsic(
                 let a = this.read_immediate(args[0])?;
                 let b = this.read_immediate(args[1])?;
                 // check x % y != 0
-                if this.binary_op(mir::BinOp::Rem, a, b)?.0.to_bits(dest.layout.size)? != 0 {
+                if this.overflowing_binary_op(mir::BinOp::Rem, a, b)?.0.to_bits(dest.layout.size)? != 0 {
                     // Check if `b` is -1, which is the "min_value / -1" case.
                     let minus1 = Scalar::from_int(-1, dest.layout.size);
                     return Err(if b.to_scalar().unwrap() == minus1 {
@@ -515,7 +515,7 @@ fn call_intrinsic(
                     "unchecked_mul" => mir::BinOp::Mul,
                     _ => bug!(),
                 };
-                let (res, overflowed) = this.binary_op(op, l, r)?;
+                let (res, overflowed, _ty) = this.overflowing_binary_op(op, l, r)?;
                 if overflowed {
                     throw_ub_format!("Overflowing arithmetic in {}", intrinsic_name.get());
                 }