@@ -4,7 +4,7 @@ use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
4
4
use rustc:: mir;
5
5
use rustc:: ty:: {
6
6
self ,
7
- layout:: { self , Align , Size , LayoutOf } ,
7
+ layout:: { self , Align , LayoutOf , Size } ,
8
8
} ;
9
9
10
10
use rand:: RngCore ;
@@ -316,11 +316,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
316
316
let allocation = this. memory_mut ( ) . get_mut ( ptr. alloc_id ) ?;
317
317
let mut offset = Size :: from_bytes ( 0 ) ;
318
318
319
- for ( value, size) in bits. iter ( ) . zip ( sizes) {
319
+ for ( & value, size) in bits. iter ( ) . zip ( sizes) {
320
+ // If `value` does not fit in `size` bits, we error instead of letting
321
+ // `Scalar::from_int` panic.
322
+ let truncated = truncate ( value as u128 , size) ;
323
+ if sign_extend ( truncated, size) as i128 != value {
324
+ throw_unsup_format ! (
325
+ "Signed value {:#x} does not fit in {} bits" ,
326
+ value,
327
+ size. bits( )
328
+ )
329
+ }
330
+
320
331
allocation. write_scalar (
321
332
tcx,
322
333
ptr. offset ( offset, tcx) ?,
323
- Scalar :: from_int ( * value, size) . into ( ) ,
334
+ Scalar :: from_int ( value, size) . into ( ) ,
324
335
size,
325
336
) ?;
326
337
offset += size;
0 commit comments