Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8d1b2ca

Browse files
committed
check that tag_alloc_base_pointer is not called on the wrong things
1 parent cbb649a commit 8d1b2ca

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/machine.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,19 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
662662
ecx: &MiriEvalContext<'mir, 'tcx>,
663663
ptr: Pointer<AllocId>,
664664
) -> Pointer<Tag> {
665+
if cfg!(debug_assertions) {
666+
// The machine promises to never call us on thread-local or extern statics.
667+
let alloc_id = ptr.provenance;
668+
match ecx.tcx.get_global_alloc(alloc_id) {
669+
Some(GlobalAlloc::Static(def_id)) if ecx.tcx.is_thread_local_static(def_id) => {
670+
panic!("tag_alloc_base_pointer called on thread-local static")
671+
}
672+
Some(GlobalAlloc::Static(def_id)) if ecx.tcx.is_foreign_item(def_id) => {
673+
panic!("tag_alloc_base_pointer called on extern static")
674+
}
675+
_ => {}
676+
}
677+
}
665678
let absolute_addr = intptrcast::GlobalStateInner::rel_ptr_to_addr(ecx, ptr);
666679
let sb_tag = if let Some(stacked_borrows) = &ecx.machine.stacked_borrows {
667680
stacked_borrows.borrow_mut().base_tag(ptr.provenance)

0 commit comments

Comments
 (0)