@@ -28,7 +28,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
2828 right : ValTy < ' tcx > ,
2929 dest : PlaceTy < ' tcx > ,
3030 ) -> EvalResult < ' tcx > {
31- let ( val, overflowed) = self . binary_op ( op, left, right) ?;
31+ let ( val, overflowed) = self . binary_op_val ( op, left, right) ?;
3232 let val = Value :: ScalarPair ( val. into ( ) , Scalar :: from_bool ( overflowed) . into ( ) ) ;
3333 self . write_value ( val, dest)
3434 }
@@ -42,7 +42,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
4242 right : ValTy < ' tcx > ,
4343 dest : PlaceTy < ' tcx > ,
4444 ) -> EvalResult < ' tcx > {
45- let ( val, _overflowed) = self . binary_op ( op, left, right) ?;
45+ let ( val, _overflowed) = self . binary_op_val ( op, left, right) ?;
4646 self . write_scalar ( val, dest)
4747 }
4848}
@@ -282,16 +282,31 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
282282 Ok ( ( val, false ) )
283283 }
284284
285+ /// Convenience wrapper that's useful when keeping the layout together with the
286+ /// value.
287+ #[ inline]
288+ pub fn binary_op_val (
289+ & self ,
290+ bin_op : mir:: BinOp ,
291+ left : ValTy < ' tcx > ,
292+ right : ValTy < ' tcx > ,
293+ ) -> EvalResult < ' tcx , ( Scalar , bool ) > {
294+ self . binary_op (
295+ bin_op,
296+ left. to_scalar ( ) ?, left. layout ,
297+ right. to_scalar ( ) ?, right. layout ,
298+ )
299+ }
300+
285301 /// Returns the result of the specified operation and whether it overflowed.
286302 pub fn binary_op (
287303 & self ,
288304 bin_op : mir:: BinOp ,
289- ValTy { value : left, layout : left_layout } : ValTy < ' tcx > ,
290- ValTy { value : right, layout : right_layout } : ValTy < ' tcx > ,
305+ left : Scalar ,
306+ left_layout : TyLayout < ' tcx > ,
307+ right : Scalar ,
308+ right_layout : TyLayout < ' tcx > ,
291309 ) -> EvalResult < ' tcx , ( Scalar , bool ) > {
292- let left = left. to_scalar ( ) ?;
293- let right = right. to_scalar ( ) ?;
294-
295310 trace ! ( "Running binary op {:?}: {:?} ({:?}), {:?} ({:?})" ,
296311 bin_op, left, left_layout. ty, right, right_layout. ty) ;
297312
@@ -322,15 +337,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
322337 right_layout. ty. is_fn( ) ) ;
323338
324339 // Handle operations that support pointer values
325- if let Some ( handled) =
326- M :: try_ptr_op ( self , bin_op, left, left_layout, right, right_layout) ?
327- {
328- return Ok ( handled) ;
340+ if left. is_ptr ( ) || right. is_ptr ( ) || bin_op == mir:: BinOp :: Offset {
341+ return M :: ptr_op ( self , bin_op, left, left_layout, right, right_layout) ;
329342 }
330343
331344 // Everything else only works with "proper" bits
332- let left = left. to_bits ( left_layout. size ) ? ;
333- let right = right. to_bits ( right_layout. size ) ? ;
345+ let left = left. to_bits ( left_layout. size ) . expect ( "we checked is_ptr" ) ;
346+ let right = right. to_bits ( right_layout. size ) . expect ( "we checked is_ptr" ) ;
334347 self . binary_int_op ( bin_op, left, left_layout, right, right_layout)
335348 }
336349 }
0 commit comments