@@ -4,7 +4,8 @@ use std::cmp::max;
44
55use rand:: Rng ;
66
7- use rustc_mir:: interpret:: { AllocId , Pointer , InterpResult , Memory , AllocCheck } ;
7+ use rustc:: ty:: layout:: HasDataLayout ;
8+ use rustc_mir:: interpret:: { AllocId , Pointer , InterpResult , Memory , AllocCheck , PointerArithmetic } ;
89use rustc_target:: abi:: Size ;
910
1011use crate :: { Evaluator , Tag , STACK_ADDR } ;
@@ -75,7 +76,9 @@ impl<'mir, 'tcx> GlobalState {
7576 let mut global_state = memory. extra . intptrcast . borrow_mut ( ) ;
7677 let global_state = & mut * global_state;
7778
78- let ( size, align) = memory. get_size_and_align ( ptr. alloc_id , AllocCheck :: Live ) ?;
79+ // There is nothing wrong with a raw pointer being cast to an integer only after
80+ // it became dangling. Hence `MaybeDead`.
81+ let ( size, align) = memory. get_size_and_align ( ptr. alloc_id , AllocCheck :: MaybeDead ) ?;
7982
8083 let base_addr = match global_state. base_addr . entry ( ptr. alloc_id ) {
8184 Entry :: Occupied ( entry) => * entry. get ( ) ,
@@ -107,7 +110,9 @@ impl<'mir, 'tcx> GlobalState {
107110 } ;
108111
109112 debug_assert_eq ! ( base_addr % align. bytes( ) , 0 ) ; // sanity check
110- Ok ( base_addr + ptr. offset . bytes ( ) )
113+ // Add offset with the right kind of pointer-overflowing arithmetic.
114+ let dl = memory. data_layout ( ) ;
115+ Ok ( dl. overflowing_offset ( base_addr, ptr. offset . bytes ( ) ) . 0 )
111116 }
112117
113118 /// Shifts `addr` to make it aligned with `align` by rounding `addr` to the smallest multiple
0 commit comments