@@ -20,8 +20,8 @@ use rustc_target::abi::{Abi, Scalar as ScalarAbi, Size, VariantIdx, Variants, Wr
20
20
use std:: hash:: Hash ;
21
21
22
22
use super :: {
23
- alloc_range , CheckInAllocMsg , GlobalAlloc , ImmTy , Immediate , InterpCx , InterpResult , MPlaceTy ,
24
- Machine , MemPlaceMeta , OpTy , Scalar , ValueVisitor ,
23
+ CheckInAllocMsg , GlobalAlloc , ImmTy , Immediate , InterpCx , InterpResult , MPlaceTy , Machine ,
24
+ MemPlaceMeta , OpTy , Scalar , ValueVisitor ,
25
25
} ;
26
26
27
27
macro_rules! throw_validation_failure {
@@ -312,7 +312,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
312
312
Ok ( try_validation ! (
313
313
self . ecx. read_immediate( op) ,
314
314
self . path,
315
- err_unsup!( ReadPointerAsBytes ) => { "(potentially part of) a pointer" } expected { "{expected}" } ,
316
315
err_ub!( InvalidUninitBytes ( None ) ) => { "uninitialized memory" } expected { "{expected}" }
317
316
) )
318
317
}
@@ -345,11 +344,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
345
344
// FIXME: check if the type/trait match what ty::Dynamic says?
346
345
}
347
346
ty:: Slice ( ..) | ty:: Str => {
348
- let _len = try_validation ! (
349
- meta. unwrap_meta( ) . to_machine_usize( self . ecx) ,
350
- self . path,
351
- err_unsup!( ReadPointerAsBytes ) => { "non-integer slice length in wide pointer" } ,
352
- ) ;
347
+ let _len = meta. unwrap_meta ( ) . to_machine_usize ( self . ecx ) ?;
353
348
// We do not check that `len * elem_size <= isize::MAX`:
354
349
// that is only required for references, and there it falls out of the
355
350
// "dereferenceable" check performed by Stacked Borrows.
@@ -669,8 +664,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
669
664
{ "{:x}" , val } expected { "a valid enum tag" } ,
670
665
err_ub!( InvalidUninitBytes ( None ) ) =>
671
666
{ "uninitialized bytes" } expected { "a valid enum tag" } ,
672
- err_unsup!( ReadPointerAsBytes ) =>
673
- { "a pointer" } expected { "a valid enum tag" } ,
674
667
)
675
668
. 1 )
676
669
} )
@@ -810,10 +803,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
810
803
let mplace = op. assert_mem_place ( ) ; // strings are unsized and hence never immediate
811
804
let len = mplace. len ( self . ecx ) ?;
812
805
try_validation ! (
813
- self . ecx. read_bytes_ptr ( mplace. ptr, Size :: from_bytes( len) ) ,
806
+ self . ecx. read_bytes_ptr_strip_provenance ( mplace. ptr, Size :: from_bytes( len) ) ,
814
807
self . path,
815
808
err_ub!( InvalidUninitBytes ( ..) ) => { "uninitialized data in `str`" } ,
816
- err_unsup!( ReadPointerAsBytes ) => { "a pointer in `str`" } ,
817
809
) ;
818
810
}
819
811
ty:: Array ( tys, ..) | ty:: Slice ( tys)
@@ -861,9 +853,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
861
853
// We also accept uninit, for consistency with the slow path.
862
854
let alloc = self . ecx . get_ptr_alloc ( mplace. ptr , size, mplace. align ) ?. expect ( "we already excluded size 0" ) ;
863
855
864
- match alloc. check_bytes ( alloc_range ( Size :: ZERO , size ) ) {
856
+ match alloc. get_bytes_strip_provenance ( ) {
865
857
// In the happy case, we needn't check anything else.
866
- Ok ( ( ) ) => { }
858
+ Ok ( _ ) => { }
867
859
// Some error happened, try to provide a more detailed description.
868
860
Err ( err) => {
869
861
// For some errors we might be able to provide extra information.
@@ -881,9 +873,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
881
873
882
874
throw_validation_failure ! ( self . path, { "uninitialized bytes" } )
883
875
}
884
- err_unsup ! ( ReadPointerAsBytes ) => {
885
- throw_validation_failure ! ( self . path, { "a pointer" } expected { "plain (non-pointer) bytes" } )
886
- }
887
876
888
877
// Propagate upwards (that will also check for unexpected errors).
889
878
_ => return Err ( err) ,
@@ -924,14 +913,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
924
913
Ok ( ( ) ) => Ok ( ( ) ) ,
925
914
// Pass through validation failures.
926
915
Err ( err) if matches ! ( err. kind( ) , err_ub!( ValidationFailure { .. } ) ) => Err ( err) ,
927
- // Also pass through InvalidProgram, those just indicate that we could not
928
- // validate and each caller will know best what to do with them.
929
- Err ( err) if matches ! ( err. kind( ) , InterpError :: InvalidProgram ( _) ) => Err ( err) ,
930
- // Avoid other errors as those do not show *where* in the value the issue lies.
931
- Err ( err) => {
916
+ // Complain about any other kind of UB error -- those are bad because we'd like to
917
+ // report them in a way that shows *where* in the value the issue lies.
918
+ Err ( err) if matches ! ( err. kind( ) , InterpError :: UndefinedBehavior ( _) ) => {
932
919
err. print_backtrace ( ) ;
933
- bug ! ( "Unexpected error during validation: {}" , err) ;
920
+ bug ! ( "Unexpected Undefined Behavior error during validation: {}" , err) ;
934
921
}
922
+ // Pass through everything else.
923
+ Err ( err) => Err ( err) ,
935
924
}
936
925
}
937
926
0 commit comments