@@ -210,7 +210,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
210
210
let new_ptr = self . allocate ( new_size, new_align, kind) ;
211
211
let old_size = match old_size_and_align {
212
212
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 ,
214
214
} ;
215
215
self . copy (
216
216
ptr,
@@ -271,20 +271,20 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
271
271
) )
272
272
}
273
273
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 ;
276
276
throw_unsup ! ( IncorrectAllocationInformation ( size, bytes, align, alloc. align) )
277
277
}
278
278
}
279
279
280
280
// Let the machine take some extra action
281
- let size = Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) ;
281
+ let size = alloc. size ;
282
282
AllocationExtra :: memory_deallocated ( & mut alloc, ptr, size) ?;
283
283
284
284
// Don't forget to remember size and align of this now-dead allocation
285
285
let old = self . dead_alloc_map . insert (
286
286
ptr. alloc_id ,
287
- ( Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) , alloc. align )
287
+ ( alloc. size , alloc. align )
288
288
) ;
289
289
if old. is_some ( ) {
290
290
bug ! ( "Nothing can be deallocated twice" ) ;
@@ -555,7 +555,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
555
555
// a) cause cycles in case `id` refers to a static
556
556
// b) duplicate a static's allocation in miri
557
557
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 ) ) ;
559
559
}
560
560
561
561
// # Function pointers
@@ -583,7 +583,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
583
583
Some ( GlobalAlloc :: Memory ( alloc) ) =>
584
584
// Need to duplicate the logic here, because the global allocations have
585
585
// 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 ) ) ,
587
587
Some ( GlobalAlloc :: Function ( _) ) =>
588
588
bug ! ( "We already checked function pointers above" ) ,
589
589
// The rest must be dead.
@@ -645,7 +645,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
645
645
let prefix_len = msg. len ( ) ;
646
646
let mut relocations = vec ! [ ] ;
647
647
648
- for i in 0 ..( alloc. bytes . len ( ) as u64 ) {
648
+ for i in 0 ..alloc. size . bytes ( ) {
649
649
let i = Size :: from_bytes ( i) ;
650
650
if let Some ( & ( _, target_id) ) = alloc. relocations . get ( & i) {
651
651
if allocs_seen. insert ( target_id) {
@@ -655,7 +655,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
655
655
}
656
656
if alloc. undef_mask . is_range_defined ( i, i + Size :: from_bytes ( 1 ) ) . is_ok ( ) {
657
657
// 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 ( ) ;
659
664
} else {
660
665
msg. push_str ( "__ " ) ;
661
666
}
@@ -664,7 +669,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
664
669
trace ! (
665
670
"{}({} bytes, alignment {}){}" ,
666
671
msg,
667
- alloc. bytes . len ( ) ,
672
+ alloc. size . bytes ( ) ,
668
673
alloc. align. bytes( ) ,
669
674
extra
670
675
) ;
0 commit comments