]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/stacked-borrows/stack-printing.rs
Auto merge of #103158 - Bryanskiy:resolve_perf, r=petrochenkov
[rust.git] / src / tools / miri / tests / pass / stacked-borrows / stack-printing.rs
1 use std::{
2     alloc::{self, Layout},
3     mem::ManuallyDrop,
4 };
5
6 extern "Rust" {
7     fn miri_get_alloc_id(ptr: *const u8) -> u64;
8     fn miri_print_stacks(alloc_id: u64);
9 }
10
11 fn main() {
12     let ptr = unsafe { alloc::alloc(Layout::new::<u8>()) };
13     let alloc_id = unsafe { miri_get_alloc_id(ptr) };
14     unsafe { miri_print_stacks(alloc_id) };
15
16     assert!(!ptr.is_null());
17     unsafe { miri_print_stacks(alloc_id) };
18
19     unsafe { *ptr = 42 };
20     unsafe { miri_print_stacks(alloc_id) };
21
22     let _b = unsafe { ManuallyDrop::new(Box::from_raw(ptr)) };
23     unsafe { miri_print_stacks(alloc_id) };
24
25     let _ptr = unsafe { &*ptr };
26     unsafe { miri_print_stacks(alloc_id) };
27
28     unsafe { alloc::dealloc(ptr, Layout::new::<u8>()) };
29 }