@@ -46,13 +46,17 @@ macro_rules! try_validation {
46
46
( $e: expr, $what: expr, $where: expr, $details: expr) => { {
47
47
match $e {
48
48
Ok ( x) => x,
49
+ // We re-throw the error, so we are okay with allocation:
50
+ // this can only slow down builds that fail anyway.
49
51
Err ( _) => throw_validation_failure!( $what, $where, $details) ,
50
52
}
51
53
} } ;
52
54
53
55
( $e: expr, $what: expr, $where: expr) => { {
54
56
match $e {
55
57
Ok ( x) => x,
58
+ // We re-throw the error, so we are okay with allocation:
59
+ // this can only slow down builds that fail anyway.
56
60
Err ( _) => throw_validation_failure!( $what, $where) ,
57
61
}
58
62
} } ;
@@ -359,10 +363,13 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
359
363
format_args!( "a dangling {} (created from integer)" , kind) ,
360
364
self . path
361
365
) ,
362
- _ => throw_validation_failure ! (
363
- format_args!( "a dangling {} (not entirely in bounds)" , kind) ,
364
- self . path
365
- ) ,
366
+ err_unsup ! ( PointerOutOfBounds { .. } ) | err_unsup ! ( DanglingPointerDeref ) => {
367
+ throw_validation_failure ! (
368
+ format_args!( "a dangling {} (not entirely in bounds)" , kind) ,
369
+ self . path
370
+ )
371
+ }
372
+ _ => bug ! ( "Unexpected error during ptr inbounds test: {}" , err) ,
366
373
}
367
374
}
368
375
} ;
@@ -638,6 +645,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
638
645
err_unsup ! ( ReadPointerAsBytes ) => {
639
646
throw_validation_failure ! ( "a pointer" , self . path, "plain (non-pointer) bytes" )
640
647
}
648
+ // Propagate upwards (that will also check for unexpected errors).
641
649
_ => return Err ( err) ,
642
650
} ,
643
651
}
@@ -797,7 +805,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
797
805
// Try to cast to ptr *once* instead of all the time.
798
806
let op = self . force_op_ptr ( op) . unwrap_or ( op) ;
799
807
800
- // Run it
801
- visitor. visit_value ( op)
808
+ // Run it.
809
+ match visitor. visit_value ( op) {
810
+ Ok ( ( ) ) => Ok ( ( ) ) ,
811
+ Err ( err) if matches ! ( err. kind, err_unsup!( ValidationFailure { .. } ) ) => Err ( err) ,
812
+ Err ( err) if cfg ! ( debug_assertions) => {
813
+ bug ! ( "Unexpected error during validation: {}" , err)
814
+ }
815
+ Err ( err) => Err ( err) ,
816
+ }
802
817
}
803
818
}
0 commit comments