]> git.lizzy.rs Git - rust.git/blobdiff - src/machine.rs
check that tag_alloc_base_pointer is not called on the wrong things
[rust.git] / src / machine.rs
index 824f0e3fc874884f9536e1911ccce76b8741e1b7..955677df6f0792a99bddfd5aac6b1ab627c6331e 100644 (file)
@@ -662,6 +662,19 @@ fn tag_alloc_base_pointer(
         ecx: &MiriEvalContext<'mir, 'tcx>,
         ptr: Pointer<AllocId>,
     ) -> Pointer<Tag> {
+        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)