@@ -4,7 +4,7 @@ use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
44use rustc:: mir;
55use rustc:: ty:: {
66 self ,
7- layout:: { self , Align , Size , LayoutOf } ,
7+ layout:: { self , Align , LayoutOf , Size } ,
88} ;
99
1010use rand:: RngCore ;
@@ -328,11 +328,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
328328 let allocation = this. memory_mut ( ) . get_mut ( ptr. alloc_id ) ?;
329329 let mut offset = Size :: from_bytes ( 0 ) ;
330330
331- for ( value, size) in bits. iter ( ) . zip ( sizes) {
331+ for ( & value, size) in bits. iter ( ) . zip ( sizes) {
332+ // If `value` does not fit in `size` bits, we error instead of letting
333+ // `Scalar::from_int` panic.
334+ let truncated = truncate ( value as u128 , size) ;
335+ if sign_extend ( truncated, size) as i128 != value {
336+ throw_unsup_format ! (
337+ "Signed value {:#x} does not fit in {} bits" ,
338+ value,
339+ size. bits( )
340+ )
341+ }
342+
332343 allocation. write_scalar (
333344 tcx,
334345 ptr. offset ( offset, tcx) ?,
335- Scalar :: from_int ( * value, size) . into ( ) ,
346+ Scalar :: from_int ( value, size) . into ( ) ,
336347 size,
337348 ) ?;
338349 offset += size;
0 commit comments