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 // UNSUPPORTED: libcpp-has-no-threads 10 11 // This test verifies behavior specified by [atomics.types.operations.req]/21: 12 // 13 // When only one memory_order argument is supplied, the value of success is 14 // order, and the value of failure is order except that a value of 15 // memory_order_acq_rel shall be replaced by the value memory_order_acquire 16 // and a value of memory_order_release shall be replaced by the value 17 // memory_order_relaxed. 18 // 19 // Clang's atomic intrinsics do this for us, but GCC's do not. We don't actually 20 // have visibility to see what these memory orders are lowered to, but we can at 21 // least check that they are lowered at all (otherwise there is a compile 22 // failure with GCC). 23 24 #include <atomic> 25 26 #include "test_macros.h" 27 28 int main(int, char**) { 29 std::atomic<int> i; 30 volatile std::atomic<int> v; 31 int exp = 0; 32 33 (void) i.compare_exchange_weak(exp, 0, std::memory_order_acq_rel); 34 (void) i.compare_exchange_weak(exp, 0, std::memory_order_release); 35 i.compare_exchange_strong(exp, 0, std::memory_order_acq_rel); 36 i.compare_exchange_strong(exp, 0, std::memory_order_release); 37 38 (void) v.compare_exchange_weak(exp, 0, std::memory_order_acq_rel); 39 (void) v.compare_exchange_weak(exp, 0, std::memory_order_release); 40 v.compare_exchange_strong(exp, 0, std::memory_order_acq_rel); 41 v.compare_exchange_strong(exp, 0, std::memory_order_release); 42 43 return 0; 44 } 45