@@ -210,7 +210,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
210210 let new_ptr = self . allocate ( new_size, new_align, kind) ;
211211 let old_size = match old_size_and_align {
212212 Some ( ( size, _align) ) => size,
213- None => Size :: from_bytes ( self . get ( ptr. alloc_id ) ?. bytes . len ( ) as u64 ) ,
213+ None => self . get ( ptr. alloc_id ) ?. size ,
214214 } ;
215215 self . copy (
216216 ptr,
@@ -271,20 +271,20 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
271271 ) )
272272 }
273273 if let Some ( ( size, align) ) = old_size_and_align {
274- if size. bytes ( ) != alloc. bytes . len ( ) as u64 || align != alloc. align {
275- let bytes = Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) ;
274+ if size != alloc. size || align != alloc. align {
275+ let bytes = alloc. size ;
276276 throw_unsup ! ( IncorrectAllocationInformation ( size, bytes, align, alloc. align) )
277277 }
278278 }
279279
280280 // Let the machine take some extra action
281- let size = Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) ;
281+ let size = alloc. size ;
282282 AllocationExtra :: memory_deallocated ( & mut alloc, ptr, size) ?;
283283
284284 // Don't forget to remember size and align of this now-dead allocation
285285 let old = self . dead_alloc_map . insert (
286286 ptr. alloc_id ,
287- ( Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) , alloc. align )
287+ ( alloc. size , alloc. align )
288288 ) ;
289289 if old. is_some ( ) {
290290 bug ! ( "Nothing can be deallocated twice" ) ;
@@ -555,7 +555,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
555555 // a) cause cycles in case `id` refers to a static
556556 // b) duplicate a static's allocation in miri
557557 if let Some ( ( _, alloc) ) = self . alloc_map . get ( id) {
558- return Ok ( ( Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) , alloc. align ) ) ;
558+ return Ok ( ( alloc. size , alloc. align ) ) ;
559559 }
560560
561561 // # Function pointers
@@ -583,7 +583,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
583583 Some ( GlobalAlloc :: Memory ( alloc) ) =>
584584 // Need to duplicate the logic here, because the global allocations have
585585 // different associated types than the interpreter-local ones.
586- Ok ( ( Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) , alloc. align ) ) ,
586+ Ok ( ( alloc. size , alloc. align ) ) ,
587587 Some ( GlobalAlloc :: Function ( _) ) =>
588588 bug ! ( "We already checked function pointers above" ) ,
589589 // The rest must be dead.
@@ -645,7 +645,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
645645 let prefix_len = msg. len ( ) ;
646646 let mut relocations = vec ! [ ] ;
647647
648- for i in 0 ..( alloc. bytes . len ( ) as u64 ) {
648+ for i in 0 ..alloc. size . bytes ( ) {
649649 let i = Size :: from_bytes ( i) ;
650650 if let Some ( & ( _, target_id) ) = alloc. relocations . get ( & i) {
651651 if allocs_seen. insert ( target_id) {
@@ -655,7 +655,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
655655 }
656656 if alloc. undef_mask . is_range_defined ( i, i + Size :: from_bytes ( 1 ) ) . is_ok ( ) {
657657 // this `as usize` is fine, since `i` came from a `usize`
658- write ! ( msg, "{:02x} " , alloc. bytes[ i. bytes( ) as usize ] ) . unwrap ( ) ;
658+ let i = i. bytes ( ) as usize ;
659+
660+ // Checked definedness (and thus range) and relocations. This access also doesn't
661+ // influence interpreter execution but is only for debugging.
662+ let bytes = alloc. inspect_with_undef_and_ptr_outside_interpreter ( i..i+1 ) ;
663+ write ! ( msg, "{:02x} " , bytes[ 0 ] ) . unwrap ( ) ;
659664 } else {
660665 msg. push_str ( "__ " ) ;
661666 }
@@ -664,7 +669,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
664669 trace ! (
665670 "{}({} bytes, alignment {}){}" ,
666671 msg,
667- alloc. bytes . len ( ) ,
672+ alloc. size . bytes ( ) ,
668673 alloc. align. bytes( ) ,
669674 extra
670675 ) ;
0 commit comments