diff options
| author | Howard Hinnant <hhinnant@apple.com> | 2010-12-07 20:46:14 +0000 |
|---|---|---|
| committer | Howard Hinnant <hhinnant@apple.com> | 2010-12-07 20:46:14 +0000 |
| commit | c772a620960748ffb42a91428171009910157ac8 (patch) | |
| tree | 39bff7613f2a393ffbd6c34bfea4397c5a5199a7 /libcxx/test | |
| parent | f878e62a0deeab9a9a59d1df35351bf6fde0fbf5 (diff) | |
| download | bcm5719-llvm-c772a620960748ffb42a91428171009910157ac8.tar.gz bcm5719-llvm-c772a620960748ffb42a91428171009910157ac8.zip | |
Work on <atomic> continues. The file size is actually sane now...
llvm-svn: 121181
Diffstat (limited to 'libcxx/test')
10 files changed, 809 insertions, 0 deletions
diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp new file mode 100644 index 00000000000..4b1a491bbcd --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp @@ -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*>(); +} diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp new file mode 100644 index 00000000000..ce960945c3b --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp @@ -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*>(); +} diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp new file mode 100644 index 00000000000..a62335c8940 --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp @@ -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 +} diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and_explicit.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and_explicit.pass.cpp new file mode 100644 index 00000000000..87f091b3dc7 --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and_explicit.pass.cpp @@ -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 +} diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or.pass.cpp new file mode 100644 index 00000000000..8a931e9e14e --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or.pass.cpp @@ -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 +} diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or_explicit.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or_explicit.pass.cpp new file mode 100644 index 00000000000..fbd5700fec7 --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or_explicit.pass.cpp @@ -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 +} diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp new file mode 100644 index 00000000000..27086a51e17 --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp @@ -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*>(); +} diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp new file mode 100644 index 00000000000..62128f32d63 --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp @@ -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*>(); +} diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor.pass.cpp new file mode 100644 index 00000000000..118f04820a2 --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor.pass.cpp @@ -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 +} diff --git a/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor_explicit.pass.cpp b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor_explicit.pass.cpp new file mode 100644 index 00000000000..6e542771861 --- /dev/null +++ b/libcxx/test/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor_explicit.pass.cpp @@ -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 +} |

