Debian Codegraph @

gcc/testsuite/rust/execute/torture/atomic_store.rs

raw
1 #![feature(intrinsics)]
2
3 #[lang = "sized"]
4 pub trait Sized {}
5
6 #[lang = "clone"]
7 pub trait Clone: Sized {
8 fn clone(&self) -> Self;
9
10 fn clone_from(&mut self, source: &Self) {
11 *self = source.clone()
12 }
13 }
14
15 mod impls {
16 use super::Clone;
17
18 macro_rules! impl_clone {
19 ($($t:ty)*) => {
20 $(
21 impl Clone for $t {
22 fn clone(&self) -> Self {
23 *self
24 }
25 }
26 )*
27 }
28 }
29
30 impl_clone! {
31 usize u8 u16 u32 u64 // u128
32 isize i8 i16 i32 i64 // i128
33 f32 f64
34 bool char
35 }
36 }
37
38 #[lang = "copy"]
39 pub trait Copy: Clone {
40 // Empty.
41 }
42
43 mod copy_impls {
44 use super::Copy;
45
46 macro_rules! impl_copy {
47 ($($t:ty)*) => {
48 $(
49 impl Copy for $t {}
50 )*
51 }
52 }
53
54 impl_copy! {
55 usize u8 u16 u32 u64 // u128
56 isize i8 i16 i32 i64 // i128
57 f32 f64
58 bool char
59 }
60 }
61
62 extern "rust-intrinsic" {
63 pub fn atomic_store_seqcst<T: Copy>(dst: *mut T, val: T);
64 pub fn atomic_store_release<T: Copy>(dst: *mut T, val: T);
65 pub fn atomic_store_relaxed<T: Copy>(dst: *mut T, val: T);
66 pub fn atomic_store_unordered<T: Copy>(dst: *mut T, val: T);
67 }
68
69 fn main() -> u32 {
70 let mut dst = 15u32;
71 let one;
72 let two;
73 let three;
74 let four;
75
76 unsafe {
77 atomic_store_seqcst(&mut dst, 1);
78 one = dst;
79
80 atomic_store_release(&mut dst, 2);
81 two = dst;
82
83 atomic_store_relaxed(&mut dst, 3);
84 three = dst;
85
86 atomic_store_unordered(&mut dst, 4);
87 four = dst;
88 }
89
90 (four + three + two + one) - 10
91 }