Debian Codegraph @

gcc/testsuite/rust/execute/torture/atomic_load.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_load_seqcst<T: Copy>(src: *const T) -> T;
64 pub fn atomic_load_acquire<T: Copy>(src: *const T) -> T;
65 pub fn atomic_load_relaxed<T: Copy>(src: *const T) -> T;
66 pub fn atomic_load_unordered<T: Copy>(src: *const T) -> T;
67 }
68
69 fn main() -> u32 {
70 let one;
71 let two;
72 let three;
73 let four;
74
75 unsafe {
76 let mut src = 1u32;
77 one = atomic_load_seqcst(&src);
78
79 src = 2;
80 two = atomic_load_acquire(&src);
81
82 src = 3;
83 three = atomic_load_relaxed(&src);
84
85 src = 4;
86 four = atomic_load_unordered(&src);
87 }
88
89 (four + three + two + one) - 10
90 }