File: issue-39827.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (34 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//@ run-pass
#![feature(core_intrinsics)]

use std::intrinsics::{ volatile_copy_memory, volatile_store, volatile_load,
                       volatile_copy_nonoverlapping_memory,
                       volatile_set_memory };

//
// This test ensures that volatile intrinsics can be specialised with
// zero-sized types and, in case of copy/set functions, can accept
// number of elements equal to zero.
//
fn main () {
    let mut dst_pair = (1, 2);
    let src_pair = (3, 4);
    let mut dst_empty = ();
    let src_empty = ();

    const COUNT_0: usize = 0;
    const COUNT_100: usize = 100;

    unsafe {
        volatile_copy_memory(&mut dst_pair, &dst_pair, COUNT_0);
        volatile_copy_nonoverlapping_memory(&mut dst_pair, &src_pair, 0);
        volatile_copy_memory(&mut dst_empty, &dst_empty, 100);
        volatile_copy_nonoverlapping_memory(&mut dst_empty, &src_empty,
                                            COUNT_100);
        volatile_set_memory(&mut dst_empty, 0, COUNT_100);
        volatile_set_memory(&mut dst_pair, 0, COUNT_0);
        volatile_store(&mut dst_empty, ());
        volatile_store(&mut dst_empty, src_empty);
        volatile_load(&src_empty);
    }
}