@@ -20,8 +20,8 @@ use rustc_target::abi::{Abi, Scalar as ScalarAbi, Size, VariantIdx, Variants, Wr
2020use std:: hash:: Hash ;
2121
2222use 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 ,
2525} ;
2626
2727macro_rules! throw_validation_failure {
@@ -312,7 +312,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
312312 Ok ( try_validation ! (
313313 self . ecx. read_immediate( op) ,
314314 self . path,
315- err_unsup!( ReadPointerAsBytes ) => { "(potentially part of) a pointer" } expected { "{expected}" } ,
316315 err_ub!( InvalidUninitBytes ( None ) ) => { "uninitialized memory" } expected { "{expected}" }
317316 ) )
318317 }
@@ -345,11 +344,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
345344 // FIXME: check if the type/trait match what ty::Dynamic says?
346345 }
347346 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 ) ?;
353348 // We do not check that `len * elem_size <= isize::MAX`:
354349 // that is only required for references, and there it falls out of the
355350 // "dereferenceable" check performed by Stacked Borrows.
@@ -669,8 +664,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
669664 { "{:x}" , val } expected { "a valid enum tag" } ,
670665 err_ub!( InvalidUninitBytes ( None ) ) =>
671666 { "uninitialized bytes" } expected { "a valid enum tag" } ,
672- err_unsup!( ReadPointerAsBytes ) =>
673- { "a pointer" } expected { "a valid enum tag" } ,
674667 )
675668 . 1 )
676669 } )
@@ -810,10 +803,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
810803 let mplace = op. assert_mem_place ( ) ; // strings are unsized and hence never immediate
811804 let len = mplace. len ( self . ecx ) ?;
812805 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) ) ,
814807 self . path,
815808 err_ub!( InvalidUninitBytes ( ..) ) => { "uninitialized data in `str`" } ,
816- err_unsup!( ReadPointerAsBytes ) => { "a pointer in `str`" } ,
817809 ) ;
818810 }
819811 ty:: Array ( tys, ..) | ty:: Slice ( tys)
@@ -861,9 +853,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
861853 // We also accept uninit, for consistency with the slow path.
862854 let alloc = self . ecx . get_ptr_alloc ( mplace. ptr , size, mplace. align ) ?. expect ( "we already excluded size 0" ) ;
863855
864- match alloc. check_bytes ( alloc_range ( Size :: ZERO , size ) ) {
856+ match alloc. get_bytes_strip_provenance ( ) {
865857 // In the happy case, we needn't check anything else.
866- Ok ( ( ) ) => { }
858+ Ok ( _ ) => { }
867859 // Some error happened, try to provide a more detailed description.
868860 Err ( err) => {
869861 // 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>
881873
882874 throw_validation_failure ! ( self . path, { "uninitialized bytes" } )
883875 }
884- err_unsup ! ( ReadPointerAsBytes ) => {
885- throw_validation_failure ! ( self . path, { "a pointer" } expected { "plain (non-pointer) bytes" } )
886- }
887876
888877 // Propagate upwards (that will also check for unexpected errors).
889878 _ => return Err ( err) ,
@@ -924,14 +913,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
924913 Ok ( ( ) ) => Ok ( ( ) ) ,
925914 // Pass through validation failures.
926915 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 ( _) ) => {
932919 err. print_backtrace ( ) ;
933- bug ! ( "Unexpected error during validation: {}" , err) ;
920+ bug ! ( "Unexpected Undefined Behavior error during validation: {}" , err) ;
934921 }
922+ // Pass through everything else.
923+ Err ( err) => Err ( err) ,
935924 }
936925 }
937926
0 commit comments