@@ -19,6 +19,8 @@ use rustc_target::abi::{Abi, Scalar as ScalarAbi, Size, VariantIdx, Variants, Wr
19
19
20
20
use std:: hash:: Hash ;
21
21
22
+ // for the validation errors
23
+ use super :: UndefinedBehaviorInfo :: * ;
22
24
use super :: {
23
25
CheckInAllocMsg , GlobalAlloc , ImmTy , Immediate , InterpCx , InterpResult , MPlaceTy , Machine ,
24
26
MemPlaceMeta , OpTy , Scalar , ValueVisitor ,
@@ -59,6 +61,7 @@ macro_rules! throw_validation_failure {
59
61
/// });
60
62
/// ```
61
63
///
64
+ /// The patterns must be of type `UndefinedBehaviorInfo`.
62
65
/// An additional expected parameter can also be added to the failure message:
63
66
///
64
67
/// ```
@@ -86,7 +89,7 @@ macro_rules! try_validation {
86
89
// allocation here as this can only slow down builds that fail anyway.
87
90
Err ( e) => match e. kind( ) {
88
91
$(
89
- $( $p) |+ =>
92
+ InterpError :: UndefinedBehavior ( $( $p) |+) =>
90
93
throw_validation_failure!(
91
94
$where,
92
95
{ $( $what_fmt ) ,+ } $( expected { $( $expected_fmt ) ,+ } ) ?
@@ -312,7 +315,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
312
315
Ok ( try_validation ! (
313
316
self . ecx. read_immediate( op) ,
314
317
self . path,
315
- err_ub! ( InvalidUninitBytes ( None ) ) => { "uninitialized memory" } expected { "{expected}" }
318
+ InvalidUninitBytes ( None ) => { "uninitialized memory" } expected { "{expected}" }
316
319
) )
317
320
}
318
321
@@ -337,8 +340,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
337
340
let ( _ty, _trait) = try_validation ! (
338
341
self . ecx. get_ptr_vtable( vtable) ,
339
342
self . path,
340
- err_ub! ( DanglingIntPointer ( ..) ) |
341
- err_ub! ( InvalidVTablePointer ( ..) ) =>
343
+ DanglingIntPointer ( ..) |
344
+ InvalidVTablePointer ( ..) =>
342
345
{ "{vtable}" } expected { "a vtable pointer" } ,
343
346
) ;
344
347
// FIXME: check if the type/trait match what ty::Dynamic says?
@@ -374,7 +377,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
374
377
let size_and_align = try_validation ! (
375
378
self . ecx. size_and_align_of_mplace( & place) ,
376
379
self . path,
377
- err_ub! ( InvalidMeta ( msg) ) => { "invalid {} metadata: {}" , kind, msg } ,
380
+ InvalidMeta ( msg) => { "invalid {} metadata: {}" , kind, msg } ,
378
381
) ;
379
382
let ( size, align) = size_and_align
380
383
// for the purpose of validity, consider foreign types to have
@@ -390,21 +393,21 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
390
393
CheckInAllocMsg :: InboundsTest , // will anyway be replaced by validity message
391
394
) ,
392
395
self . path,
393
- err_ub! ( AlignmentCheckFailed { required, has } ) =>
396
+ AlignmentCheckFailed { required, has } =>
394
397
{
395
398
"an unaligned {kind} (required {} byte alignment but found {})" ,
396
399
required. bytes( ) ,
397
400
has. bytes( )
398
401
} ,
399
- err_ub! ( DanglingIntPointer ( 0 , _) ) =>
402
+ DanglingIntPointer ( 0 , _) =>
400
403
{ "a null {kind}" } ,
401
- err_ub! ( DanglingIntPointer ( i, _) ) =>
404
+ DanglingIntPointer ( i, _) =>
402
405
{ "a dangling {kind} (address {i:#x} is unallocated)" } ,
403
- err_ub! ( PointerOutOfBounds { .. } ) =>
406
+ PointerOutOfBounds { .. } =>
404
407
{ "a dangling {kind} (going beyond the bounds of its allocation)" } ,
405
408
// This cannot happen during const-eval (because interning already detects
406
409
// dangling pointers), but it can happen in Miri.
407
- err_ub! ( PointerUseAfterFree ( ..) ) =>
410
+ PointerUseAfterFree ( ..) =>
408
411
{ "a dangling {kind} (use-after-free)" } ,
409
412
) ;
410
413
// Do not allow pointers to uninhabited types.
@@ -475,7 +478,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
475
478
try_validation ! (
476
479
value. to_bool( ) ,
477
480
self . path,
478
- err_ub! ( InvalidBool ( ..) ) =>
481
+ InvalidBool ( ..) =>
479
482
{ "{:x}" , value } expected { "a boolean" } ,
480
483
) ;
481
484
Ok ( true )
@@ -485,7 +488,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
485
488
try_validation ! (
486
489
value. to_char( ) ,
487
490
self . path,
488
- err_ub! ( InvalidChar ( ..) ) =>
491
+ InvalidChar ( ..) =>
489
492
{ "{:x}" , value } expected { "a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)" } ,
490
493
) ;
491
494
Ok ( true )
@@ -544,8 +547,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
544
547
let _fn = try_validation ! (
545
548
self . ecx. get_ptr_fn( ptr) ,
546
549
self . path,
547
- err_ub! ( DanglingIntPointer ( ..) ) |
548
- err_ub! ( InvalidFunctionPointer ( ..) ) =>
550
+ DanglingIntPointer ( ..) |
551
+ InvalidFunctionPointer ( ..) =>
549
552
{ "{ptr}" } expected { "a function pointer" } ,
550
553
) ;
551
554
// FIXME: Check if the signature matches
@@ -660,9 +663,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
660
663
Ok ( try_validation ! (
661
664
this. ecx. read_discriminant( op) ,
662
665
this. path,
663
- err_ub! ( InvalidTag ( val) ) =>
666
+ InvalidTag ( val) =>
664
667
{ "{:x}" , val } expected { "a valid enum tag" } ,
665
- err_ub! ( InvalidUninitBytes ( None ) ) =>
668
+ InvalidUninitBytes ( None ) =>
666
669
{ "uninitialized bytes" } expected { "a valid enum tag" } ,
667
670
)
668
671
. 1 )
@@ -805,7 +808,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
805
808
try_validation ! (
806
809
self . ecx. read_bytes_ptr_strip_provenance( mplace. ptr, Size :: from_bytes( len) ) ,
807
810
self . path,
808
- err_ub! ( InvalidUninitBytes ( ..) ) => { "uninitialized data in `str`" } ,
811
+ InvalidUninitBytes ( ..) => { "uninitialized data in `str`" } ,
809
812
) ;
810
813
}
811
814
ty:: Array ( tys, ..) | ty:: Slice ( tys)
0 commit comments