@@ -28,7 +28,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
28
28
right : ValTy < ' tcx > ,
29
29
dest : PlaceTy < ' tcx > ,
30
30
) -> EvalResult < ' tcx > {
31
- let ( val, overflowed) = self . binary_op ( op, left, right) ?;
31
+ let ( val, overflowed) = self . binary_op_val ( op, left, right) ?;
32
32
let val = Value :: ScalarPair ( val. into ( ) , Scalar :: from_bool ( overflowed) . into ( ) ) ;
33
33
self . write_value ( val, dest)
34
34
}
@@ -42,7 +42,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
42
42
right : ValTy < ' tcx > ,
43
43
dest : PlaceTy < ' tcx > ,
44
44
) -> EvalResult < ' tcx > {
45
- let ( val, _overflowed) = self . binary_op ( op, left, right) ?;
45
+ let ( val, _overflowed) = self . binary_op_val ( op, left, right) ?;
46
46
self . write_scalar ( val, dest)
47
47
}
48
48
}
@@ -282,16 +282,31 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
282
282
Ok ( ( val, false ) )
283
283
}
284
284
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
+
285
301
/// Returns the result of the specified operation and whether it overflowed.
286
302
pub fn binary_op (
287
303
& self ,
288
304
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 > ,
291
309
) -> EvalResult < ' tcx , ( Scalar , bool ) > {
292
- let left = left. to_scalar ( ) ?;
293
- let right = right. to_scalar ( ) ?;
294
-
295
310
trace ! ( "Running binary op {:?}: {:?} ({:?}), {:?} ({:?})" ,
296
311
bin_op, left, left_layout. ty, right, right_layout. ty) ;
297
312
@@ -322,15 +337,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
322
337
right_layout. ty. is_fn( ) ) ;
323
338
324
339
// 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) ;
329
342
}
330
343
331
344
// 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" ) ;
334
347
self . binary_int_op ( bin_op, left, left_layout, right, right_layout)
335
348
}
336
349
}
0 commit comments