Skip to content

Commit 18e8089

Browse files
authoredJul 18, 2020
Rollup merge of #74449 - tmiasko:cmpxchg-test, r=nikomatsakis
Test codegen of compare_exchange operations Add a codegen test for compare_exchange to verify that rustc emits expected LLVM IR.
2 parents f276dd4 + b26ecd2 commit 18e8089

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
 

‎src/test/codegen/atomic-operations.rs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Code generation of atomic operations.
2+
//
3+
// compile-flags: -O
4+
#![crate_type = "lib"]
5+
6+
use std::sync::atomic::{AtomicI32, Ordering::*};
7+
8+
// CHECK-LABEL: @compare_exchange
9+
#[no_mangle]
10+
pub fn compare_exchange(a: &AtomicI32) {
11+
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 10 monotonic monotonic
12+
let _ = a.compare_exchange(0, 10, Relaxed, Relaxed);
13+
14+
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 20 release monotonic
15+
let _ = a.compare_exchange(0, 20, Release, Relaxed);
16+
17+
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 30 acquire monotonic
18+
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 31 acquire acquire
19+
let _ = a.compare_exchange(0, 30, Acquire, Relaxed);
20+
let _ = a.compare_exchange(0, 31, Acquire, Acquire);
21+
22+
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 40 acq_rel monotonic
23+
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 41 acq_rel acquire
24+
let _ = a.compare_exchange(0, 40, AcqRel, Relaxed);
25+
let _ = a.compare_exchange(0, 41, AcqRel, Acquire);
26+
27+
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 50 seq_cst monotonic
28+
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 51 seq_cst acquire
29+
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 52 seq_cst seq_cst
30+
let _ = a.compare_exchange(0, 50, SeqCst, Relaxed);
31+
let _ = a.compare_exchange(0, 51, SeqCst, Acquire);
32+
let _ = a.compare_exchange(0, 52, SeqCst, SeqCst);
33+
}
34+
35+
// CHECK-LABEL: @compare_exchange_weak
36+
#[no_mangle]
37+
pub fn compare_exchange_weak(w: &AtomicI32) {
38+
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 10 monotonic monotonic
39+
let _ = w.compare_exchange_weak(1, 10, Relaxed, Relaxed);
40+
41+
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 20 release monotonic
42+
let _ = w.compare_exchange_weak(1, 20, Release, Relaxed);
43+
44+
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 30 acquire monotonic
45+
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 31 acquire acquire
46+
let _ = w.compare_exchange_weak(1, 30, Acquire, Relaxed);
47+
let _ = w.compare_exchange_weak(1, 31, Acquire, Acquire);
48+
49+
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 40 acq_rel monotonic
50+
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 41 acq_rel acquire
51+
let _ = w.compare_exchange_weak(1, 40, AcqRel, Relaxed);
52+
let _ = w.compare_exchange_weak(1, 41, AcqRel, Acquire);
53+
54+
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 50 seq_cst monotonic
55+
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 51 seq_cst acquire
56+
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 52 seq_cst seq_cst
57+
let _ = w.compare_exchange_weak(1, 50, SeqCst, Relaxed);
58+
let _ = w.compare_exchange_weak(1, 51, SeqCst, Acquire);
59+
let _ = w.compare_exchange_weak(1, 52, SeqCst, SeqCst);
60+
}

0 commit comments

Comments
 (0)
Please sign in to comment.