43 lines · cpp
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-exception6//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 is12// order, and the value of failure is order except that a value of13// memory_order_acq_rel shall be replaced by the value memory_order_acquire14// and a value of memory_order_release shall be replaced by the value15// memory_order_relaxed.16//17// Clang's atomic intrinsics do this for us, but GCC's do not. We don't actually18// have visibility to see what these memory orders are lowered to, but we can at19// least check that they are lowered at all (otherwise there is a compile20// failure with GCC).21 22#include <atomic>23 24#include "test_macros.h"25 26int 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(exp, 0, std::memory_order_acq_rel);32 (void) i.compare_exchange_weak(exp, 0, std::memory_order_release);33 i.compare_exchange_strong(exp, 0, std::memory_order_acq_rel);34 i.compare_exchange_strong(exp, 0, std::memory_order_release);35 36 (void) v.compare_exchange_weak(exp, 0, std::memory_order_acq_rel);37 (void) v.compare_exchange_weak(exp, 0, std::memory_order_release);38 v.compare_exchange_strong(exp, 0, std::memory_order_acq_rel);39 v.compare_exchange_strong(exp, 0, std::memory_order_release);40 41 return 0;42}43