Compare commits

..

14 Commits

Author SHA1 Message Date
Howard Hinnant
613ebe935d Tagging 12
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/tags/libcpp-12@121296 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-08 22:28:16 +00:00
Howard Hinnant
31aaf55f4c N3158 Missing preconditions for default-constructed match_result objects
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121282 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-08 21:07:55 +00:00
Howard Hinnant
1b18a48e28 cleaning up...
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121275 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-08 20:09:09 +00:00
Howard Hinnant
770d1c4ea7 After a long break to wait for the atomic spec to settle, this completes the library part of <atomic>. It currently won't even parse as it depends on the existence of the intrinsics specified at http://libcxx.llvm.org/atomic_design_a.html. Everything has been tested using fake intrinsics which have now been removed. As the intrinsics come online, the ATOMIC_* macros will need to be adjusted to reflect which operations are lock-free. These macros will probably need to be #ifdef'd for each supported platform.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121267 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-08 17:20:28 +00:00
Michael J. Spencer
c9f5d9fca6 test: Rename string_op+= to string_op_plus_equal. Windows git doesn't like it.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121265 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-08 17:06:47 +00:00
Howard Hinnant
d2f6afbfab atomics ...
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121204 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-07 23:24:41 +00:00
Howard Hinnant
57e5e87323 atomics ...
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121203 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-07 23:24:09 +00:00
Howard Hinnant
f02417b600 atomics ...
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121202 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-07 23:20:28 +00:00
Howard Hinnant
91e2f26fec Work on <atomic> continues. The file size is actually sane now...
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121181 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-07 20:46:14 +00:00
Howard Hinnant
4777bf2799 Getting <atomic> warmed back up. We have a hopefully more stable spec now. And I believe the intrinsic spec at http://libcxx.llvm.org/atomic_design_a.html is still good.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121064 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-06 23:10:08 +00:00
Howard Hinnant
7a0248d2d7 Add a couple more std-qualifers.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121002 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-06 15:11:48 +00:00
Howard Hinnant
d42c4beeff oops, forgot std::
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@120915 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-04 19:56:43 +00:00
Howard Hinnant
1f970ad73a Fix up uses of new/terminate/unexpected handlers to use the new getters.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@120914 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-04 19:54:11 +00:00
Howard Hinnant
55ddb21dd4 Add typeinfo for char16_t, char32_t and nullptr.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@120810 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-03 17:25:24 +00:00
74 changed files with 3964 additions and 12405 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -208,6 +208,8 @@ public:
bool matched;
constexpr sub_match();
difference_type length() const;
operator string_type() const;
string_type str() const;
@@ -452,6 +454,8 @@ public:
match_results& operator=(match_results&& m);
~match_results();
bool ready() const;
// size:
size_type size() const;
size_type max_size() const;
@@ -4683,6 +4687,9 @@ public:
bool matched;
_LIBCPP_INLINE_VISIBILITY
/*constexpr*/ sub_match() : matched() {}
_LIBCPP_INLINE_VISIBILITY
difference_type length() const
{return matched ? _STD::distance(this->first, this->second) : 0;}
@@ -5104,6 +5111,7 @@ private:
value_type __unmatched_;
value_type __prefix_;
value_type __suffix_;
bool __ready_;
public:
_BidirectionalIterator __position_start_;
typedef const value_type& const_reference;
@@ -5123,6 +5131,9 @@ public:
// match_results& operator=(match_results&& __m) = default;
// ~match_results() = default;
_LIBCPP_INLINE_VISIBILITY
bool ready() const {return __ready_;}
// size:
_LIBCPP_INLINE_VISIBILITY
size_type size() const {return __matches_.size();}
@@ -5224,6 +5235,7 @@ public:
__suffix_.matched = __m.suffix().matched;
if (!__no_update_pos)
__position_start_ = __prefix_.first;
__ready_ = __m.ready();
}
private:
@@ -5254,7 +5266,8 @@ match_results<_BidirectionalIterator, _Allocator>::match_results(
__unmatched_(),
__prefix_(),
__suffix_(),
__position_start_()
__position_start_(),
__ready_(false)
{
}
@@ -5274,6 +5287,7 @@ match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
__suffix_ = __unmatched_;
if (!__no_update_pos)
__position_start_ = __prefix_.first;
__ready_ = true;
}
template <class _BidirectionalIterator, class _Allocator>
@@ -5379,6 +5393,7 @@ match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
swap(__prefix_, __m.__prefix_);
swap(__suffix_, __m.__suffix_);
swap(__position_start_, __m.__position_start_);
swap(__ready_, __m.__ready_);
}
typedef match_results<const char*> cmatch;
@@ -5391,10 +5406,13 @@ bool
operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
const match_results<_BidirectionalIterator, _Allocator>& __y)
{
if (__x.__ready_ != __y.__ready_)
return false;
if (!__x.__ready_)
return true;
return __x.__matches_ == __y.__matches_ &&
__x.__prefix_ == __y.__prefix_ &&
__x.__suffix_ == __y.__suffix_ &&
__x.__position_start_ == __y.__position_start_;
__x.__suffix_ == __y.__suffix_;
}
template <class _BidirectionalIterator, class _Allocator>

View File

@@ -26,6 +26,15 @@ ___cxa_vec_new2
___cxa_vec_new3
___dynamic_cast
___gxx_personality_v0
__ZTIDi
__ZTIDn
__ZTIDs
__ZTIPDi
__ZTIPDn
__ZTIPDs
__ZTIPKDi
__ZTIPKDn
__ZTIPKDs
__ZTSPm
__ZTSPl
__ZTSPj

View File

@@ -38,7 +38,7 @@ std::get_unexpected() throw()
void
std::unexpected()
{
(*__unexpected_handler)();
(*std::get_unexpected())();
// unexpected handler should not return
std::terminate();
}
@@ -62,7 +62,7 @@ std::terminate()
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
(*__terminate_handler)();
(*std::get_terminate())();
// handler should not return
::abort ();
#ifndef _LIBCPP_NO_EXCEPTIONS

View File

