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