@@ -11,7 +11,7 @@ use rand::Rng;
11
11
12
12
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
13
13
use rustc_span:: Span ;
14
- use rustc_target:: abi:: { Align , HasDataLayout , Size } ;
14
+ use rustc_target:: abi:: { Align , Size } ;
15
15
16
16
use crate :: { concurrency:: VClock , * } ;
17
17
@@ -307,15 +307,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
307
307
308
308
let ( prov, offset) = ptr. into_parts ( ) ; // offset is relative (AllocId provenance)
309
309
let alloc_id = prov. alloc_id ( ) ;
310
- let base_addr = ecx. addr_from_alloc_id ( alloc_id, kind) ?;
311
310
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 (
316
314
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) )
319
319
}
320
320
321
321
/// 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> {
341
341
let base_addr = * ecx. machine . alloc_addresses . borrow ( ) . base_addr . get ( & alloc_id) . unwrap ( ) ;
342
342
343
343
// 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) ) )
350
346
}
351
347
}
352
348
0 commit comments