22//! looking at their MIR. Intrinsics/functions supported here are shared by CTFE
33//! and miri.
44
5+ use std:: convert:: TryFrom ;
6+
57use rustc:: mir:: {
68 self ,
79 interpret:: { ConstValue , GlobalId , InterpResult , Scalar } ,
@@ -220,7 +222,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
220222 sym:: discriminant_value => {
221223 let place = self . deref_operand ( args[ 0 ] ) ?;
222224 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) ?;
224226 }
225227 sym:: unchecked_shl
226228 | sym:: unchecked_shr
@@ -275,7 +277,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
275277 }
276278
277279 sym:: ptr_offset_from => {
278- let isize_layout = self . layout_of ( self . tcx . types . isize ) ?;
279280 let a = self . read_immediate ( args[ 0 ] ) ?. to_scalar ( ) ?;
280281 let b = self . read_immediate ( args[ 1 ] ) ?. to_scalar ( ) ?;
281282
@@ -292,7 +293,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
292293 let a = a. to_machine_usize ( self ) ?;
293294 let b = b. to_machine_usize ( self ) ?;
294295 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) ?;
296297 true
297298 } else {
298299 false
@@ -312,6 +313,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
312313 ) ;
313314 }
314315 let usize_layout = self . layout_of ( self . tcx . types . usize ) ?;
316+ let isize_layout = self . layout_of ( self . tcx . types . isize ) ?;
315317 let a_offset = ImmTy :: from_uint ( a. offset . bytes ( ) , usize_layout) ;
316318 let b_offset = ImmTy :: from_uint ( b. offset . bytes ( ) , usize_layout) ;
317319 let ( val, _overflowed, _ty) =
0 commit comments