@@ -36,8 +36,9 @@ operator new(std::size_t size) throw (std::bad_alloc)
{
// If malloc fails and there is a new_handler,
// call it to try free up memory.
if (__new_handler)
__new_handler();
std::new_handler nh = std::get_new_handler();
if (nh)
nh();
else
#ifndef _LIBCPP_NO_EXCEPTIONS
throw std::bad_alloc();

View File

@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// void atomic_signal_fence(memory_order m);
#include <atomic>
int main()
{
std::atomic_signal_fence(std::memory_order_seq_cst);
}

View File

@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// void atomic_thread_fence(memory_order m);
#include <atomic>
int main()
{
std::atomic_thread_fence(std::memory_order_seq_cst);
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// #define ATOMIC_CHAR_LOCK_FREE unspecified
// #define ATOMIC_CHAR16_T_LOCK_FREE unspecified
// #define ATOMIC_CHAR32_T_LOCK_FREE unspecified
// #define ATOMIC_WCHAR_T_LOCK_FREE unspecified
// #define ATOMIC_SHORT_LOCK_FREE unspecified
// #define ATOMIC_INT_LOCK_FREE unspecified
// #define ATOMIC_LONG_LOCK_FREE unspecified
// #define ATOMIC_LLONG_LOCK_FREE unspecified
#include <atomic>
#include <cassert>
int main()
{
assert(ATOMIC_CHAR_LOCK_FREE == 0 ||
ATOMIC_CHAR_LOCK_FREE == 1 ||
ATOMIC_CHAR_LOCK_FREE == 2);
assert(ATOMIC_CHAR16_T_LOCK_FREE == 0 ||
ATOMIC_CHAR16_T_LOCK_FREE == 1 ||
ATOMIC_CHAR16_T_LOCK_FREE == 2);
assert(ATOMIC_CHAR32_T_LOCK_FREE == 0 ||
ATOMIC_CHAR32_T_LOCK_FREE == 1 ||
ATOMIC_CHAR32_T_LOCK_FREE == 2);
assert(ATOMIC_WCHAR_T_LOCK_FREE == 0 ||
ATOMIC_WCHAR_T_LOCK_FREE == 1 ||
ATOMIC_WCHAR_T_LOCK_FREE == 2);
assert(ATOMIC_SHORT_LOCK_FREE == 0 ||
ATOMIC_SHORT_LOCK_FREE == 1 ||
ATOMIC_SHORT_LOCK_FREE == 2);
assert(ATOMIC_INT_LOCK_FREE == 0 ||
ATOMIC_INT_LOCK_FREE == 1 ||
ATOMIC_INT_LOCK_FREE == 2);
assert(ATOMIC_LONG_LOCK_FREE == 0 ||
ATOMIC_LONG_LOCK_FREE == 1 ||
ATOMIC_LONG_LOCK_FREE == 2);
assert(ATOMIC_LLONG_LOCK_FREE == 0 ||
ATOMIC_LLONG_LOCK_FREE == 1 ||
ATOMIC_LLONG_LOCK_FREE == 2);
}

View File

@@ -0,0 +1,126 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// struct atomic<T*>
// {
// bool is_lock_free() const volatile;
// bool is_lock_free() const;
// void store(T* desr, memory_order m = memory_order_seq_cst) volatile;
// void store(T* desr, memory_order m = memory_order_seq_cst);
// T* load(memory_order m = memory_order_seq_cst) const volatile;
// T* load(memory_order m = memory_order_seq_cst) const;
// operator T*() const volatile;
// operator T*() const;
// T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile;
// T* exchange(T* desr, memory_order m = memory_order_seq_cst);
// bool compare_exchange_weak(T*& expc, T* desr,
// memory_order s, memory_order f) volatile;
// bool compare_exchange_weak(T*& expc, T* desr,
// memory_order s, memory_order f);
// bool compare_exchange_strong(T*& expc, T* desr,
// memory_order s, memory_order f) volatile;
// bool compare_exchange_strong(T*& expc, T* desr,
// memory_order s, memory_order f);
// bool compare_exchange_weak(T*& expc, T* desr,
// memory_order m = memory_order_seq_cst) volatile;
// bool compare_exchange_weak(T*& expc, T* desr,
// memory_order m = memory_order_seq_cst);
// bool compare_exchange_strong(T*& expc, T* desr,
// memory_order m = memory_order_seq_cst) volatile;
// bool compare_exchange_strong(T*& expc, T* desr,
// memory_order m = memory_order_seq_cst);
// T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile;
// T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst);
// T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile;
// T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst);
//
// atomic() = default;
// constexpr atomic(T* desr);
// atomic(const atomic&) = delete;
// atomic& operator=(const atomic&) = delete;
// atomic& operator=(const atomic&) volatile = delete;
//
// T* operator=(T*) volatile;
// T* operator=(T*);
// T* operator++(int) volatile;
// T* operator++(int);
// T* operator--(int) volatile;
// T* operator--(int);
// T* operator++() volatile;
// T* operator++();
// T* operator--() volatile;
// T* operator--();
// T* operator+=(ptrdiff_t op) volatile;
// T* operator+=(ptrdiff_t op);
// T* operator-=(ptrdiff_t op) volatile;
// T* operator-=(ptrdiff_t op);
// };
#include <atomic>
#include <cassert>
template <class A, class T>
void
do_test()
{
typedef typename std::remove_pointer<T>::type X;
A obj(T(0));
assert(obj == T(0));
std::atomic_init(&obj, T(1));
assert(obj == T(1));
std::atomic_init(&obj, T(2));
assert(obj == T(2));
bool b0 = obj.is_lock_free();
obj.store(T(0));
assert(obj == T(0));
obj.store(T(1), std::memory_order_release);
assert(obj == T(1));
assert(obj.load() == T(1));
assert(obj.load(std::memory_order_acquire) == T(1));
assert(obj.exchange(T(2)) == T(1));
assert(obj == T(2));
assert(obj.exchange(T(3), std::memory_order_relaxed) == T(2));
assert(obj == T(3));
T x = obj;
assert(obj.compare_exchange_weak(x, T(2)) == true);
assert(obj == T(2));
assert(x == T(3));
assert(obj.compare_exchange_weak(x, T(1)) == false);
assert(obj == T(2));
assert(x == T(1));
x = T(2);
assert(obj.compare_exchange_strong(x, T(1)) == true);
assert(obj == T(1));
assert(x == T(2));
assert(obj.compare_exchange_strong(x, T(0)) == false);
assert(obj == T(1));
assert(x == T(0));
assert((obj = T(0)) == T(0));
assert(obj == T(0));
obj = T(2*sizeof(X));
assert((obj += std::ptrdiff_t(3)) == T(5*sizeof(X)));
assert(obj == T(5*sizeof(X)));
assert((obj -= std::ptrdiff_t(3)) == T(2*sizeof(X)));
assert(obj == T(2*sizeof(X)));
}
template <class A, class T>
void test()
{
do_test<A, T>();
do_test<volatile A, T>();
}
int main()
{
test<std::atomic<int*>, int*>();
}

View File

@@ -1,220 +0,0 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// typedef struct atomic_address
// {
// bool is_lock_free() const volatile;
// bool is_lock_free() const;
// void store(void*, memory_order = memory_order_seq_cst) volatile;
// void store(void*, memory_order = memory_order_seq_cst);
// void* load(memory_order = memory_order_seq_cst) const volatile;
// void* load(memory_order = memory_order_seq_cst) const;
// operator void*() const volatile;
// operator void*() const;
// void* exchange(void*, memory_order = memory_order_seq_cst) volatile;
// void* exchange(void*, memory_order = memory_order_seq_cst);
// bool compare_exchange_weak(void*&, void*, memory_order,
// memory_order) volatile;
// bool compare_exchange_weak(void*&, void*, memory_order, memory_order);
// bool compare_exchange_strong(void*&, void*, memory_order,
// memory_order) volatile;
// bool compare_exchange_strong(void*&, void*, memory_order, memory_order);
// bool compare_exchange_weak(void*&, void*,
// memory_order = memory_order_seq_cst) volatile;
// bool compare_exchange_weak(void*&, void*,
// memory_order = memory_order_seq_cst);
// bool compare_exchange_strong(void*&, void*,
// memory_order = memory_order_seq_cst) volatile;
// bool compare_exchange_strong(void*&, void*,
// memory_order = memory_order_seq_cst);
// bool compare_exchange_weak(const void*&, const void*,
// memory_order, memory_order) volatile;
// bool compare_exchange_weak(const void*&, const void*, memory_order,
// memory_order);
// bool compare_exchange_strong(const void*&, const void*, memory_order,
// memory_order) volatile;
// bool compare_exchange_strong(const void*&, const void*, memory_order,
// memory_order);
// bool compare_exchange_weak(const void*&, const void*,
// memory_order = memory_order_seq_cst) volatile;
// bool compare_exchange_weak(const void*&, const void*,
// memory_order = memory_order_seq_cst);
// bool compare_exchange_strong(const void*&, const void*,
// memory_order = memory_order_seq_cst) volatile;
// bool compare_exchange_strong(const void*&, const void*,
// memory_order = memory_order_seq_cst);
// void* fetch_add(ptrdiff_t, memory_order = memory_order_seq_cst) volatile;
// void* fetch_add(ptrdiff_t, memory_order = memory_order_seq_cst);
// void* fetch_sub(ptrdiff_t, memory_order = memory_order_seq_cst) volatile;
// void* fetch_sub(ptrdiff_t, memory_order = memory_order_seq_cst);
// atomic_address() = default;
// constexpr atomic_address(void*);
// atomic_address(const atomic_address&) = delete;
// atomic_address& operator=(const atomic_address&) = delete;
// atomic_address& operator=(const atomic_address&) volatile = delete;
// void* operator=(const void*) volatile;
// void* operator=(const void*);
// void* operator+=(ptrdiff_t) volatile;
// void* operator+=(ptrdiff_t);
// void* operator-=(ptrdiff_t) volatile;
// void* operator-=(ptrdiff_t);
// } atomic_address;
//
// bool atomic_is_lock_free(const volatile atomic_address*);
// bool atomic_is_lock_free(const atomic_address*);
// void atomic_init(volatile atomic_address*, void*);
// void atomic_init(atomic_address*, void*);
// void atomic_store(volatile atomic_address*, void*);
// void atomic_store(atomic_address*, void*);
// void atomic_store_explicit(volatile atomic_address*, void*, memory_order);
// void atomic_store_explicit(atomic_address*, void*, memory_order);
// void* atomic_load(const volatile atomic_address*);
// void* atomic_load(const atomic_address*);
// void* atomic_load_explicit(const volatile atomic_address*, memory_order);
// void* atomic_load_explicit(const atomic_address*, memory_order);
// void* atomic_exchange(volatile atomic_address*, void*);
// void* atomic_exchange(atomic_address*, void*);
// void* atomic_exchange_explicit(volatile atomic_address*, void*, memory_order);
// void* atomic_exchange_explicit(atomic_address*, void*, memory_order);
// bool atomic_compare_exchange_weak(volatile atomic_address*, void**, void*);
// bool atomic_compare_exchange_weak(atomic_address*, void**, void*);
// bool atomic_compare_exchange_strong(volatile atomic_address*, void**, void*);
// bool atomic_compare_exchange_strong(atomic_address*, void**, void*);
// bool atomic_compare_exchange_weak_explicit(volatile atomic_address*, void**,
// void*, memory_order, memory_order);
// bool atomic_compare_exchange_weak_explicit(atomic_address*, void**, void*,
// memory_order, memory_order);
// bool atomic_compare_exchange_strong_explicit(volatile atomic_address*, void**,
// void*, memory_order, memory_order);
// bool atomic_compare_exchange_strong_explicit(atomic_address*, void**, void*,
// memory_order, memory_order);
// void* atomic_fetch_add(volatile atomic_address*, ptrdiff_t);
// void* atomic_fetch_add(atomic_address*, ptrdiff_t);
// void* atomic_fetch_add_explicit(volatile atomic_address*, ptrdiff_t,
// memory_order);
// void* atomic_fetch_add_explicit(atomic_address*, ptrdiff_t, memory_order);
// void* atomic_fetch_sub(volatile atomic_address*, ptrdiff_t);
// void* atomic_fetch_sub(atomic_address*, ptrdiff_t);
// void* atomic_fetch_sub_explicit(volatile atomic_address*, ptrdiff_t,
// memory_order);
// void* atomic_fetch_sub_explicit(atomic_address*, ptrdiff_t, memory_order);
#include <atomic>
#include <cassert>
template <class A, class T>
void
do_test()
{
A obj(T(0));
assert(obj == T(0));
std::atomic_init(&obj, T(1));
assert(obj == T(1));
std::atomic_init(&obj, T(2));
assert(obj == T(2));
bool b0 = obj.is_lock_free();
obj.store(T(0));
assert(obj == T(0));
obj.store(T(1), std::memory_order_release);
assert(obj == T(1));
assert(obj.load() == T(1));
assert(obj.load(std::memory_order_acquire) == T(1));
assert(obj.exchange(T(2)) == T(1));
assert(obj == T(2));
assert(obj.exchange(T(3), std::memory_order_relaxed) == T(2));
assert(obj == T(3));
T x = obj;
assert(obj.compare_exchange_weak(x, T(2)) == true);
assert(obj == T(2));
assert(x == T(3));
assert(obj.compare_exchange_weak(x, T(1)) == false);
assert(obj == T(2));
assert(x == T(2));
assert(obj.compare_exchange_strong(x, T(1)) == true);
assert(obj == T(1));
assert(x == T(2));
assert(obj.compare_exchange_strong(x, T(0)) == false);
assert(obj == T(1));
assert(x == T(1));
assert((obj = T(0)) == T(0));
assert(obj == T(0));
obj = T(2);
assert((obj += std::ptrdiff_t(3)) == T(5));
assert(obj == T(5));
assert((obj -= std::ptrdiff_t(3)) == T(2));
assert(obj == T(2));
std::atomic_init(&obj, T(1));
assert(obj == T(1));
bool b1 = std::atomic_is_lock_free(&obj);
std::atomic_store(&obj, T(0));
assert(obj == T(0));
std::atomic_store_explicit(&obj, T(1), std::memory_order_release);
assert(obj == T(1));
assert(std::atomic_load(&obj) == T(1));
assert(std::atomic_load_explicit(&obj, std::memory_order_acquire) == T(1));
assert(std::atomic_exchange(&obj, T(2)) == T(1));
assert(obj == T(2));
assert(std::atomic_exchange_explicit(&obj, T(3), std::memory_order_relaxed) == T(2));
assert(obj == T(3));
x = obj;
assert(std::atomic_compare_exchange_weak(&obj, &x, T(2)) == true);
assert(obj == T(2));
assert(x == T(3));
assert(std::atomic_compare_exchange_weak(&obj, &x, T(1)) == false);
assert(obj == T(2));
assert(x == T(2));
assert(std::atomic_compare_exchange_strong(&obj, &x, T(1)) == true);
assert(obj == T(1));
assert(x == T(2));
assert(std::atomic_compare_exchange_strong(&obj, &x, T(0)) == false);
assert(obj == T(1));
assert(x == T(1));
assert(std::atomic_compare_exchange_weak_explicit(&obj, &x, T(2),
std::memory_order_relaxed, std::memory_order_relaxed) == true);
assert(obj == T(2));
assert(x == T(1));
assert(std::atomic_compare_exchange_weak_explicit(&obj, &x, T(3),
std::memory_order_relaxed, std::memory_order_relaxed) == false);
assert(obj == T(2));
assert(x == T(2));
assert(std::atomic_compare_exchange_strong_explicit(&obj, &x, T(3),
std::memory_order_relaxed, std::memory_order_relaxed) == true);
assert(obj == T(3));
assert(x == T(2));
assert(std::atomic_compare_exchange_strong_explicit(&obj, &x, T(0),
std::memory_order_relaxed, std::memory_order_relaxed) == false);
assert(obj == T(3));
assert(x == T(3));
assert((obj = T(1)) == T(1));
assert(obj == T(1));
obj = T(2);
assert(std::atomic_fetch_add(&obj, std::ptrdiff_t(3)) == T(2));
assert(obj == T(5));
assert(std::atomic_fetch_add_explicit(&obj, std::ptrdiff_t(3), std::memory_order_seq_cst) == T(5));
assert(obj == T(8));
assert(std::atomic_fetch_sub(&obj, std::ptrdiff_t(3)) == T(8));
assert(obj == T(5));
assert(std::atomic_fetch_sub_explicit(&obj, std::ptrdiff_t(3), std::memory_order_seq_cst) == T(5));
assert(obj == T(2));
}
template <class A, class T>
void test()
{
do_test<A, T>();
do_test<volatile A, T>();
}
int main()
{
test<std::atomic_address, void*>();
}

View File

@@ -1,239 +0,0 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// typedef struct atomic_bool
// {
// bool is_lock_free() const volatile;
// bool is_lock_free() const;
// void store(bool, memory_order = memory_order_seq_cst) volatile;
// void store(bool, memory_order = memory_order_seq_cst);
// bool load(memory_order = memory_order_seq_cst) const volatile;
// bool load(memory_order = memory_order_seq_cst) const;
// operator bool() const volatile;
// operator bool() const;
// bool exchange(bool, memory_order = memory_order_seq_cst) volatile;
// bool exchange(bool, memory_order = memory_order_seq_cst);
// bool compare_exchange_weak(bool&, bool, memory_order,
// memory_order) volatile;
// bool compare_exchange_weak(bool&, bool, memory_order, memory_order);
// bool compare_exchange_strong(bool&, bool, memory_order,
// memory_order) volatile;
// bool compare_exchange_strong(bool&, bool, memory_order, memory_order);
// bool compare_exchange_weak(bool&, bool,
// memory_order = memory_order_seq_cst) volatile;
// bool compare_exchange_weak(bool&, bool,
// memory_order = memory_order_seq_cst);
// bool compare_exchange_strong(bool&, bool,
// memory_order = memory_order_seq_cst) volatile;
// bool compare_exchange_strong(bool&, bool,
// memory_order = memory_order_seq_cst);
// atomic_bool() = default;
// constexpr atomic_bool(bool);
// atomic_bool(const atomic_bool&) = delete;
// atomic_bool& operator=(const atomic_bool&) = delete;
// atomic_bool& operator=(const atomic_bool&) volatile = delete;
// bool operator=(bool) volatile;
// bool operator=(bool);
// } atomic_bool;
//
// bool atomic_is_lock_free(const volatile atomic_bool*);
// bool atomic_is_lock_free(const atomic_bool*);
// void atomic_init(volatile atomic_bool*, bool);
// void atomic_init(atomic_bool*, bool);
// void atomic_store(volatile atomic_bool*, bool);
// void atomic_store(atomic_bool*, bool);
// void atomic_store_explicit(volatile atomic_bool*, bool, memory_order);
// void atomic_store_explicit(atomic_bool*, bool, memory_order);
// bool atomic_load(const volatile atomic_bool*);
// bool atomic_load(const atomic_bool*);
// bool atomic_load_explicit(const volatile atomic_bool*, memory_order);
// bool atomic_load_explicit(const atomic_bool*, memory_order);
// bool atomic_exchange(volatile atomic_bool*, bool);
// bool atomic_exchange(atomic_bool*, bool);
// bool atomic_exchange_explicit(volatile atomic_bool*, bool, memory_order);
// bool atomic_exchange_explicit(atomic_bool*, bool, memory_order);
// bool atomic_compare_exchange_weak(volatile atomic_bool*, bool*, bool);
// bool atomic_compare_exchange_weak(atomic_bool*, bool*, bool);
// bool atomic_compare_exchange_strong(volatile atomic_bool*, bool*, bool);
// bool atomic_compare_exchange_strong(atomic_bool*, bool*, bool);
// bool atomic_compare_exchange_weak_explicit(volatile atomic_bool*, bool*, bool,
// memory_order, memory_order);
// bool atomic_compare_exchange_weak_explicit(atomic_bool*, bool*, bool,
// memory_order, memory_order);
// bool atomic_compare_exchange_strong_explicit(volatile atomic_bool*, bool*, bool,
// memory_order, memory_order);
// bool atomic_compare_exchange_strong_explicit(atomic_bool*, bool*, bool,
// memory_order, memory_order);
#include <atomic>
#include <cassert>
int main()
{
{
volatile std::atomic_bool obj(true);
assert(obj == true);
std::atomic_init(&obj, false);
assert(obj == false);
std::atomic_init(&obj, true);
assert(obj == true);
bool b0 = obj.is_lock_free();
obj.store(false);
assert(obj == false);
obj.store(true, std::memory_order_release);
assert(obj == true);
assert(obj.load() == true);
assert(obj.load(std::memory_order_acquire) == true);
assert(obj.exchange(false) == true);
assert(obj == false);
assert(obj.exchange(true, std::memory_order_relaxed) == false);
assert(obj == true);
bool x = obj;
assert(obj.compare_exchange_weak(x, false) == true);
assert(obj == false);
assert(x == true);
assert(obj.compare_exchange_weak(x, true) == false);
assert(obj == false);
assert(x == false);
assert(obj.compare_exchange_strong(x, true) == true);
assert(obj == true);
assert(x == false);
assert(obj.compare_exchange_strong(x, false) == false);
assert(obj == true);
assert(x == true);
assert((obj = false) == false);
assert(obj == false);
std::atomic_init(&obj, true);
assert(obj == true);
bool b1 = std::atomic_is_lock_free(&obj);
std::atomic_store(&obj, false);
assert(obj == false);
std::atomic_store_explicit(&obj, true, std::memory_order_release);
assert(obj == true);
assert(std::atomic_load(&obj) == true);
assert(std::atomic_load_explicit(&obj, std::memory_order_acquire) == true);
assert(std::atomic_exchange(&obj, false) == true);
assert(obj == false);
assert(std::atomic_exchange_explicit(&obj, true, std::memory_order_relaxed) == false);
assert(obj == true);
x = obj;
assert(std::atomic_compare_exchange_weak(&obj, &x, false) == true);
assert(obj == false);
assert(x == true);
assert(std::atomic_compare_exchange_weak(&obj, &x, true) == false);
assert(obj == false);
assert(x == false);
assert(std::atomic_compare_exchange_strong(&obj, &x, true) == true);
assert(obj == true);
assert(x == false);
assert(std::atomic_compare_exchange_strong(&obj, &x, false) == false);
assert(obj == true);
assert(x == true);
assert(std::atomic_compare_exchange_weak_explicit(&obj, &x, false,
std::memory_order_relaxed, std::memory_order_relaxed) == true);
assert(obj == false);
assert(x == true);
assert(std::atomic_compare_exchange_weak_explicit(&obj, &x, true,
std::memory_order_relaxed, std::memory_order_relaxed) == false);
assert(obj == false);
assert(x == false);
assert(std::atomic_compare_exchange_strong_explicit(&obj, &x, true,
std::memory_order_relaxed, std::memory_order_relaxed) == true);
assert(obj == true);
assert(x == false);
assert(std::atomic_compare_exchange_strong_explicit(&obj, &x, false,
std::memory_order_relaxed, std::memory_order_relaxed) == false);
assert(obj == true);
assert(x == true);
assert((obj = false) == false);
assert(obj == false);
}
{
std::atomic_bool obj(true);
assert(obj == true);
std::atomic_init(&obj, false);
assert(obj == false);
std::atomic_init(&obj, true);
assert(obj == true);
bool b0 = obj.is_lock_free();
obj.store(false);
assert(obj == false);
obj.store(true, std::memory_order_release);
assert(obj == true);
assert(obj.load() == true);
assert(obj.load(std::memory_order_acquire) == true);
assert(obj.exchange(false) == true);
assert(obj == false);
assert(obj.exchange(true, std::memory_order_relaxed) == false);
assert(obj == true);
bool x = obj;
assert(obj.compare_exchange_weak(x, false) == true);
assert(obj == false);
assert(x == true);
assert(obj.compare_exchange_weak(x, true) == false);
assert(obj == false);
assert(x == false);
assert(obj.compare_exchange_strong(x, true) == true);
assert(obj == true);
assert(x == false);
assert(obj.compare_exchange_strong(x, false) == false);
assert(obj == true);
assert(x == true);
assert((obj = false) == false);
assert(obj == false);
std::atomic_init(&obj, true);
assert(obj == true);
bool b1 = std::atomic_is_lock_free(&obj);
std::atomic_store(&obj, false);
assert(obj == false);
std::atomic_store_explicit(&obj, true, std::memory_order_release);
assert(obj == true);
assert(std::atomic_load(&obj) == true);
assert(std::atomic_load_explicit(&obj, std::memory_order_acquire) == true);
assert(std::atomic_exchange(&obj, false) == true);
assert(obj == false);
assert(std::atomic_exchange_explicit(&obj, true, std::memory_order_relaxed) == false);
assert(obj == true);
x = obj;
assert(std::atomic_compare_exchange_weak(&obj, &x, false) == true);
assert(obj == false);
assert(x == true);
assert(std::atomic_compare_exchange_weak(&obj, &x, true) == false);
assert(obj == false);
assert(x == false);
assert(std::atomic_compare_exchange_strong(&obj, &x, true) == true);
assert(obj == true);
assert(x == false);
assert(std::atomic_compare_exchange_strong(&obj, &x, false) == false);
assert(obj == true);
assert(x == true);
assert(std::atomic_compare_exchange_weak_explicit(&obj, &x, false,
std::memory_order_relaxed, std::memory_order_relaxed) == true);
assert(obj == false);
assert(x == true);
assert(std::atomic_compare_exchange_weak_explicit(&obj, &x, true,
std::memory_order_relaxed, std::memory_order_relaxed) == false);
assert(obj == false);
assert(x == false);
assert(std::atomic_compare_exchange_strong_explicit(&obj, &x, true,
std::memory_order_relaxed, std::memory_order_relaxed) == true);
assert(obj == true);
assert(x == false);
assert(std::atomic_compare_exchange_strong_explicit(&obj, &x, false,
std::memory_order_relaxed, std::memory_order_relaxed) == false);
assert(obj == true);
assert(x == true);
assert((obj = false) == false);
assert(obj == false);
}
}

View File

@@ -1,276 +0,0 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// typedef struct atomic_itype
// {
// bool is_lock_free() const volatile;
// bool is_lock_free() const;
// void store(itype, memory_order = memory_order_seq_cst) volatile;
// void store(itype, memory_order = memory_order_seq_cst);
// itype load(memory_order = memory_order_seq_cst) const volatile;
// itype load(memory_order = memory_order_seq_cst) const;
// operator itype() const volatile;
// operator itype() const;
// itype exchange(itype, memory_order = memory_order_seq_cst) volatile;
// itype exchange(itype, memory_order = memory_order_seq_cst);
// bool compare_exchange_weak(itype&, itype, memory_order,
// memory_order) volatile;
// bool compare_exchange_weak(itype&, itype, memory_order, memory_order);
// bool compare_exchange_strong(itype&, itype, memory_order,
// memory_order) volatile;
// bool compare_exchange_strong(itype&, itype, memory_order, memory_order);
// bool compare_exchange_weak(itype&, itype,
// memory_order = memory_order_seq_cst) volatile;
// bool compare_exchange_weak(itype&, itype,
// memory_order = memory_order_seq_cst);
// bool compare_exchange_strong(itype&, itype,
// memory_order = memory_order_seq_cst) volatile;
// bool compare_exchange_strong(itype&, itype,
// memory_order = memory_order_seq_cst);
// itype fetch_add(itype, memory_order = memory_order_seq_cst) volatile;
// itype fetch_add(itype, memory_order = memory_order_seq_cst);
// itype fetch_sub(itype, memory_order = memory_order_seq_cst) volatile;
// itype fetch_sub(itype, memory_order = memory_order_seq_cst);
// itype fetch_and(itype, memory_order = memory_order_seq_cst) volatile;
// itype fetch_and(itype, memory_order = memory_order_seq_cst);
// itype fetch_or(itype, memory_order = memory_order_seq_cst) volatile;
// itype fetch_or(itype, memory_order = memory_order_seq_cst);
// itype fetch_xor(itype, memory_order = memory_order_seq_cst) volatile;
// itype fetch_xor(itype, memory_order = memory_order_seq_cst);
// atomic_itype() = default;
// constexpr atomic_itype(itype);
// atomic_itype(const atomic_itype&) = delete;
// atomic_itype& operator=(const atomic_itype&) = delete;
// atomic_itype& operator=(const atomic_itype&) volatile = delete;
// itype operator=(itype) volatile;
// itype operator=(itype);
// itype operator++(int) volatile;
// itype operator++(int);
// itype operator--(int) volatile;
// itype operator--(int);
// itype operator++() volatile;
// itype operator++();
// itype operator--() volatile;
// itype operator--();
// itype operator+=(itype) volatile;
// itype operator+=(itype);
// itype operator-=(itype) volatile;
// itype operator-=(itype);
// itype operator&=(itype) volatile;
// itype operator&=(itype);
// itype operator|=(itype) volatile;
// itype operator|=(itype);
// itype operator^=(itype) volatile;
// itype operator^=(itype);
// } atomic_itype;
//
// bool atomic_is_lock_free(const volatile atomic_itype*);
// bool atomic_is_lock_free(const atomic_itype*);
// void atomic_init(volatile atomic_itype*, itype);
// void atomic_init(atomic_itype*, itype);
// void atomic_store(volatile atomic_itype*, itype);
// void atomic_store(atomic_itype*, itype);
// void atomic_store_explicit(volatile atomic_itype*, itype, memory_order);
// void atomic_store_explicit(atomic_itype*, itype, memory_order);
// itype atomic_load(const volatile atomic_itype*);
// itype atomic_load(const atomic_itype*);
// itype atomic_load_explicit(const volatile atomic_itype*, memory_order);
// itype atomic_load_explicit(const atomic_itype*, memory_order);
// itype atomic_exchange(volatile atomic_itype*, itype);
// itype atomic_exchange(atomic_itype*, itype);
// itype atomic_exchange_explicit(volatile atomic_itype*, itype, memory_order);
// itype atomic_exchange_explicit(atomic_itype*, itype, memory_order);
// bool atomic_compare_exchange_weak(volatile atomic_itype*, itype*, itype);
// bool atomic_compare_exchange_weak(atomic_itype*, itype*, itype);
// bool atomic_compare_exchange_strong(volatile atomic_itype*, itype*, itype);
// bool atomic_compare_exchange_strong(atomic_itype*, itype*, itype);
// bool atomic_compare_exchange_weak_explicit(volatile atomic_itype*, itype*, itype,
// memory_order, memory_order);
// bool atomic_compare_exchange_weak_explicit(atomic_itype*, itype*, itype,
// memory_order, memory_order);
// bool atomic_compare_exchange_strong_explicit(volatile atomic_itype*, itype*, itype,
// memory_order, memory_order);
// bool atomic_compare_exchange_strong_explicit(atomic_itype*, itype*, itype,
// memory_order, memory_order);
// itype atomic_fetch_add(volatile atomic_itype*, itype);
// itype atomic_fetch_add(atomic_itype*, itype);
// itype atomic_fetch_add_explicit(volatile atomic_itype*, itype, memory_order);
// itype atomic_fetch_add_explicit(atomic_itype*, itype, memory_order);
// itype atomic_fetch_sub(volatile atomic_itype*, itype);
// itype atomic_fetch_sub(atomic_itype*, itype);
// itype atomic_fetch_sub_explicit(volatile atomic_itype*, itype, memory_order);
// itype atomic_fetch_sub_explicit(atomic_itype*, itype, memory_order);
// itype atomic_fetch_and(volatile atomic_itype*, itype);
// itype atomic_fetch_and(atomic_itype*, itype);
// itype atomic_fetch_and_explicit(volatile atomic_itype*, itype, memory_order);
// itype atomic_fetch_and_explicit(atomic_itype*, itype, memory_order);
// itype atomic_fetch_or(volatile atomic_itype*, itype);
// itype atomic_fetch_or(atomic_itype*, itype);
// itype atomic_fetch_or_explicit(volatile atomic_itype*, itype, memory_order);
// itype atomic_fetch_or_explicit(atomic_itype*, itype, memory_order);
// itype atomic_fetch_xor(volatile atomic_itype*, itype);
// itype atomic_fetch_xor(atomic_itype*, itype);
// itype atomic_fetch_xor_explicit(volatile atomic_itype*, itype, memory_order);
// itype atomic_fetch_xor_explicit(atomic_itype*, itype, memory_order);
#include <atomic>
#include <cassert>
template <class A, class T>
void
do_test()
{
A obj(T(0));
assert(obj == T(0));
std::atomic_init(&obj, T(1));
assert(obj == T(1));
std::atomic_init(&obj, T(2));
assert(obj == T(2));
bool b0 = obj.is_lock_free();
obj.store(T(0));
assert(obj == T(0));
obj.store(T(1), std::memory_order_release);
assert(obj == T(1));
assert(obj.load() == T(1));
assert(obj.load(std::memory_order_acquire) == T(1));
assert(obj.exchange(T(2)) == T(1));
assert(obj == T(2));
assert(obj.exchange(T(3), std::memory_order_relaxed) == T(2));
assert(obj == T(3));
T x = obj;
assert(obj.compare_exchange_weak(x, T(2)) == true);
assert(obj == T(2));
assert(x == T(3));
assert(obj.compare_exchange_weak(x, T(1)) == false);
assert(obj == T(2));
assert(x == T(2));
assert(obj.compare_exchange_strong(x, T(1)) == true);
assert(obj == T(1));
assert(x == T(2));
assert(obj.compare_exchange_strong(x, T(0)) == false);
assert(obj == T(1));
assert(x == T(1));
assert((obj = T(0)) == T(0));
assert(obj == T(0));
assert(obj++ == T(0));
assert(obj == T(1));
assert(++obj == T(2));
assert(obj == T(2));
assert(--obj == T(1));
assert(obj == T(1));
assert(obj-- == T(1));
assert(obj == T(0));
obj = T(2);
assert((obj += T(3)) == T(5));
assert(obj == T(5));
assert((obj -= T(3)) == T(2));
assert(obj == T(2));
assert((obj |= T(5)) == T(7));
assert(obj == T(7));
assert((obj &= T(0xF)) == T(7));
assert(obj == T(7));
assert((obj ^= T(0xF)) == T(8));
assert(obj == T(8));
std::atomic_init(&obj, T(1));
assert(obj == T(1));
bool b1 = std::atomic_is_lock_free(&obj);
std::atomic_store(&obj, T(0));
assert(obj == T(0));
std::atomic_store_explicit(&obj, T(1), std::memory_order_release);
assert(obj == T(1));
assert(std::atomic_load(&obj) == T(1));
assert(std::atomic_load_explicit(&obj, std::memory_order_acquire) == T(1));
assert(std::atomic_exchange(&obj, T(2)) == T(1));
assert(obj == T(2));
assert(std::atomic_exchange_explicit(&obj, T(3), std::memory_order_relaxed) == T(2));
assert(obj == T(3));
x = obj;
assert(std::atomic_compare_exchange_weak(&obj, &x, T(2)) == true);
assert(obj == T(2));
assert(x == T(3));
assert(std::atomic_compare_exchange_weak(&obj, &x, T(1)) == false);
assert(obj == T(2));
assert(x == T(2));
assert(std::atomic_compare_exchange_strong(&obj, &x, T(1)) == true);
assert(obj == T(1));
assert(x == T(2));
assert(std::atomic_compare_exchange_strong(&obj, &x, T(0)) == false);
assert(obj == T(1));
assert(x == T(1));
assert(std::atomic_compare_exchange_weak_explicit(&obj, &x, T(2),
std::memory_order_relaxed, std::memory_order_relaxed) == true);
assert(obj == T(2));
assert(x == T(1));
assert(std::atomic_compare_exchange_weak_explicit(&obj, &x, T(3),
std::memory_order_relaxed, std::memory_order_relaxed) == false);
assert(obj == T(2));
assert(x == T(2));
assert(std::atomic_compare_exchange_strong_explicit(&obj, &x, T(3),
std::memory_order_relaxed, std::memory_order_relaxed) == true);
assert(obj == T(3));
assert(x == T(2));
assert(std::atomic_compare_exchange_strong_explicit(&obj, &x, T(0),
std::memory_order_relaxed, std::memory_order_relaxed) == false);
assert(obj == T(3));
assert(x == T(3));
assert((obj = T(1)) == T(1));
assert(obj == T(1));
obj = T(2);
assert(std::atomic_fetch_add(&obj, T(3)) == T(2));
assert(obj == T(5));
assert(std::atomic_fetch_add_explicit(&obj, T(3), std::memory_order_seq_cst) == T(5));
assert(obj == T(8));
assert(std::atomic_fetch_sub(&obj, T(3)) == T(8));
assert(obj == T(5));
assert(std::atomic_fetch_sub_explicit(&obj, T(3), std::memory_order_seq_cst) == T(5));
assert(obj == T(2));
assert(std::atomic_fetch_or(&obj, T(5)) == T(2));
assert(obj == T(7));
assert(std::atomic_fetch_or_explicit(&obj, T(8), std::memory_order_seq_cst) == T(7));
assert(obj == T(0xF));
assert(std::atomic_fetch_and(&obj, T(7)) == T(0xF));
assert(obj == T(7));
assert(std::atomic_fetch_and_explicit(&obj, T(3), std::memory_order_seq_cst) == T(7));
assert(obj == T(3));
assert(std::atomic_fetch_xor(&obj, T(7)) == T(3));
assert(obj == T(4));
assert(std::atomic_fetch_xor_explicit(&obj, T(7), std::memory_order_seq_cst) == T(4));
assert(obj == T(3));
}
template <class A, class T>
void test()
{
do_test<A, T>();
do_test<volatile A, T>();
}
int main()
{
test<std::atomic_char, char>();
test<std::atomic_schar, signed char>();
test<std::atomic_uchar, unsigned char>();
test<std::atomic_short, short>();
test<std::atomic_ushort, unsigned short>();
test<std::atomic_int, int>();
test<std::atomic_uint, unsigned int>();
test<std::atomic_long, long>();
test<std::atomic_ulong, unsigned long>();
test<std::atomic_llong, long long>();
test<std::atomic_ullong, unsigned long long>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<std::atomic_char16_t, char16_t>();
test<std::atomic_char32_t, char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<std::atomic_wchar_t, wchar_t>();
}

View File

@@ -0,0 +1,163 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// struct atomic
// {
// bool is_lock_free() const volatile;
// bool is_lock_free() const;
// void store(T desr, memory_order m = memory_order_seq_cst) volatile;
// void store(T desr, memory_order m = memory_order_seq_cst);
// T load(memory_order m = memory_order_seq_cst) const volatile;
// T load(memory_order m = memory_order_seq_cst) const;
// operator T() const volatile;
// operator T() const;
// T exchange(T desr, memory_order m = memory_order_seq_cst) volatile;
// T exchange(T desr, memory_order m = memory_order_seq_cst);
// bool compare_exchange_weak(T& expc, T desr,
// memory_order s, memory_order f) volatile;
// bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f);
// bool compare_exchange_strong(T& expc, T desr,
// memory_order s, memory_order f) volatile;
// bool compare_exchange_strong(T& expc, T desr,
// memory_order s, memory_order f);
// bool compare_exchange_weak(T& expc, T desr,
// memory_order m = memory_order_seq_cst) volatile;
// bool compare_exchange_weak(T& expc, T desr,
// memory_order m = memory_order_seq_cst);
// bool compare_exchange_strong(T& expc, T desr,
// memory_order m = memory_order_seq_cst) volatile;
// bool compare_exchange_strong(T& expc, T desr,
// memory_order m = memory_order_seq_cst);
//
// atomic() = default;
// constexpr atomic(T desr);
// atomic(const atomic&) = delete;
// atomic& operator=(const atomic&) = delete;
// atomic& operator=(const atomic&) volatile = delete;
// T operator=(T) volatile;
// T operator=(T);
// };
#include <atomic>
#include <cassert>
int main()
{
{
volatile std::atomic<bool> _;
volatile std::atomic<bool> obj(true);
assert(obj == true);
std::atomic_init(&obj, false);
assert(obj == false);
std::atomic_init(&obj, true);
assert(obj == true);
bool b0 = obj.is_lock_free();
obj.store(false);
assert(obj == false);
obj.store(true, std::memory_order_release);
assert(obj == true);
assert(obj.load() == true);
assert(obj.load(std::memory_order_acquire) == true);
assert(obj.exchange(false) == true);
assert(obj == false);
assert(obj.exchange(true, std::memory_order_relaxed) == false);
assert(obj == true);
bool x = obj;
assert(obj.compare_exchange_weak(x, false) == true);
assert(obj == false);
assert(x == true);
assert(obj.compare_exchange_weak(x, true,
std::memory_order_seq_cst) == false);
assert(obj == false);
assert(x == true);
obj.store(true);
assert(obj.compare_exchange_weak(x, false,
std::memory_order_seq_cst,
std::memory_order_seq_cst) == true);
assert(obj == false);
assert(x == true);
x = true;
obj.store(true);
assert(obj.compare_exchange_strong(x, false) == true);
assert(obj == false);
assert(x == true);
assert(obj.compare_exchange_strong(x, true,
std::memory_order_seq_cst) == false);
assert(obj == false);
assert(x == true);
x = true;
obj.store(true);
assert(obj.compare_exchange_strong(x, false,
std::memory_order_seq_cst,
std::memory_order_seq_cst) == true);
assert(obj == false);
assert(x == true);
assert((obj = false) == false);
assert(obj == false);
assert((obj = true) == true);
assert(obj == true);
}
{
std::atomic<bool> _;
std::atomic<bool> obj(true);
assert(obj == true);
std::atomic_init(&obj, false);
assert(obj == false);
std::atomic_init(&obj, true);
assert(obj == true);
bool b0 = obj.is_lock_free();
obj.store(false);
assert(obj == false);
obj.store(true, std::memory_order_release);
assert(obj == true);
assert(obj.load() == true);
assert(obj.load(std::memory_order_acquire) == true);
assert(obj.exchange(false) == true);
assert(obj == false);
assert(obj.exchange(true, std::memory_order_relaxed) == false);
assert(obj == true);
bool x = obj;
assert(obj.compare_exchange_weak(x, false) == true);
assert(obj == false);
assert(x == true);
assert(obj.compare_exchange_weak(x, true,
std::memory_order_seq_cst) == false);
assert(obj == false);
assert(x == true);
obj.store(true);
assert(obj.compare_exchange_weak(x, false,
std::memory_order_seq_cst,
std::memory_order_seq_cst) == true);
assert(obj == false);
assert(x == true);
x = true;
obj.store(true);
assert(obj.compare_exchange_strong(x, false) == true);
assert(obj == false);
assert(x == true);
assert(obj.compare_exchange_strong(x, true,
std::memory_order_seq_cst) == false);
assert(obj == false);
assert(x == true);
x = true;
obj.store(true);
assert(obj.compare_exchange_strong(x, false,
std::memory_order_seq_cst,
std::memory_order_seq_cst) == true);
assert(obj == false);
assert(x == true);
assert((obj = false) == false);
assert(obj == false);
assert((obj = true) == true);
assert(obj == true);
}
}

View File

@@ -0,0 +1,66 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// typedef atomic<int_least8_t> atomic_int_least8_t;
// typedef atomic<uint_least8_t> atomic_uint_least8_t;
// typedef atomic<int_least16_t> atomic_int_least16_t;
// typedef atomic<uint_least16_t> atomic_uint_least16_t;
// typedef atomic<int_least32_t> atomic_int_least32_t;
// typedef atomic<uint_least32_t> atomic_uint_least32_t;
// typedef atomic<int_least64_t> atomic_int_least64_t;
// typedef atomic<uint_least64_t> atomic_uint_least64_t;
//
// typedef atomic<int_fast8_t> atomic_int_fast8_t;
// typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
// typedef atomic<int_fast16_t> atomic_int_fast16_t;
// typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
// typedef atomic<int_fast32_t> atomic_int_fast32_t;
// typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
// typedef atomic<int_fast64_t> atomic_int_fast64_t;
// typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
//
// typedef atomic<intptr_t> atomic_intptr_t;
// typedef atomic<uintptr_t> atomic_uintptr_t;
// typedef atomic<size_t> atomic_size_t;
// typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
// typedef atomic<intmax_t> atomic_intmax_t;
// typedef atomic<uintmax_t> atomic_uintmax_t;
#include <atomic>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::atomic< std::int_least8_t>, std::atomic_int_least8_t>::value), "");
static_assert((std::is_same<std::atomic< std::uint_least8_t>, std::atomic_uint_least8_t>::value), "");
static_assert((std::is_same<std::atomic< std::int_least16_t>, std::atomic_int_least16_t>::value), "");
static_assert((std::is_same<std::atomic<std::uint_least16_t>, std::atomic_uint_least16_t>::value), "");
static_assert((std::is_same<std::atomic< std::int_least32_t>, std::atomic_int_least32_t>::value), "");
static_assert((std::is_same<std::atomic<std::uint_least32_t>, std::atomic_uint_least32_t>::value), "");
static_assert((std::is_same<std::atomic< std::int_least64_t>, std::atomic_int_least64_t>::value), "");
static_assert((std::is_same<std::atomic<std::uint_least64_t>, std::atomic_uint_least64_t>::value), "");
static_assert((std::is_same<std::atomic< std::int_fast8_t>, std::atomic_int_fast8_t>::value), "");
static_assert((std::is_same<std::atomic< std::uint_fast8_t>, std::atomic_uint_fast8_t>::value), "");
static_assert((std::is_same<std::atomic< std::int_fast16_t>, std::atomic_int_fast16_t>::value), "");
static_assert((std::is_same<std::atomic<std::uint_fast16_t>, std::atomic_uint_fast16_t>::value), "");
static_assert((std::is_same<std::atomic< std::int_fast32_t>, std::atomic_int_fast32_t>::value), "");
static_assert((std::is_same<std::atomic<std::uint_fast32_t>, std::atomic_uint_fast32_t>::value), "");
static_assert((std::is_same<std::atomic< std::int_fast64_t>, std::atomic_int_fast64_t>::value), "");
static_assert((std::is_same<std::atomic<std::uint_fast64_t>, std::atomic_uint_fast64_t>::value), "");
static_assert((std::is_same<std::atomic< std::intptr_t>, std::atomic_intptr_t>::value), "");
static_assert((std::is_same<std::atomic<std::uintptr_t>, std::atomic_uintptr_t>::value), "");
static_assert((std::is_same<std::atomic< std::size_t>, std::atomic_size_t>::value), "");
static_assert((std::is_same<std::atomic<std::ptrdiff_t>, std::atomic_ptrdiff_t>::value), "");
static_assert((std::is_same<std::atomic< std::intmax_t>, std::atomic_intmax_t>::value), "");
static_assert((std::is_same<std::atomic<std::uintmax_t>, std::atomic_uintmax_t>::value), "");
}

View File

@@ -0,0 +1,191 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <>
// struct atomic<integral>
// {
// bool is_lock_free() const volatile;
// bool is_lock_free() const;
// void store(integral desr, memory_order m = memory_order_seq_cst) volatile;
// void store(integral desr, memory_order m = memory_order_seq_cst);
// integral load(memory_order m = memory_order_seq_cst) const volatile;
// integral load(memory_order m = memory_order_seq_cst) const;
// operator integral() const volatile;
// operator integral() const;
// integral exchange(integral desr,
// memory_order m = memory_order_seq_cst) volatile;
// integral exchange(integral desr, memory_order m = memory_order_seq_cst);
// bool compare_exchange_weak(integral& expc, integral desr,
// memory_order s, memory_order f) volatile;
// bool compare_exchange_weak(integral& expc, integral desr,
// memory_order s, memory_order f);
// bool compare_exchange_strong(integral& expc, integral desr,
// memory_order s, memory_order f) volatile;
// bool compare_exchange_strong(integral& expc, integral desr,
// memory_order s, memory_order f);
// bool compare_exchange_weak(integral& expc, integral desr,
// memory_order m = memory_order_seq_cst) volatile;
// bool compare_exchange_weak(integral& expc, integral desr,
// memory_order m = memory_order_seq_cst);
// bool compare_exchange_strong(integral& expc, integral desr,
// memory_order m = memory_order_seq_cst) volatile;
// bool compare_exchange_strong(integral& expc, integral desr,
// memory_order m = memory_order_seq_cst);
//
// integral
// fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile;
// integral fetch_add(integral op, memory_order m = memory_order_seq_cst);
// integral
// fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile;
// integral fetch_sub(integral op, memory_order m = memory_order_seq_cst);
// integral
// fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile;
// integral fetch_and(integral op, memory_order m = memory_order_seq_cst);
// integral
// fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile;
// integral fetch_or(integral op, memory_order m = memory_order_seq_cst);
// integral
// fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile;
// integral fetch_xor(integral op, memory_order m = memory_order_seq_cst);
//
// atomic() = default;
// constexpr atomic(integral desr);
// atomic(const atomic&) = delete;
// atomic& operator=(const atomic&) = delete;
// atomic& operator=(const atomic&) volatile = delete;
// integral operator=(integral desr) volatile;
// integral operator=(integral desr);
//
// integral operator++(int) volatile;
// integral operator++(int);
// integral operator--(int) volatile;
// integral operator--(int);
// integral operator++() volatile;
// integral operator++();
// integral operator--() volatile;
// integral operator--();
// integral operator+=(integral op) volatile;
// integral operator+=(integral op);
// integral operator-=(integral op) volatile;
// integral operator-=(integral op);
// integral operator&=(integral op) volatile;
// integral operator&=(integral op);
// integral operator|=(integral op) volatile;
// integral operator|=(integral op);
// integral operator^=(integral op) volatile;
// integral operator^=(integral op);
// };
#include <atomic>
#include <cassert>
template <class A, class T>
void
do_test()
{
A obj(T(0));
assert(obj == T(0));
std::atomic_init(&obj, T(1));
assert(obj == T(1));
std::atomic_init(&obj, T(2));
assert(obj == T(2));
bool b0 = obj.is_lock_free();
obj.store(T(0));
assert(obj == T(0));
obj.store(T(1), std::memory_order_release);
assert(obj == T(1));
assert(obj.load() == T(1));
assert(obj.load(std::memory_order_acquire) == T(1));
assert(obj.exchange(T(2)) == T(1));
assert(obj == T(2));
assert(obj.exchange(T(3), std::memory_order_relaxed) == T(2));
assert(obj == T(3));
T x = obj;
assert(obj.compare_exchange_weak(x, T(2)) == true);
assert(obj == T(2));
assert(x == T(3));
assert(obj.compare_exchange_weak(x, T(1)) == false);
assert(obj == T(2));
assert(x == T(1));
x = T(2);
assert(obj.compare_exchange_strong(x, T(1)) == true);
assert(obj == T(1));
assert(x == T(2));
assert(obj.compare_exchange_strong(x, T(0)) == false);
assert(obj == T(1));
assert(x == T(0));
assert((obj = T(0)) == T(0));
assert(obj == T(0));
assert(obj++ == T(0));
assert(obj == T(1));
assert(++obj == T(2));
assert(obj == T(2));
assert(--obj == T(1));
assert(obj == T(1));
assert(obj-- == T(1));
assert(obj == T(0));
obj = T(2);
assert((obj += T(3)) == T(5));
assert(obj == T(5));
assert((obj -= T(3)) == T(2));
assert(obj == T(2));
assert((obj |= T(5)) == T(7));
assert(obj == T(7));
assert((obj &= T(0xF)) == T(7));
assert(obj == T(7));
assert((obj ^= T(0xF)) == T(8));
assert(obj == T(8));
}
template <class A, class T>
void test()
{
do_test<A, T>();
do_test<volatile A, T>();
}
int main()
{
test<std::atomic_char, char>();
test<std::atomic_schar, signed char>();
test<std::atomic_uchar, unsigned char>();
test<std::atomic_short, short>();
test<std::atomic_ushort, unsigned short>();
test<std::atomic_int, int>();
test<std::atomic_uint, unsigned int>();
test<std::atomic_long, long>();
test<std::atomic_ulong, unsigned long>();
test<std::atomic_llong, long long>();
test<std::atomic_ullong, unsigned long long>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<std::atomic_char16_t, char16_t>();
test<std::atomic_char32_t, char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<std::atomic_wchar_t, wchar_t>();
test<volatile std::atomic_char, char>();
test<volatile std::atomic_schar, signed char>();
test<volatile std::atomic_uchar, unsigned char>();
test<volatile std::atomic_short, short>();
test<volatile std::atomic_ushort, unsigned short>();
test<volatile std::atomic_int, int>();
test<volatile std::atomic_uint, unsigned int>();
test<volatile std::atomic_long, long>();
test<volatile std::atomic_ulong, unsigned long>();
test<volatile std::atomic_llong, long long>();
test<volatile std::atomic_ullong, unsigned long long>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<volatile std::atomic_char16_t, char16_t>();
test<volatile std::atomic_char32_t, char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<volatile std::atomic_wchar_t, wchar_t>();
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// typedef atomic<char> atomic_char;
// typedef atomic<signed char> atomic_schar;
// typedef atomic<unsigned char> atomic_uchar;
// typedef atomic<short> atomic_short;
// typedef atomic<unsigned short> atomic_ushort;
// typedef atomic<int> atomic_int;
// typedef atomic<unsigned int> atomic_uint;
// typedef atomic<long> atomic_long;
// typedef atomic<unsigned long> atomic_ulong;
// typedef atomic<long long> atomic_llong;
// typedef atomic<unsigned long long> atomic_ullong;
// typedef atomic<char16_t> atomic_char16_t;
// typedef atomic<char32_t> atomic_char32_t;
// typedef atomic<wchar_t> atomic_wchar_t;
#include <atomic>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::atomic<char>, std::atomic_char>::value), "");
static_assert((std::is_same<std::atomic<signed char>, std::atomic_schar>::value), "");
static_assert((std::is_same<std::atomic<unsigned char>, std::atomic_uchar>::value), "");
static_assert((std::is_same<std::atomic<short>, std::atomic_short>::value), "");
static_assert((std::is_same<std::atomic<unsigned short>, std::atomic_ushort>::value), "");
static_assert((std::is_same<std::atomic<int>, std::atomic_int>::value), "");
static_assert((std::is_same<std::atomic<unsigned int>, std::atomic_uint>::value), "");
static_assert((std::is_same<std::atomic<long>, std::atomic_long>::value), "");
static_assert((std::is_same<std::atomic<unsigned long>, std::atomic_ulong>::value), "");
static_assert((std::is_same<std::atomic<long long>, std::atomic_llong>::value), "");
static_assert((std::is_same<std::atomic<unsigned long long>, std::atomic_ullong>::value), "");
static_assert((std::is_same<std::atomic<wchar_t>, std::atomic_wchar_t>::value), "");
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
static_assert((std::is_same<std::atomic<char16_t>, std::atomic_char16_t>::value), "");
static_assert((std::is_same<std::atomic<char32_t>, std::atomic_char32_t>::value), "");
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
}

View File

@@ -1,3 +1,4 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
@@ -7,14 +8,6 @@
//
//===----------------------------------------------------------------------===//
// <functional>
#include <functional>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}

View File

@@ -0,0 +1,13 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// bool
// atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr);
//
// template <class T>
// bool
// atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A a;
T t(T(1));
std::atomic_init(&a, t);
assert(std::atomic_compare_exchange_strong(&a, &t, T(2)) == true);
assert(a == T(2));
assert(t == T(1));
assert(std::atomic_compare_exchange_strong(&a, &t, T(3)) == false);
assert(a == T(2));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A a;
T t(T(1));
std::atomic_init(&a, t);
assert(std::atomic_compare_exchange_strong(&a, &t, T(2)) == true);
assert(a == T(2));
assert(t == T(1));
assert(std::atomic_compare_exchange_strong(&a, &t, T(3)) == false);
assert(a == T(2));
assert(t == T(3));
}
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,95 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// bool
// atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj, T* expc,
// T desr,
// memory_order s, memory_order f);
//
// template <class T>
// bool
// atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc, T desr,
// memory_order s, memory_order f);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A a;
T t(T(1));
std::atomic_init(&a, t);
assert(std::atomic_compare_exchange_strong_explicit(&a, &t, T(2),
std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
assert(a == T(2));
assert(t == T(1));
assert(std::atomic_compare_exchange_strong_explicit(&a, &t, T(3),
std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
assert(a == T(2));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A a;
T t(T(1));
std::atomic_init(&a, t);
assert(std::atomic_compare_exchange_strong_explicit(&a, &t, T(2),
std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
assert(a == T(2));
assert(t == T(1));
assert(std::atomic_compare_exchange_strong_explicit(&a, &t, T(3),
std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
assert(a == T(2));
assert(t == T(3));
}
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// bool
// atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr);
//
// template <class T>
// bool
// atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A a;
T t(T(1));
std::atomic_init(&a, t);
assert(std::atomic_compare_exchange_weak(&a, &t, T(2)) == true);
assert(a == T(2));
assert(t == T(1));
assert(std::atomic_compare_exchange_weak(&a, &t, T(3)) == false);
assert(a == T(2));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A a;
T t(T(1));
std::atomic_init(&a, t);
assert(std::atomic_compare_exchange_weak(&a, &t, T(2)) == true);
assert(a == T(2));
assert(t == T(1));
assert(std::atomic_compare_exchange_weak(&a, &t, T(3)) == false);
assert(a == T(2));
assert(t == T(3));
}
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,95 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// bool
// atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
// T desr,
// memory_order s, memory_order f);
//
// template <class T>
// bool
// atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
// memory_order s, memory_order f);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A a;
T t(T(1));
std::atomic_init(&a, t);
assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(2),
std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
assert(a == T(2));
assert(t == T(1));
assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(3),
std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
assert(a == T(2));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A a;
T t(T(1));
std::atomic_init(&a, t);
assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(2),
std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
assert(a == T(2));
assert(t == T(1));
assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(3),
std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
assert(a == T(2));
assert(t == T(3));
}
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// T
// atomic_exchange(volatile atomic<T>* obj, T desr);
//
// template <class T>
// T
// atomic_exchange(atomic<T>* obj, T desr);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_exchange(&t, T(2)) == T(1));
assert(t == T(2));
volatile A vt;
std::atomic_init(&vt, T(3));
assert(std::atomic_exchange(&vt, T(4)) == T(3));
assert(vt == T(4));
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// T
// atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m);
//
// template <class T>
// T
// atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_exchange_explicit(&t, T(2), std::memory_order_seq_cst)
== T(1));
assert(t == T(2));
volatile A vt;
std::atomic_init(&vt, T(3));
assert(std::atomic_exchange_explicit(&vt, T(4), std::memory_order_seq_cst)
== T(3));
assert(vt == T(4));
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_add(volatile atomic<Integral>* obj, Integral op);
//
// template <class Integral>
// Integral
// atomic_fetch_add(atomic<Integral>* obj, Integral op);
//
// template <class T>
// T*
// atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op);
//
// template <class T>
// T*
// atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_add(&t, T(2)) == T(1));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_add(&t, T(2)) == T(1));
assert(t == T(3));
}
}
template <class T>
void
testp()
{
{
typedef std::atomic<T> A;
typedef typename std::remove_pointer<T>::type X;
A t;
std::atomic_init(&t, T(1*sizeof(X)));
assert(std::atomic_fetch_add(&t, 2) == T(1*sizeof(X)));
assert(t == T(3*sizeof(X)));
}
{
typedef std::atomic<T> A;
typedef typename std::remove_pointer<T>::type X;
volatile A t;
std::atomic_init(&t, T(1*sizeof(X)));
assert(std::atomic_fetch_add(&t, 2) == T(1*sizeof(X)));
assert(t == T(3*sizeof(X)));
}
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
testp<int*>();
testp<const int*>();
}

View File

@@ -0,0 +1,111 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
// memory_order m);
// template <class Integral>
// Integral
// atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
// memory_order m);
// template <class T>
// T*
// atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
// memory_order m);
// template <class T>
// T*
// atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_add_explicit(&t, T(2),
std::memory_order_seq_cst) == T(1));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_add_explicit(&t, T(2),
std::memory_order_seq_cst) == T(1));
assert(t == T(3));
}
}
template <class T>
void
testp()
{
{
typedef std::atomic<T> A;
typedef typename std::remove_pointer<T>::type X;
A t;
std::atomic_init(&t, T(1*sizeof(X)));
assert(std::atomic_fetch_add_explicit(&t, 2,
std::memory_order_seq_cst) == T(1*sizeof(X)));
assert(t == T(3*sizeof(X)));
}
{
typedef std::atomic<T> A;
typedef typename std::remove_pointer<T>::type X;
volatile A t;
std::atomic_init(&t, T(1*sizeof(X)));
assert(std::atomic_fetch_add_explicit(&t, 2,
std::memory_order_seq_cst) == T(1*sizeof(X)));
assert(t == T(3*sizeof(X)));
}
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
testp<int*>();
testp<const int*>();
}

