@@ -238,7 +238,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
238
238
new_align : Align ,
239
239
kind : MemoryKind < M :: MemoryKind > ,
240
240
) -> InterpResult < ' tcx , Pointer < M :: PointerTag > > {
241
- let ( alloc_id, offset, ptr ) = self . ptr_get_alloc_id ( ptr) ?;
241
+ let ( alloc_id, offset, _tag ) = self . ptr_get_alloc_id ( ptr) ?;
242
242
if offset. bytes ( ) != 0 {
243
243
throw_ub_format ! (
244
244
"reallocating {:?} which does not point to the beginning of an object" ,
@@ -255,14 +255,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
255
255
} ;
256
256
// This will also call the access hooks.
257
257
self . mem_copy (
258
- ptr. into ( ) ,
258
+ ptr,
259
259
Align :: ONE ,
260
260
new_ptr. into ( ) ,
261
261
Align :: ONE ,
262
262
old_size. min ( new_size) ,
263
263
/*nonoverlapping*/ true ,
264
264
) ?;
265
- self . deallocate_ptr ( ptr. into ( ) , old_size_and_align, kind) ?;
265
+ self . deallocate_ptr ( ptr, old_size_and_align, kind) ?;
266
266
267
267
Ok ( new_ptr)
268
268
}
@@ -274,7 +274,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
274
274
old_size_and_align : Option < ( Size , Align ) > ,
275
275
kind : MemoryKind < M :: MemoryKind > ,
276
276
) -> InterpResult < ' tcx > {
277
- let ( alloc_id, offset, ptr ) = self . ptr_get_alloc_id ( ptr) ?;
277
+ let ( alloc_id, offset, tag ) = self . ptr_get_alloc_id ( ptr) ?;
278
278
trace ! ( "deallocating: {}" , alloc_id) ;
279
279
280
280
if offset. bytes ( ) != 0 {
@@ -330,7 +330,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
330
330
* self . tcx ,
331
331
& mut self . machine ,
332
332
& mut alloc. extra ,
333
- ptr . provenance ,
333
+ tag ,
334
334
alloc_range ( Size :: ZERO , size) ,
335
335
) ?;
336
336
@@ -350,17 +350,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
350
350
ptr : Pointer < Option < M :: PointerTag > > ,
351
351
size : Size ,
352
352
align : Align ,
353
- ) -> InterpResult < ' tcx , Option < ( AllocId , Size , Pointer < M :: PointerTag > ) > > {
353
+ ) -> InterpResult < ' tcx , Option < ( AllocId , Size , M :: PointerTag ) > > {
354
354
let align = M :: enforce_alignment ( & self ) . then_some ( align) ;
355
355
self . check_and_deref_ptr (
356
356
ptr,
357
357
size,
358
358
align,
359
359
CheckInAllocMsg :: MemoryAccessTest ,
360
- |alloc_id, offset, ptr | {
360
+ |alloc_id, offset, tag | {
361
361
let ( size, align) =
362
362
self . get_alloc_size_and_align ( alloc_id, AllocCheck :: Dereferenceable ) ?;
363
- Ok ( ( size, align, ( alloc_id, offset, ptr ) ) )
363
+ Ok ( ( size, align, ( alloc_id, offset, tag ) ) )
364
364
} ,
365
365
)
366
366
}
@@ -404,7 +404,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
404
404
alloc_size : impl FnOnce (
405
405
AllocId ,
406
406
Size ,
407
- Pointer < M :: PointerTag > ,
407
+ M :: PointerTag ,
408
408
) -> InterpResult < ' tcx , ( Size , Align , T ) > ,
409
409
) -> InterpResult < ' tcx , Option < T > > {
410
410
fn check_offset_align ( offset : u64 , align : Align ) -> InterpResult < ' static > {
@@ -433,8 +433,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
433
433
}
434
434
None
435
435
}
436
- Ok ( ( alloc_id, offset, ptr ) ) => {
437
- let ( alloc_size, alloc_align, ret_val) = alloc_size ( alloc_id, offset, ptr ) ?;
436
+ Ok ( ( alloc_id, offset, tag ) ) => {
437
+ let ( alloc_size, alloc_align, ret_val) = alloc_size ( alloc_id, offset, tag ) ?;
438
438
// Test bounds. This also ensures non-null.
439
439
// It is sufficient to check this for the end pointer. Also check for overflow!
440
440
if offset. checked_add ( size, & self . tcx ) . map_or ( true , |end| end > alloc_size) {
@@ -450,10 +450,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
450
450
// we want the error to be about the bounds.
451
451
if let Some ( align) = align {
452
452
if M :: force_int_for_alignment_check ( self ) {
453
- let addr = Scalar :: from_pointer ( ptr, & self . tcx )
454
- . to_machine_usize ( & self . tcx )
455
- . expect ( "ptr-to-int cast for align check should never fail" ) ;
456
- check_offset_align ( addr, align) ?;
453
+ assert ! ( M :: PointerTag :: OFFSET_IS_ADDR , "ptr-to-int cast for align check should never fail" ) ;
454
+ let ( _, addr) = ptr. into_parts ( ) ; // we checked that offset is absolute
455
+ check_offset_align ( addr. bytes ( ) , align) ?;
457
456
} else {
458
457
// Check allocation alignment and offset alignment.
459
458
if alloc_align. bytes ( ) < align. bytes ( ) {
@@ -569,14 +568,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
569
568
size,
570
569
align,
571
570
CheckInAllocMsg :: MemoryAccessTest ,
572
- |alloc_id, offset, ptr | {
571
+ |alloc_id, offset, tag | {
573
572
let alloc = self . get_alloc_raw ( alloc_id) ?;
574
- Ok ( ( alloc. size ( ) , alloc. align , ( alloc_id, offset, ptr , alloc) ) )
573
+ Ok ( ( alloc. size ( ) , alloc. align , ( alloc_id, offset, tag , alloc) ) )
575
574
} ,
576
575
) ?;
577
- if let Some ( ( alloc_id, offset, ptr , alloc) ) = ptr_and_alloc {
576
+ if let Some ( ( alloc_id, offset, tag , alloc) ) = ptr_and_alloc {
578
577
let range = alloc_range ( offset, size) ;
579
- M :: memory_read ( * self . tcx , & self . machine , & alloc. extra , ptr . provenance , range) ?;
578
+ M :: memory_read ( * self . tcx , & self . machine , & alloc. extra , tag , range) ?;
580
579
Ok ( Some ( AllocRef { alloc, range, tcx : * self . tcx , alloc_id } ) )
581
580
} else {
582
581
// Even in this branch we have to be sure that we actually access the allocation, in
@@ -631,13 +630,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
631
630
align : Align ,
632
631
) -> InterpResult < ' tcx , Option < AllocRefMut < ' a , ' tcx , M :: PointerTag , M :: AllocExtra > > > {
633
632
let parts = self . get_ptr_access ( ptr, size, align) ?;
634
- if let Some ( ( alloc_id, offset, ptr ) ) = parts {
633
+ if let Some ( ( alloc_id, offset, tag ) ) = parts {
635
634
let tcx = * self . tcx ;
636
635
// FIXME: can we somehow avoid looking up the allocation twice here?
637
636
// We cannot call `get_raw_mut` inside `check_and_deref_ptr` as that would duplicate `&mut self`.
638
637
let ( alloc, machine) = self . get_alloc_raw_mut ( alloc_id) ?;
639
638
let range = alloc_range ( offset, size) ;
640
- M :: memory_written ( tcx, machine, & mut alloc. extra , ptr . provenance , range) ?;
639
+ M :: memory_written ( tcx, machine, & mut alloc. extra , tag , range) ?;
641
640
Ok ( Some ( AllocRefMut { alloc, range, tcx, alloc_id } ) )
642
641
} else {
643
642
Ok ( None )
@@ -732,7 +731,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
732
731
ptr : Pointer < Option < M :: PointerTag > > ,
733
732
) -> InterpResult < ' tcx , FnVal < ' tcx , M :: ExtraFnVal > > {
734
733
trace ! ( "get_fn({:?})" , ptr) ;
735
- let ( alloc_id, offset, _ptr ) = self . ptr_get_alloc_id ( ptr) ?;
734
+ let ( alloc_id, offset, _tag ) = self . ptr_get_alloc_id ( ptr) ?;
736
735
if offset. bytes ( ) != 0 {
737
736
throw_ub ! ( InvalidFunctionPointer ( Pointer :: new( alloc_id, offset) ) )
738
737
}
@@ -1009,16 +1008,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1009
1008
// and once below to get the underlying `&[mut] Allocation`.
1010
1009
1011
1010
// Source alloc preparations and access hooks.
1012
- let Some ( ( src_alloc_id, src_offset, src ) ) = src_parts else {
1011
+ let Some ( ( src_alloc_id, src_offset, src_tag ) ) = src_parts else {
1013
1012
// Zero-sized *source*, that means dst is also zero-sized and we have nothing to do.
1014
1013
return Ok ( ( ) ) ;
1015
1014
} ;
1016
1015
let src_alloc = self . get_alloc_raw ( src_alloc_id) ?;
1017
1016
let src_range = alloc_range ( src_offset, size) ;
1018
- M :: memory_read ( * tcx, & self . machine , & src_alloc. extra , src . provenance , src_range) ?;
1017
+ M :: memory_read ( * tcx, & self . machine , & src_alloc. extra , src_tag , src_range) ?;
1019
1018
// We need the `dest` ptr for the next operation, so we get it now.
1020
1019
// We already did the source checks and called the hooks so we are good to return early.
1021
- let Some ( ( dest_alloc_id, dest_offset, dest ) ) = dest_parts else {
1020
+ let Some ( ( dest_alloc_id, dest_offset, dest_tag ) ) = dest_parts else {
1022
1021
// Zero-sized *destination*.
1023
1022
return Ok ( ( ) ) ;
1024
1023
} ;
@@ -1040,7 +1039,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1040
1039
// Destination alloc preparations and access hooks.
1041
1040
let ( dest_alloc, extra) = self . get_alloc_raw_mut ( dest_alloc_id) ?;
1042
1041
let dest_range = alloc_range ( dest_offset, size * num_copies) ;
1043
- M :: memory_written ( * tcx, extra, & mut dest_alloc. extra , dest . provenance , dest_range) ?;
1042
+ M :: memory_written ( * tcx, extra, & mut dest_alloc. extra , dest_tag , dest_range) ?;
1044
1043
let dest_bytes = dest_alloc
1045
1044
. get_bytes_mut_ptr ( & tcx, dest_range)
1046
1045
. map_err ( |e| e. to_interp_error ( dest_alloc_id) ) ?
@@ -1159,11 +1158,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1159
1158
pub fn ptr_try_get_alloc_id (
1160
1159
& self ,
1161
1160
ptr : Pointer < Option < M :: PointerTag > > ,
1162
- ) -> Result < ( AllocId , Size , Pointer < M :: PointerTag > ) , u64 > {
1161
+ ) -> Result < ( AllocId , Size , M :: PointerTag ) , u64 > {
1163
1162
match ptr. into_pointer_or_addr ( ) {
1164
1163
Ok ( ptr) => {
1165
1164
let ( alloc_id, offset) = M :: ptr_get_alloc ( self , ptr) ;
1166
- Ok ( ( alloc_id, offset, ptr) )
1165
+ Ok ( ( alloc_id, offset, ptr. provenance ) )
1167
1166
}
1168
1167
Err ( addr) => Err ( addr. bytes ( ) ) ,
1169
1168
}
@@ -1174,7 +1173,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1174
1173
pub fn ptr_get_alloc_id (
1175
1174
& self ,
1176
1175
ptr : Pointer < Option < M :: PointerTag > > ,
1177
- ) -> InterpResult < ' tcx , ( AllocId , Size , Pointer < M :: PointerTag > ) > {
1176
+ ) -> InterpResult < ' tcx , ( AllocId , Size , M :: PointerTag ) > {
1178
1177
self . ptr_try_get_alloc_id ( ptr) . map_err ( |offset| {
1179
1178
err_ub ! ( DanglingIntPointer ( offset, CheckInAllocMsg :: InboundsTest ) ) . into ( )
1180
1179
} )
0 commit comments