diff options
| author | bors <bors@rust-lang.org> | 2020-07-18 13:00:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-07-18 13:00:50 +0000 |
| commit | 7d31ffc1ac9e9ea356e896e63307168a64501b9d (patch) | |
| tree | aa1118412d2690e0e595788144b14970826c3d1f /src/test/codegen | |
| parent | d3df8512d2c2afc6d2e7d8b5b951dd7f2ad77b02 (diff) | |
| parent | cae9c503b0d6de9702ca99bda95c081b1eb530f5 (diff) | |
| download | rust-7d31ffc1ac9e9ea356e896e63307168a64501b9d.tar.gz rust-7d31ffc1ac9e9ea356e896e63307168a64501b9d.zip | |
Auto merge of #74468 - Manishearth:rollup-5nhvz80, r=Manishearth
Rollup of 11 pull requests Successful merges: - #72414 ( Add lazy initialization primitives to std) - #74069 (Compare tagged/niche-filling layout and pick the best one) - #74418 (ci: Set `shell: bash` as a default, remove duplicates) - #74441 (bootstrap.py: patch RPATH on NixOS to handle the new zlib dependency.) - #74444 (Add regression test for #69414) - #74448 (improper_ctypes_definitions: allow `Box`) - #74449 (Test codegen of compare_exchange operations) - #74450 (Fix `Safety` docs for `from_raw_parts_mut`) - #74453 (Use intra-doc links in `str` and `BTreeSet`) - #74457 (rustbuild: drop tool::should_install) - #74464 (Use pathdiff crate) Failed merges: r? @ghost
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/atomic-operations.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/codegen/atomic-operations.rs b/src/test/codegen/atomic-operations.rs new file mode 100644 index 00000000000..ff94ac8543f --- /dev/null +++ b/src/test/codegen/atomic-operations.rs @@ -0,0 +1,60 @@ +// Code generation of atomic operations. +// +// compile-flags: -O +#![crate_type = "lib"] + +use std::sync::atomic::{AtomicI32, Ordering::*}; + +// CHECK-LABEL: @compare_exchange +#[no_mangle] +pub fn compare_exchange(a: &AtomicI32) { + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 10 monotonic monotonic + let _ = a.compare_exchange(0, 10, Relaxed, Relaxed); + + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 20 release monotonic + let _ = a.compare_exchange(0, 20, Release, Relaxed); + + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 30 acquire monotonic + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 31 acquire acquire + let _ = a.compare_exchange(0, 30, Acquire, Relaxed); + let _ = a.compare_exchange(0, 31, Acquire, Acquire); + + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 40 acq_rel monotonic + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 41 acq_rel acquire + let _ = a.compare_exchange(0, 40, AcqRel, Relaxed); + let _ = a.compare_exchange(0, 41, AcqRel, Acquire); + + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 50 seq_cst monotonic + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 51 seq_cst acquire + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 52 seq_cst seq_cst + let _ = a.compare_exchange(0, 50, SeqCst, Relaxed); + let _ = a.compare_exchange(0, 51, SeqCst, Acquire); + let _ = a.compare_exchange(0, 52, SeqCst, SeqCst); +} + +// CHECK-LABEL: @compare_exchange_weak +#[no_mangle] +pub fn compare_exchange_weak(w: &AtomicI32) { + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 10 monotonic monotonic + let _ = w.compare_exchange_weak(1, 10, Relaxed, Relaxed); + + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 20 release monotonic + let _ = w.compare_exchange_weak(1, 20, Release, Relaxed); + + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 30 acquire monotonic + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 31 acquire acquire + let _ = w.compare_exchange_weak(1, 30, Acquire, Relaxed); + let _ = w.compare_exchange_weak(1, 31, Acquire, Acquire); + + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 40 acq_rel monotonic + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 41 acq_rel acquire + let _ = w.compare_exchange_weak(1, 40, AcqRel, Relaxed); + let _ = w.compare_exchange_weak(1, 41, AcqRel, Acquire); + + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 50 seq_cst monotonic + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 51 seq_cst acquire + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 52 seq_cst seq_cst + let _ = w.compare_exchange_weak(1, 50, SeqCst, Relaxed); + let _ = w.compare_exchange_weak(1, 51, SeqCst, Acquire); + let _ = w.compare_exchange_weak(1, 52, SeqCst, SeqCst); +} |
