From 8d1b2ca3ec998fc8bdbfe03f5c8faf7cc138a9ed Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 14 Jun 2022 09:45:02 -0700 Subject: [PATCH] check that tag_alloc_base_pointer is not called on the wrong things --- src/machine.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index 824f0e3fc87..955677df6f0 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -662,6 +662,19 @@ fn tag_alloc_base_pointer( ecx: &MiriEvalContext<'mir, 'tcx>, ptr: Pointer, ) -> Pointer { + if cfg!(debug_assertions) { + // The machine promises to never call us on thread-local or extern statics. + let alloc_id = ptr.provenance; + match ecx.tcx.get_global_alloc(alloc_id) { + Some(GlobalAlloc::Static(def_id)) if ecx.tcx.is_thread_local_static(def_id) => { + panic!("tag_alloc_base_pointer called on thread-local static") + } + Some(GlobalAlloc::Static(def_id)) if ecx.tcx.is_foreign_item(def_id) => { + panic!("tag_alloc_base_pointer called on extern static") + } + _ => {} + } + } let absolute_addr = intptrcast::GlobalStateInner::rel_ptr_to_addr(ecx, ptr); let sb_tag = if let Some(stacked_borrows) = &ecx.machine.stacked_borrows { stacked_borrows.borrow_mut().base_tag(ptr.provenance) -- 2.44.0