]> git.lizzy.rs Git - rust.git/blob - tests/ui/intrinsics/intrinsic-volatile.rs
Auto merge of #106975 - tmiasko:basic-blocks-cache, r=cjgillot
[rust.git] / tests / ui / intrinsics / intrinsic-volatile.rs
1 // run-pass
2
3 #![feature(core_intrinsics)]
4
5 use std::intrinsics::*;
6
7 pub fn main() {
8     unsafe {
9         let mut x: Box<u8> = Box::new(0);
10         let mut y: Box<u8> = Box::new(0);
11
12         // test volatile load
13         assert_eq!(volatile_load(&*x), 0);
14         *x = 1;
15         assert_eq!(volatile_load(&*x), 1);
16
17         // test volatile store
18         volatile_store(&mut *x, 2);
19         assert_eq!(*x, 2);
20
21         // test volatile copy memory
22         volatile_copy_memory(&mut *y, &*x, 1);
23         assert_eq!(*y, 2);
24
25         // test volatile copy non-overlapping memory
26         *x = 3;
27         volatile_copy_nonoverlapping_memory(&mut *y, &*x, 1);
28         assert_eq!(*y, 3);
29
30         // test volatile set memory
31         volatile_set_memory(&mut *x, 4, 1);
32         assert_eq!(*x, 4);
33
34         // test unaligned volatile load
35         let arr: [u8; 3] = [1, 2, 3];
36         let ptr = arr[1..].as_ptr() as *const u16;
37         assert_eq!(unaligned_volatile_load(ptr), u16::from_ne_bytes([arr[1], arr[2]]));
38
39         // test unaligned volatile store
40         let ptr = arr[1..].as_ptr() as *mut u16;
41         unaligned_volatile_store(ptr, 0);
42         assert_eq!(arr, [1, 0, 0]);
43     }
44 }