about summary refs log tree commit diff
path: root/src/tools/miri/tests/genmc/pass/litmus/default.rs
blob: 55fb1ac34acb418724b4e1f541caeaa57853f3ce (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
//@compile-flags: -Zmiri-genmc -Zmiri-disable-stacked-borrows

// Translated from GenMC's "litmus/default" test.

#![no_main]

#[path = "../../../utils/genmc.rs"]
mod genmc;

use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering::*;

use crate::genmc::*;

static X: AtomicU64 = AtomicU64::new(0);

#[unsafe(no_mangle)]
fn miri_start(_argc: isize, _argv: *const *const u8) -> isize {
    // FIXME(genmc,HACK): remove this initializing write once Miri-GenMC supports mixed atomic-non-atomic accesses.
    X.store(0, Relaxed);

    unsafe {
        let mut a = 1234;
        let mut b = 1234;
        let ids = [
            spawn_pthread_closure(|| {
                a = X.load(Acquire);
                b = X.load(Acquire);
            }),
            spawn_pthread_closure(|| {
                X.store(1, Release);
            }),
            spawn_pthread_closure(|| {
                X.store(2, Release);
            }),
        ];
        // Join so we can read the final values.
        join_pthreads(ids);

        // Check that we don't get any unexpected values:
        if !matches!((a, b), (0, 0) | (0, 1) | (0, 2) | (1, 1) | (1, 2) | (2, 1) | (2, 2)) {
            std::process::abort();
        }

        0
    }
}