File tree 2 files changed +16
-1
lines changed
src/librustc_middle/mir/interpret
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -360,6 +360,11 @@ pub enum UndefinedBehaviorInfo {
360
360
InvalidUndefBytes ( Option < Pointer > ) ,
361
361
/// Working with a local that is not currently live.
362
362
DeadLocal ,
363
+ /// Data size is not equal to target size.
364
+ ScalarSizeMismatch {
365
+ target_size : u64 ,
366
+ data_size : u64 ,
367
+ } ,
363
368
}
364
369
365
370
impl fmt:: Debug for UndefinedBehaviorInfo {
@@ -421,6 +426,11 @@ impl fmt::Debug for UndefinedBehaviorInfo {
421
426
"using uninitialized data, but this operation requires initialized memory"
422
427
) ,
423
428
DeadLocal => write ! ( f, "accessing a dead local variable" ) ,
429
+ ScalarSizeMismatch { target_size, data_size } => write ! (
430
+ f,
431
+ "scalar size mismatch: expected {} bytes but got {} bytes instead" ,
432
+ target_size, data_size
433
+ ) ,
424
434
}
425
435
}
426
436
}
Original file line number Diff line number Diff line change @@ -393,7 +393,12 @@ impl<'tcx, Tag> Scalar<Tag> {
393
393
assert_ne ! ( target_size. bytes( ) , 0 , "you should never look at the bits of a ZST" ) ;
394
394
match self {
395
395
Scalar :: Raw { data, size } => {
396
- assert_eq ! ( target_size. bytes( ) , u64 :: from( size) ) ;
396
+ if target_size. bytes ( ) != u64:: from ( size) {
397
+ throw_ub ! ( ScalarSizeMismatch {
398
+ target_size: target_size. bytes( ) ,
399
+ data_size: u64 :: from( size) ,
400
+ } ) ;
401
+ }
397
402
Scalar :: check_data ( data, size) ;
398
403
Ok ( data)
399
404
}
You can’t perform that action at this time.
0 commit comments