2
2
//! looking at their MIR. Intrinsics/functions supported here are shared by CTFE
3
3
//! and miri.
4
4
5
+ use std:: convert:: TryFrom ;
6
+
5
7
use rustc:: mir:: {
6
8
self ,
7
9
interpret:: { ConstValue , GlobalId , InterpResult , Scalar } ,
@@ -220,7 +222,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
220
222
sym:: discriminant_value => {
221
223
let place = self . deref_operand ( args[ 0 ] ) ?;
222
224
let discr_val = self . read_discriminant ( place. into ( ) ) ?. 0 ;
223
- self . write_scalar ( Scalar :: from_uint ( discr_val, dest . layout . size ) , dest) ?;
225
+ self . write_scalar ( Scalar :: from_u64 ( u64 :: try_from ( discr_val) . unwrap ( ) ) , dest) ?;
224
226
}
225
227
sym:: unchecked_shl
226
228
| sym:: unchecked_shr
@@ -275,7 +277,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
275
277
}
276
278
277
279
sym:: ptr_offset_from => {
278
- let isize_layout = self . layout_of ( self . tcx . types . isize ) ?;
279
280
let a = self . read_immediate ( args[ 0 ] ) ?. to_scalar ( ) ?;
280
281
let b = self . read_immediate ( args[ 1 ] ) ?. to_scalar ( ) ?;
281
282
@@ -292,7 +293,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
292
293
let a = a. to_machine_usize ( self ) ?;
293
294
let b = b. to_machine_usize ( self ) ?;
294
295
if a == b && a != 0 {
295
- self . write_scalar ( Scalar :: from_int ( 0 , isize_layout . size ) , dest) ?;
296
+ self . write_scalar ( Scalar :: from_machine_isize ( 0 , self ) , dest) ?;
296
297
true
297
298
} else {
298
299
false
@@ -312,6 +313,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
312
313
) ;
313
314
}
314
315
let usize_layout = self . layout_of ( self . tcx . types . usize ) ?;
316
+ let isize_layout = self . layout_of ( self . tcx . types . isize ) ?;
315
317
let a_offset = ImmTy :: from_uint ( a. offset . bytes ( ) , usize_layout) ;
316
318
let b_offset = ImmTy :: from_uint ( b. offset . bytes ( ) , usize_layout) ;
317
319
let ( val, _overflowed, _ty) =
0 commit comments