@@ -144,9 +144,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
144
144
}
145
145
146
146
/// Call this to turn untagged "global" pointers (obtained via `tcx`) into
147
- /// the *canonical* machine pointer to the allocation. This represents a *direct*
148
- /// access to that memory, as opposed to access through a pointer that was created
149
- /// by the program. Must never be used for derived (program-created) pointers!
147
+ /// the *canonical* machine pointer to the allocation. Must never be used
148
+ /// for any other pointers!
149
+ ///
150
+ /// This represents a *direct* access to that memory, as opposed to access
151
+ /// through a pointer that was created by the program.
150
152
#[ inline]
151
153
pub fn tag_static_base_pointer ( & self , ptr : Pointer ) -> Pointer < M :: PointerTag > {
152
154
ptr. with_tag ( M :: tag_static_base_pointer ( & self . extra , ptr. alloc_id ) )
@@ -195,9 +197,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
195
197
kind : MemoryKind < M :: MemoryKinds > ,
196
198
) -> Pointer < M :: PointerTag > {
197
199
let id = self . tcx . alloc_map . lock ( ) . reserve ( ) ;
198
- let alloc = M :: init_allocation_extra ( & self . extra , id, Cow :: Owned ( alloc) , Some ( kind) ) ;
200
+ debug_assert_ne ! ( Some ( kind) , M :: STATIC_KIND . map( MemoryKind :: Machine ) ,
201
+ "dynamically allocating static memory" ) ;
202
+ let ( alloc, tag) = M :: init_allocation_extra ( & self . extra , id, Cow :: Owned ( alloc) , Some ( kind) ) ;
199
203
self . alloc_map . insert ( id, ( kind, alloc. into_owned ( ) ) ) ;
200
- self . tag_static_base_pointer ( Pointer :: from ( id) )
204
+ Pointer :: from ( id) . with_tag ( tag )
201
205
}
202
206
203
207
pub fn reallocate (
@@ -478,12 +482,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
478
482
}
479
483
} ;
480
484
// We got tcx memory. Let the machine initialize its "extra" stuff.
481
- Ok ( M :: init_allocation_extra (
485
+ let ( alloc , tag ) = M :: init_allocation_extra (
482
486
memory_extra,
483
487
id, // always use the ID we got as input, not the "hidden" one.
484
488
alloc,
485
489
M :: STATIC_KIND . map ( MemoryKind :: Machine ) ,
486
- ) )
490
+ ) ;
491
+ debug_assert_eq ! ( tag, M :: tag_static_base_pointer( memory_extra, id) ) ;
492
+ Ok ( alloc)
487
493
}
488
494
489
495
/// Gives raw access to the `Allocation`, without bounds or alignment checks.
0 commit comments