@@ -367,7 +367,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
367
367
let bytes = self . get_bytes_with_undef_and_ptr ( cx, ptr, size) ?;
368
368
// Undef check happens *after* we established that the alignment is correct.
369
369
// We must not return `Ok()` for unaligned pointers!
370
- if self . check_defined ( ptr, size) . is_err ( ) {
370
+ if self . is_defined ( ptr, size) . is_err ( ) {
371
371
// This inflates undefined bytes to the entire scalar, even if only a few
372
372
// bytes are undefined.
373
373
return Ok ( ScalarMaybeUndef :: Undef ) ;
@@ -552,13 +552,19 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
552
552
}
553
553
554
554
/// Undefined bytes.
555
- impl < ' tcx , Tag , Extra > Allocation < Tag , Extra > {
555
+ impl < ' tcx , Tag : Copy , Extra > Allocation < Tag , Extra > {
556
+ /// Checks whether the given range is entirely defined.
557
+ ///
558
+ /// Returns `Ok(())` if it's defined. Otherwise returns the index of the byte
559
+ /// at which the first undefined access begins.
560
+ fn is_defined ( & self , ptr : Pointer < Tag > , size : Size ) -> Result < ( ) , Size > {
561
+ self . undef_mask . is_range_defined ( ptr. offset , ptr. offset + size) // `Size` addition
562
+ }
563
+
556
564
/// Checks that a range of bytes is defined. If not, returns the `ReadUndefBytes`
557
565
/// error which will report the first byte which is undefined.
558
- #[ inline]
559
566
fn check_defined ( & self , ptr : Pointer < Tag > , size : Size ) -> InterpResult < ' tcx > {
560
- self . undef_mask
561
- . is_range_defined ( ptr. offset , ptr. offset + size) // `Size` addition
567
+ self . is_defined ( ptr, size)
562
568
. or_else ( |idx| throw_ub ! ( InvalidUndefBytes ( Some ( Pointer :: new( ptr. alloc_id, idx) ) ) ) )
563
569
}
564
570
0 commit comments