1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // This test verifies behavior specified by [atomics.types.operations.req]/21: |
10 | // |
11 | // When only one memory_order argument is supplied, the value of success is |
12 | // order, and the value of failure is order except that a value of |
13 | // memory_order_acq_rel shall be replaced by the value memory_order_acquire |
14 | // and a value of memory_order_release shall be replaced by the value |
15 | // memory_order_relaxed. |
16 | // |
17 | // Clang's atomic intrinsics do this for us, but GCC's do not. We don't actually |
18 | // have visibility to see what these memory orders are lowered to, but we can at |
19 | // least check that they are lowered at all (otherwise there is a compile |
20 | // failure with GCC). |
21 | |
22 | #include <atomic> |
23 | |
24 | #include "test_macros.h" |
25 | |
26 | int main(int, char**) { |
27 | std::atomic<int> i; |
28 | volatile std::atomic<int> v; |
29 | int exp = 0; |
30 | |
31 | (void) i.compare_exchange_weak(i1&: exp, i2: 0, m: std::memory_order_acq_rel); |
32 | (void) i.compare_exchange_weak(i1&: exp, i2: 0, m: std::memory_order_release); |
33 | i.compare_exchange_strong(i1&: exp, i2: 0, m: std::memory_order_acq_rel); |
34 | i.compare_exchange_strong(i1&: exp, i2: 0, m: std::memory_order_release); |
35 | |
36 | (void) v.compare_exchange_weak(i1&: exp, i2: 0, m: std::memory_order_acq_rel); |
37 | (void) v.compare_exchange_weak(i1&: exp, i2: 0, m: std::memory_order_release); |
38 | v.compare_exchange_strong(i1&: exp, i2: 0, m: std::memory_order_acq_rel); |
39 | v.compare_exchange_strong(i1&: exp, i2: 0, m: std::memory_order_release); |
40 | |
41 | return 0; |
42 | } |
43 | |