1 //
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 // XFAIL: !has-64-bit-atomics
10 // XFAIL: !has-1024-bit-atomics
11
12 // T load(memory_order = memory_order::seq_cst) const noexcept;
13
14 #include <atomic>
15 #include <concepts>
16 #include <cassert>
17 #include <type_traits>
18
19 #include "atomic_helpers.h"
20 #include "test_helper.h"
21 #include "test_macros.h"
22
23 template <typename T>
24 struct TestLoad {
operator ()TestLoad25 void operator()() const {
26 T x(T(1));
27 std::atomic_ref<T> const a(x);
28
29 {
30 std::same_as<T> decltype(auto) y = a.load();
31 assert(y == T(1));
32 ASSERT_NOEXCEPT(a.load());
33 }
34
35 {
36 std::same_as<T> decltype(auto) y = a.load(std::memory_order_seq_cst);
37 assert(y == T(1));
38 ASSERT_NOEXCEPT(a.load(std::memory_order_seq_cst));
39 }
40
41 // memory_order::seq_cst
42 {
43 auto store = [](std::atomic_ref<T> const& y, T, T new_val) { y.store(new_val); };
44 auto load_no_arg = [](std::atomic_ref<T> const& y) { return y.load(); };
45 auto load_with_order = [](std::atomic_ref<T> const& y) { return y.load(std::memory_order::seq_cst); };
46 test_seq_cst<T>(store, load_no_arg);
47 test_seq_cst<T>(store, load_with_order);
48 }
49
50 // memory_order::release
51 {
52 auto store = [](std::atomic_ref<T> const& y, T, T new_val) { y.store(new_val, std::memory_order::release); };
53 auto load = [](std::atomic_ref<T> const& y) { return y.load(std::memory_order::acquire); };
54 test_acquire_release<T>(store, load);
55 }
56 }
57 };
58
main(int,char **)59 int main(int, char**) {
60 TestEachAtomicType<TestLoad>()();
61 return 0;
62 }
63