@@ -5,7 +5,7 @@ use rustc::ty::layout::{self, LayoutOf, Size, Align};
5
5
use rustc:: ty;
6
6
7
7
use crate :: {
8
- PlaceTy , OpTy , ImmTy , Immediate , Scalar , Tag ,
8
+ PlaceTy , OpTy , Immediate , Scalar , Tag ,
9
9
OperatorEvalContextExt
10
10
} ;
11
11
@@ -120,7 +120,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
120
120
this. memory ( ) . check_ptr_access ( place. ptr , place. layout . size , align) ?;
121
121
122
122
// 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 ;
124
124
let res = Immediate :: ScalarPair ( old. to_scalar_or_undef ( ) , eq. into ( ) ) ;
125
125
this. write_immediate ( res, dest) ?; // old value is returned
126
126
// update ptr depending on comparison
@@ -183,13 +183,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
183
183
_ => bug ! ( ) ,
184
184
} ;
185
185
// Atomics wrap around on overflow.
186
- let ( val, _overflowed ) = this. binary_op ( op, old, rhs) ?;
186
+ let val = this. binary_op ( op, old, rhs) ?;
187
187
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) ?
189
189
} else {
190
190
val
191
191
} ;
192
- this. write_scalar ( val, place. into ( ) ) ?;
192
+ this. write_immediate ( * val, place. into ( ) ) ?;
193
193
}
194
194
195
195
"breakpoint" => unimplemented ! ( ) , // halt miri
@@ -312,7 +312,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
312
312
let a = this. read_immediate ( args[ 0 ] ) ?;
313
313
let b = this. read_immediate ( args[ 1 ] ) ?;
314
314
// 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 {
316
316
// Check if `b` is -1, which is the "min_value / -1" case.
317
317
let minus1 = Scalar :: from_int ( -1 , dest. layout . size ) ;
318
318
return Err ( if b. to_scalar ( ) . unwrap ( ) == minus1 {
@@ -515,7 +515,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
515
515
"unchecked_mul" => mir:: BinOp :: Mul ,
516
516
_ => bug ! ( ) ,
517
517
} ;
518
- let ( res, overflowed) = this. binary_op ( op, l, r) ?;
518
+ let ( res, overflowed, _ty ) = this. overflowing_binary_op ( op, l, r) ?;
519
519
if overflowed {
520
520
throw_ub_format ! ( "Overflowing arithmetic in {}" , intrinsic_name. get( ) ) ;
521
521
}
0 commit comments