View File

@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_and(volatile atomic<Integral>* obj, Integral op);
//
// template <class Integral>
// Integral
// atomic_fetch_and(atomic<Integral>* obj, Integral op);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_and(&t, T(2)) == T(1));
assert(t == T(0));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_and(&t, T(2)) == T(3));
assert(t == T(2));
}
}
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op);
//
// template <class Integral>
// Integral
// atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_and_explicit(&t, T(2),
std::memory_order_seq_cst) == T(1));
assert(t == T(0));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_and_explicit(&t, T(2),
std::memory_order_seq_cst) == T(3));
assert(t == T(2));
}
}
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
}

View File

@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_or(volatile atomic<Integral>* obj, Integral op);
//
// template <class Integral>
// Integral
// atomic_fetch_or(atomic<Integral>* obj, Integral op);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_or(&t, T(2)) == T(1));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_or(&t, T(2)) == T(3));
assert(t == T(3));
}
}
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op);
//
// template <class Integral>
// Integral
// atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_or_explicit(&t, T(2),
std::memory_order_seq_cst) == T(1));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_or_explicit(&t, T(2),
std::memory_order_seq_cst) == T(3));
assert(t == T(3));
}
}
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
}

View File

@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op);
//
// template <class Integral>
// Integral
// atomic_fetch_sub(atomic<Integral>* obj, Integral op);
//
// template <class T>
// T*
// atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op);
//
// template <class T>
// T*
// atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_sub(&t, T(2)) == T(3));
assert(t == T(1));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_sub(&t, T(2)) == T(3));
assert(t == T(1));
}
}
template <class T>
void
testp()
{
{
typedef std::atomic<T> A;
typedef typename std::remove_pointer<T>::type X;
A t;
std::atomic_init(&t, T(3*sizeof(X)));
assert(std::atomic_fetch_sub(&t, 2) == T(3*sizeof(X)));
assert(t == T(1*sizeof(X)));
}
{
typedef std::atomic<T> A;
typedef typename std::remove_pointer<T>::type X;
volatile A t;
std::atomic_init(&t, T(3*sizeof(X)));
assert(std::atomic_fetch_sub(&t, 2) == T(3*sizeof(X)));
assert(t == T(1*sizeof(X)));
}
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
testp<int*>();
testp<const int*>();
}

