@@ -290,30 +290,29 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
290
290
FloatTy :: F64 => self . binary_float_op ( bin_op, left. to_f64 ( ) ?, right. to_f64 ( ) ?) ,
291
291
} )
292
292
}
293
- _ => {
294
- // Must be integer(-like) types. Don't forget about == on fn pointers.
295
- assert ! (
296
- left. layout. ty. is_integral( ) ||
297
- left. layout. ty. is_unsafe_ptr( ) || left. layout. ty. is_fn_ptr( ) ,
298
- "Unexpected LHS type {:?} for BinOp {:?}" , left. layout. ty, bin_op) ;
293
+ _ if left. layout . ty . is_integral ( ) => {
294
+ // the RHS type can be different, e.g. for shifts -- but it has to be integral, too
299
295
assert ! (
300
- right. layout. ty. is_integral( ) ||
301
- right. layout. ty. is_unsafe_ptr( ) || right. layout. ty. is_fn_ptr( ) ,
302
- "Unexpected RHS type {:?} for BinOp {:?}" , right. layout. ty, bin_op) ;
303
-
304
- // Handle operations that support pointer values
305
- if left. to_scalar_ptr ( ) ?. is_ptr ( ) ||
306
- right. to_scalar_ptr ( ) ?. is_ptr ( ) ||
307
- bin_op == mir:: BinOp :: Offset
308
- {
309
- return M :: ptr_op ( self , bin_op, left, right) ;
310
- }
296
+ right. layout. ty. is_integral( ) ,
297
+ "Unexpected types for BinOp: {:?} {:?} {:?}" ,
298
+ left. layout. ty, bin_op, right. layout. ty
299
+ ) ;
311
300
312
- // Everything else only works with "proper" bits
313
- let l = left. to_bits ( ) . expect ( "we checked is_ptr" ) ;
314
- let r = right. to_bits ( ) . expect ( "we checked is_ptr" ) ;
301
+ let l = self . force_bits ( left. to_scalar ( ) ?, left. layout . size ) ?;
302
+ let r = self . force_bits ( right. to_scalar ( ) ?, right. layout . size ) ?;
315
303
self . binary_int_op ( bin_op, l, left. layout , r, right. layout )
316
304
}
305
+ _ if left. layout . ty . is_unsafe_ptr ( ) || left. layout . ty . is_fn_ptr ( ) => {
306
+ // The RHS type must be the same *or an integer type* (for `Offset`)
307
+ assert ! (
308
+ right. layout. ty == left. layout. ty || right. layout. ty. is_integral( ) ,
309
+ "Unexpected types for BinOp: {:?} {:?} {:?}" ,
310
+ left. layout. ty, bin_op, right. layout. ty
311
+ ) ;
312
+
313
+ M :: binary_ptr_op ( self , bin_op, left, right)
314
+ }
315
+ _ => bug ! ( "Invalid MIR: bad LHS type for binop: {:?}" , left. layout. ty) ,
317
316
}
318
317
}
319
318
0 commit comments