@@ -60,7 +60,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
60
60
let op = this. read_immediate ( & this. project_index ( & op, i) ?) ?;
61
61
let dest = this. project_index ( & dest, i) ?;
62
62
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 ( ) ,
64
64
Op :: Abs => {
65
65
// Works for f32 and f64.
66
66
let ty:: Float ( float_ty) = op. layout . ty . kind ( ) else {
@@ -177,7 +177,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
177
177
let dest = this. project_index ( & dest, i) ?;
178
178
let val = match which {
179
179
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) ?;
181
181
if matches ! ( mir_op, BinOp :: Shl | BinOp :: Shr ) {
182
182
// Shifts have extra UB as SIMD operations that the MIR binop does not have.
183
183
// See <https://github.com/rust-lang/rust/issues/91237>.
@@ -188,13 +188,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
188
188
}
189
189
if matches ! ( mir_op, BinOp :: Eq | BinOp :: Ne | BinOp :: Lt | BinOp :: Le | BinOp :: Gt | BinOp :: Ge ) {
190
190
// 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 ( ) ;
193
193
bool_to_simd_element ( val, dest. layout . size )
194
194
} 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 ( )
198
198
}
199
199
}
200
200
Op :: SaturatingOp ( mir_op) => {
@@ -304,18 +304,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
304
304
let op = this. read_immediate ( & this. project_index ( & op, i) ?) ?;
305
305
res = match which {
306
306
Op :: MirOp ( mir_op) => {
307
- this. binary_op ( mir_op, & res, & op) ?
307
+ this. wrapping_binary_op ( mir_op, & res, & op) ?
308
308
}
309
309
Op :: MirOpBool ( mir_op) => {
310
310
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) ?
312
312
}
313
313
Op :: Max => {
314
314
if matches ! ( res. layout. ty. kind( ) , ty:: Float ( _) ) {
315
315
ImmTy :: from_scalar ( fmax_op ( & res, & op) ?, res. layout )
316
316
} else {
317
317
// 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 ( ) ? {
319
319
res
320
320
} else {
321
321
op
@@ -327,7 +327,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
327
327
ImmTy :: from_scalar ( fmin_op ( & res, & op) ?, res. layout )
328
328
} else {
329
329
// 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 ( ) ? {
331
331
res
332
332
} else {
333
333
op
@@ -356,7 +356,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
356
356
let mut res = init;
357
357
for i in 0 ..op_len {
358
358
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) ?;
360
360
}
361
361
this. write_immediate ( * res, dest) ?;
362
362
}
@@ -441,17 +441,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
441
441
// Int-to-(int|float): always safe
442
442
( ty:: Int ( _) | ty:: Uint ( _) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) )
443
443
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 ) ?,
445
445
// Float-to-float: always safe
446
446
( 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 ) ?,
448
448
// Float-to-int in safe mode
449
449
( 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 ) ?,
451
451
// Float-to-int in unchecked mode
452
452
( ty:: Float ( FloatTy :: F32 ) , ty:: Int ( _) | ty:: Uint ( _) ) if unsafe_cast => {
453
453
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 )
455
455
. ok_or_else ( || {
456
456
err_ub_format ! (
457
457
"`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> {
462
462
}
463
463
( ty:: Float ( FloatTy :: F64 ) , ty:: Int ( _) | ty:: Uint ( _) ) if unsafe_cast => {
464
464
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 )
466
466
. ok_or_else ( || {
467
467
err_ub_format ! (
468
468
"`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> {
473
473
}
474
474
// Ptr-to-ptr cast
475
475
( ty:: RawPtr ( ..) , ty:: RawPtr ( ..) ) if ptr_cast =>
476
- this. ptr_to_ptr ( & op, dest. layout . ty ) ?,
476
+ this. ptr_to_ptr ( & op, dest. layout ) ?,
477
477
// Ptr/Int casts
478
478
( 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 ) ?,
480
480
( 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 ) ?,
482
482
// Error otherwise
483
483
_ =>
484
484
throw_unsup_format ! (
@@ -487,7 +487,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
487
487
to_ty = dest. layout. ty,
488
488
) ,
489
489
} ;
490
- this. write_immediate ( val, & dest) ?;
490
+ this. write_immediate ( * val, & dest) ?;
491
491
}
492
492
}
493
493
"shuffle" => {
0 commit comments