@@ -5,7 +5,7 @@ use rustc::ty::layout::{self, LayoutOf, Size, Align};
55use rustc:: ty;
66
77use crate :: {
8- PlaceTy , OpTy , ImmTy , Immediate , Scalar , Tag ,
8+ PlaceTy , OpTy , Immediate , Scalar , Tag ,
99 OperatorEvalContextExt
1010} ;
1111
@@ -120,7 +120,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
120120 this. memory ( ) . check_ptr_access ( place. ptr , place. layout . size , align) ?;
121121
122122 // binary_op will bail if either of them is not a scalar
123- let ( eq , _ ) = this. binary_op ( mir:: BinOp :: Eq , old, expect_old) ?;
123+ let eq = this. overflowing_binary_op ( mir:: BinOp :: Eq , old, expect_old) ?. 0 ;
124124 let res = Immediate :: ScalarPair ( old. to_scalar_or_undef ( ) , eq. into ( ) ) ;
125125 this. write_immediate ( res, dest) ?; // old value is returned
126126 // update ptr depending on comparison
@@ -183,13 +183,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
183183 _ => bug ! ( ) ,
184184 } ;
185185 // Atomics wrap around on overflow.
186- let ( val, _overflowed ) = this. binary_op ( op, old, rhs) ?;
186+ let val = this. binary_op ( op, old, rhs) ?;
187187 let val = if neg {
188- this. unary_op ( mir:: UnOp :: Not , ImmTy :: from_scalar ( val, old . layout ) ) ?
188+ this. unary_op ( mir:: UnOp :: Not , val) ?
189189 } else {
190190 val
191191 } ;
192- this. write_scalar ( val, place. into ( ) ) ?;
192+ this. write_immediate ( * val, place. into ( ) ) ?;
193193 }
194194
195195 "breakpoint" => unimplemented ! ( ) , // halt miri
@@ -312,7 +312,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
312312 let a = this. read_immediate ( args[ 0 ] ) ?;
313313 let b = this. read_immediate ( args[ 1 ] ) ?;
314314 // check x % y != 0
315- if this. binary_op ( mir:: BinOp :: Rem , a, b) ?. 0 . to_bits ( dest. layout . size ) ? != 0 {
315+ if this. overflowing_binary_op ( mir:: BinOp :: Rem , a, b) ?. 0 . to_bits ( dest. layout . size ) ? != 0 {
316316 // Check if `b` is -1, which is the "min_value / -1" case.
317317 let minus1 = Scalar :: from_int ( -1 , dest. layout . size ) ;
318318 return Err ( if b. to_scalar ( ) . unwrap ( ) == minus1 {
@@ -515,7 +515,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
515515 "unchecked_mul" => mir:: BinOp :: Mul ,
516516 _ => bug ! ( ) ,
517517 } ;
518- let ( res, overflowed) = this. binary_op ( op, l, r) ?;
518+ let ( res, overflowed, _ty ) = this. overflowing_binary_op ( op, l, r) ?;
519519 if overflowed {
520520 throw_ub_format ! ( "Overflowing arithmetic in {}" , intrinsic_name. get( ) ) ;
521521 }
0 commit comments