@@ -60,7 +60,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
6060 let op = this. read_immediate ( & this. project_index ( & op, i) ?) ?;
6161 let dest = this. project_index ( & dest, i) ?;
6262 let val = match which {
63- Op :: MirOp ( mir_op) => this. unary_op ( mir_op, & op) ?. to_scalar ( ) ,
63+ Op :: MirOp ( mir_op) => this. wrapping_unary_op ( mir_op, & op) ?. to_scalar ( ) ,
6464 Op :: Abs => {
6565 // Works for f32 and f64.
6666 let ty:: Float ( float_ty) = op. layout . ty . kind ( ) else {
@@ -177,7 +177,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
177177 let dest = this. project_index ( & dest, i) ?;
178178 let val = match which {
179179 Op :: MirOp ( mir_op) => {
180- let ( val, overflowed, ty ) = this. overflowing_binary_op ( mir_op, & left, & right) ?;
180+ let ( val, overflowed) = this. overflowing_binary_op ( mir_op, & left, & right) ?;
181181 if matches ! ( mir_op, BinOp :: Shl | BinOp :: Shr ) {
182182 // Shifts have extra UB as SIMD operations that the MIR binop does not have.
183183 // See <https://github.com/rust-lang/rust/issues/91237>.
@@ -188,13 +188,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
188188 }
189189 if matches ! ( mir_op, BinOp :: Eq | BinOp :: Ne | BinOp :: Lt | BinOp :: Le | BinOp :: Gt | BinOp :: Ge ) {
190190 // Special handling for boolean-returning operations
191- assert_eq ! ( ty, this. tcx. types. bool ) ;
192- let val = val. to_bool ( ) . unwrap ( ) ;
191+ assert_eq ! ( val . layout . ty, this. tcx. types. bool ) ;
192+ let val = val. to_scalar ( ) . to_bool ( ) . unwrap ( ) ;
193193 bool_to_simd_element ( val, dest. layout . size )
194194 } else {
195- assert_ne ! ( ty, this. tcx. types. bool ) ;
196- assert_eq ! ( ty, dest. layout. ty) ;
197- val
195+ assert_ne ! ( val . layout . ty, this. tcx. types. bool ) ;
196+ assert_eq ! ( val . layout . ty, dest. layout. ty) ;
197+ val. to_scalar ( )
198198 }
199199 }
200200 Op :: SaturatingOp ( mir_op) => {
@@ -304,18 +304,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
304304 let op = this. read_immediate ( & this. project_index ( & op, i) ?) ?;
305305 res = match which {
306306 Op :: MirOp ( mir_op) => {
307- this. binary_op ( mir_op, & res, & op) ?
307+ this. wrapping_binary_op ( mir_op, & res, & op) ?
308308 }
309309 Op :: MirOpBool ( mir_op) => {
310310 let op = imm_from_bool ( simd_element_to_bool ( op) ?) ;
311- this. binary_op ( mir_op, & res, & op) ?
311+ this. wrapping_binary_op ( mir_op, & res, & op) ?
312312 }
313313 Op :: Max => {
314314 if matches ! ( res. layout. ty. kind( ) , ty:: Float ( _) ) {
315315 ImmTy :: from_scalar ( fmax_op ( & res, & op) ?, res. layout )
316316 } else {
317317 // Just boring integers, so NaNs to worry about
318- if this. binary_op ( BinOp :: Ge , & res, & op) ?. to_scalar ( ) . to_bool ( ) ? {
318+ if this. wrapping_binary_op ( BinOp :: Ge , & res, & op) ?. to_scalar ( ) . to_bool ( ) ? {
319319 res
320320 } else {
321321 op
@@ -327,7 +327,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
327327 ImmTy :: from_scalar ( fmin_op ( & res, & op) ?, res. layout )
328328 } else {
329329 // Just boring integers, so NaNs to worry about
330- if this. binary_op ( BinOp :: Le , & res, & op) ?. to_scalar ( ) . to_bool ( ) ? {
330+ if this. wrapping_binary_op ( BinOp :: Le , & res, & op) ?. to_scalar ( ) . to_bool ( ) ? {
331331 res
332332 } else {
333333 op
@@ -356,7 +356,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
356356 let mut res = init;
357357 for i in 0 ..op_len {
358358 let op = this. read_immediate ( & this. project_index ( & op, i) ?) ?;
359- res = this. binary_op ( mir_op, & res, & op) ?;
359+ res = this. wrapping_binary_op ( mir_op, & res, & op) ?;
360360 }
361361 this. write_immediate ( * res, dest) ?;
362362 }
@@ -441,17 +441,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
441441 // Int-to-(int|float): always safe
442442 ( ty:: Int ( _) | ty:: Uint ( _) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) )
443443 if safe_cast || unsafe_cast =>
444- this. int_to_int_or_float ( & op, dest. layout . ty ) ?,
444+ this. int_to_int_or_float ( & op, dest. layout ) ?,
445445 // Float-to-float: always safe
446446 ( ty:: Float ( _) , ty:: Float ( _) ) if safe_cast || unsafe_cast =>
447- this. float_to_float_or_int ( & op, dest. layout . ty ) ?,
447+ this. float_to_float_or_int ( & op, dest. layout ) ?,
448448 // Float-to-int in safe mode
449449 ( ty:: Float ( _) , ty:: Int ( _) | ty:: Uint ( _) ) if safe_cast =>
450- this. float_to_float_or_int ( & op, dest. layout . ty ) ?,
450+ this. float_to_float_or_int ( & op, dest. layout ) ?,
451451 // Float-to-int in unchecked mode
452452 ( ty:: Float ( FloatTy :: F32 ) , ty:: Int ( _) | ty:: Uint ( _) ) if unsafe_cast => {
453453 let f = op. to_scalar ( ) . to_f32 ( ) ?;
454- this. float_to_int_checked ( f, dest. layout . ty , Round :: TowardZero )
454+ this. float_to_int_checked ( f, dest. layout , Round :: TowardZero )
455455 . ok_or_else ( || {
456456 err_ub_format ! (
457457 "`simd_cast` intrinsic called on {f} which cannot be represented in target type `{:?}`" ,
@@ -462,7 +462,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
462462 }
463463 ( ty:: Float ( FloatTy :: F64 ) , ty:: Int ( _) | ty:: Uint ( _) ) if unsafe_cast => {
464464 let f = op. to_scalar ( ) . to_f64 ( ) ?;
465- this. float_to_int_checked ( f, dest. layout . ty , Round :: TowardZero )
465+ this. float_to_int_checked ( f, dest. layout , Round :: TowardZero )
466466 . ok_or_else ( || {
467467 err_ub_format ! (
468468 "`simd_cast` intrinsic called on {f} which cannot be represented in target type `{:?}`" ,
@@ -473,12 +473,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
473473 }
474474 // Ptr-to-ptr cast
475475 ( ty:: RawPtr ( ..) , ty:: RawPtr ( ..) ) if ptr_cast =>
476- this. ptr_to_ptr ( & op, dest. layout . ty ) ?,
476+ this. ptr_to_ptr ( & op, dest. layout ) ?,
477477 // Ptr/Int casts
478478 ( ty:: RawPtr ( ..) , ty:: Int ( _) | ty:: Uint ( _) ) if expose_cast =>
479- this. pointer_expose_address_cast ( & op, dest. layout . ty ) ?,
479+ this. pointer_expose_address_cast ( & op, dest. layout ) ?,
480480 ( ty:: Int ( _) | ty:: Uint ( _) , ty:: RawPtr ( ..) ) if from_exposed_cast =>
481- this. pointer_from_exposed_address_cast ( & op, dest. layout . ty ) ?,
481+ this. pointer_from_exposed_address_cast ( & op, dest. layout ) ?,
482482 // Error otherwise
483483 _ =>
484484 throw_unsup_format ! (
@@ -487,7 +487,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
487487 to_ty = dest. layout. ty,
488488 ) ,
489489 } ;
490- this. write_immediate ( val, & dest) ?;
490+ this. write_immediate ( * val, & dest) ?;
491491 }
492492 }
493493 "shuffle" => {
0 commit comments