@@ -144,9 +144,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
144144 }
145145
146146 /// 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.
150152 #[ inline]
151153 pub fn tag_static_base_pointer ( & self , ptr : Pointer ) -> Pointer < M :: PointerTag > {
152154 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> {
195197 kind : MemoryKind < M :: MemoryKinds > ,
196198 ) -> Pointer < M :: PointerTag > {
197199 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) ) ;
199203 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 )
201205 }
202206
203207 pub fn reallocate (
@@ -478,12 +482,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
478482 }
479483 } ;
480484 // 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 (
482486 memory_extra,
483487 id, // always use the ID we got as input, not the "hidden" one.
484488 alloc,
485489 M :: STATIC_KIND . map ( MemoryKind :: Machine ) ,
486- ) )
490+ ) ;
491+ debug_assert_eq ! ( tag, M :: tag_static_base_pointer( memory_extra, id) ) ;
492+ Ok ( alloc)
487493 }
488494
489495 /// Gives raw access to the `Allocation`, without bounds or alignment checks.
0 commit comments