View File

@@ -0,0 +1,112 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
// memory_order m);
// template <class Integral>
// Integral
// atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
// memory_order m);
//
// template <class T>
// T*
// atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
// memory_order m);
// template <class T>
// T*
// atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_sub_explicit(&t, T(2),
std::memory_order_seq_cst) == T(3));
assert(t == T(1));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_sub_explicit(&t, T(2),
std::memory_order_seq_cst) == T(3));
assert(t == T(1));
}
}
template <class T>
void
testp()
{
{
typedef std::atomic<T> A;
typedef typename std::remove_pointer<T>::type X;
A t;
std::atomic_init(&t, T(3*sizeof(X)));
assert(std::atomic_fetch_sub_explicit(&t, 2,
std::memory_order_seq_cst) == T(3*sizeof(X)));
assert(t == T(1*sizeof(X)));
}
{
typedef std::atomic<T> A;
typedef typename std::remove_pointer<T>::type X;
volatile A t;
std::atomic_init(&t, T(3*sizeof(X)));
assert(std::atomic_fetch_sub_explicit(&t, 2,
std::memory_order_seq_cst) == T(3*sizeof(X)));
assert(t == T(1*sizeof(X)));
}
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
testp<int*>();
testp<const int*>();
}

View File

@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op);
//
// template <class Integral>
// Integral
// atomic_fetch_xor(atomic<Integral>* obj, Integral op);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_xor(&t, T(2)) == T(1));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_xor(&t, T(2)) == T(3));
assert(t == T(1));
}
}
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class Integral>
// Integral
// atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op);
//
// template <class Integral>
// Integral
// atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_fetch_xor_explicit(&t, T(2),
std::memory_order_seq_cst) == T(1));
assert(t == T(3));
}
{
typedef std::atomic<T> A;
volatile A t;
std::atomic_init(&t, T(3));
assert(std::atomic_fetch_xor_explicit(&t, T(2),
std::memory_order_seq_cst) == T(3));
assert(t == T(1));
}
}
int main()
{
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
}

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// void
// atomic_init(volatile atomic<T>* obj, T desr);
//
// template <class T>
// void
// atomic_init(atomic<T>* obj, T desr);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(t == T(1));
volatile A vt;
std::atomic_init(&vt, T(2));
assert(vt == T(2));
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// bool
// atomic_is_lock_free(const volatile atomic<T>* obj);
//
// template <class T>
// bool
// atomic_is_lock_free(const atomic<T>* obj);
#include <atomic>
template <class T>
void
test()
{
typedef std::atomic<T> A;
const A ct;
bool b1 = std::atomic_is_lock_free(&ct);
const volatile A cvt;
bool b2 = std::atomic_is_lock_free(&cvt);
}
struct A
{
char _[4];
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// T
// atomic_load(const volatile atomic<T>* obj);
//
// template <class T>
// T
// atomic_load(const atomic<T>* obj);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_load(&t) == T(1));
volatile A vt;
std::atomic_init(&vt, T(2));
assert(std::atomic_load(&vt) == T(2));
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// T
// atomic_load_explicit(const volatile atomic<T>* obj, memory_order m);
//
// template <class T>
// T
// atomic_load_explicit(const atomic<T>* obj, memory_order m);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
typedef std::atomic<T> A;
A t;
std::atomic_init(&t, T(1));
assert(std::atomic_load_explicit(&t, std::memory_order_seq_cst) == T(1));
volatile A vt;
std::atomic_init(&vt, T(2));
assert(std::atomic_load_explicit(&vt, std::memory_order_seq_cst) == T(2));
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// void
// atomic_store(volatile atomic<T>* obj, T desr);
//
// template <class T>
// void
// atomic_store(atomic<T>* obj, T desr);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
typedef std::atomic<T> A;
A t;
std::atomic_store(&t, T(1));
assert(t == T(1));
volatile A vt;
std::atomic_store(&vt, T(2));
assert(vt == T(2));
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// template <class T>
// void
// atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m);
//
// template <class T>
// void
// atomic_store_explicit(atomic<T>* obj, T desr, memory_order m);
#include <atomic>
#include <cassert>
template <class T>
void
test()
{
typedef std::atomic<T> A;
A t;
std::atomic_store_explicit(&t, T(1), std::memory_order_seq_cst);
assert(t == T(1));
volatile A vt;
std::atomic_store_explicit(&vt, T(2), std::memory_order_seq_cst);
assert(vt == T(2));
}
struct A
{
int i;
explicit A(int d = 0) : i(d) {}
A(const A& a) : i(a.i) {}
A(const volatile A& a) : i(a.i) {}
void operator=(const volatile A& a) volatile {i = a.i;}
friend bool operator==(const A& x, const A& y)
{return x.i == y.i;}
};
int main()
{
test<A>();
test<char>();
test<signed char>();
test<unsigned char>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
test<wchar_t>();
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
test<char16_t>();
test<char32_t>();
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
test<int*>();
test<const int*>();
}

View File

@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// #define ATOMIC_VAR_INIT(value)
#include <atomic>
#include <cassert>
int main()
{
std::atomic<int> v = ATOMIC_VAR_INIT(5);
assert(v == 5);
}

View File

@@ -0,0 +1,13 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,13 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template <class Arg1, class Arg2, class Result>
// struct binary_function
// {
// typedef Arg1 first_argument_type;
// typedef Arg2 second_argument_type;
// typedef Result result_type;
// };
#include <functional>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::binary_function<int, unsigned, char>::first_argument_type, int>::value), "");
static_assert((std::is_same<std::binary_function<int, unsigned, char>::second_argument_type, unsigned>::value), "");
static_assert((std::is_same<std::binary_function<int, unsigned, char>::result_type, char>::value), "");
}

View File

@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// template <class Arg, class Result>
// struct unary_function
// {
// typedef Arg argument_type;
// typedef Result result_type;
// };
#include <functional>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::unary_function<unsigned, char>::argument_type, unsigned>::value), "");
static_assert((std::is_same<std::unary_function<unsigned, char>::result_type, char>::value), "");
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// class match_results<BidirectionalIterator, Allocator>
// bool ready() const;
#include <regex>
#include <cassert>
void
test1()
{
std::match_results<const char*> m;
const char s[] = "abcdefghijk";
assert(m.ready() == false);
std::regex_search(s, m, std::regex("cd((e)fg)hi"));
assert(m.ready() == true);
}
void
test2()
{
std::match_results<const char*> m;
const char s[] = "abcdefghijk";
assert(m.ready() == false);
std::regex_search(s, m, std::regex("z"));
assert(m.ready() == true);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// template <class BidirectionalIterator> class sub_match;
// constexpr sub_match();
#include <regex>
#include <cassert>
int main()
{
{
typedef char CharT;
typedef std::sub_match<const CharT*> SM;
SM sm;
assert(sm.matched == false);
}
{
typedef wchar_t CharT;
typedef std::sub_match<const CharT*> SM;
SM sm;
assert(sm.matched == false);
}
}