]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/leak-in-static.rs
Merge commit '598f0909568a51de8a2d1148f55a644fd8dffad0' into sync_cg_clif-2023-01-24
[rust.git] / src / tools / miri / tests / pass / leak-in-static.rs
1 use std::{
2     ptr,
3     sync::atomic::{AtomicPtr, Ordering},
4 };
5
6 static mut LEAKER: Option<Box<Vec<i32>>> = None;
7
8 fn main() {
9     // Having memory "leaked" in globals is allowed.
10     unsafe {
11         LEAKER = Some(Box::new(vec![0; 42]));
12     }
13
14     // Make sure this is allowed even when `AtomicPtr` is used.
15     {
16         static LEAK: AtomicPtr<usize> = AtomicPtr::new(ptr::null_mut());
17         LEAK.store(Box::into_raw(Box::new(0usize)), Ordering::SeqCst);
18
19         static LEAK2: AtomicPtr<usize> = AtomicPtr::new(ptr::null_mut());
20         // Make sure this also works when using 'swap'.
21         LEAK2.swap(Box::into_raw(Box::new(0usize)), Ordering::SeqCst);
22     }
23 }