@@ -11,7 +11,7 @@ use rand::Rng;
1111
1212use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
1313use rustc_span:: Span ;
14- use rustc_target:: abi:: { Align , HasDataLayout , Size } ;
14+ use rustc_target:: abi:: { Align , Size } ;
1515
1616use crate :: { concurrency:: VClock , * } ;
1717
@@ -307,15 +307,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
307307
308308 let ( prov, offset) = ptr. into_parts ( ) ; // offset is relative (AllocId provenance)
309309 let alloc_id = prov. alloc_id ( ) ;
310- let base_addr = ecx. addr_from_alloc_id ( alloc_id, kind) ?;
311310
312- // Add offset with the right kind of pointer-overflowing arithmetic.
313- let dl = ecx. data_layout ( ) ;
314- let absolute_addr = dl. overflowing_offset ( base_addr, offset. bytes ( ) ) . 0 ;
315- Ok ( interpret:: Pointer :: new (
311+ // Get a pointer to the beginning of this allocation.
312+ let base_addr = ecx. addr_from_alloc_id ( alloc_id, kind) ?;
313+ let base_ptr = interpret:: Pointer :: new (
316314 Provenance :: Concrete { alloc_id, tag } ,
317- Size :: from_bytes ( absolute_addr) ,
318- ) )
315+ Size :: from_bytes ( base_addr) ,
316+ ) ;
317+ // Add offset with the right kind of pointer-overflowing arithmetic.
318+ Ok ( base_ptr. wrapping_offset ( offset, ecx) )
319319 }
320320
321321 /// When a pointer is used for a memory access, this computes where in which allocation the
@@ -341,12 +341,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
341341 let base_addr = * ecx. machine . alloc_addresses . borrow ( ) . base_addr . get ( & alloc_id) . unwrap ( ) ;
342342
343343 // Wrapping "addr - base_addr"
344- #[ allow( clippy:: cast_possible_wrap) ] // we want to wrap here
345- let neg_base_addr = ( base_addr as i64 ) . wrapping_neg ( ) ;
346- Some ( (
347- alloc_id,
348- Size :: from_bytes ( ecx. overflowing_signed_offset ( addr. bytes ( ) , neg_base_addr) . 0 ) ,
349- ) )
344+ let rel_offset = ecx. truncate_to_target_usize ( addr. bytes ( ) . wrapping_sub ( base_addr) ) ;
345+ Some ( ( alloc_id, Size :: from_bytes ( rel_offset) ) )
350346 }
351347}
352348
0 commit comments