From cc859306f499cc0438d3df3baf22fec5055bb38e Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 10 Jul 2017 04:16:50 +0000 Subject: Work around PR31864 - ATOMIC_LLONG_LOCK_FREE is incorrect in 32 bit builds llvm-svn: 307517 --- .../atomics.lockfree/isalwayslockfree.pass.cpp | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'libcxx/test') diff --git a/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp b/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp index e42e9f28448..7a4090b9c25 100644 --- a/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp +++ b/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp @@ -25,6 +25,40 @@ template void checkAlwaysLockFree() { assert(std::atomic().is_lock_free()); } +// FIXME: This separate test is needed to work around llvm.org/PR31864 +// which causes ATOMIC_LLONG_LOCK_FREE to be defined as '1' in 32-bit builds +// even though __atomic_always_lock_free returns true for the same type. +constexpr bool NeedWorkaroundForPR31864 = +#if defined(__clang__) +(sizeof(void*) == 4); // Needed on 32 bit builds +#else +false; +#endif + +template * = nullptr, + class LLong = long long, + class ULLong = unsigned long long> +void checkLongLongTypes() { + static_assert(std::atomic::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE)); + static_assert(std::atomic::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE)); +} + +// Used to make the calls to __atomic_always_lock_free dependent on a template +// parameter. +template constexpr size_t getSizeOf() { return sizeof(T); } + +template * = nullptr, + class LLong = long long, + class ULLong = unsigned long long> +void checkLongLongTypes() { + constexpr bool ExpectLockFree = __atomic_always_lock_free(getSizeOf(), 0); + static_assert(std::atomic::is_always_lock_free == ExpectLockFree, ""); + static_assert(std::atomic::is_always_lock_free == ExpectLockFree, ""); + static_assert((0 != ATOMIC_LLONG_LOCK_FREE) == ExpectLockFree, ""); +} + int main() { // structs and unions can't be defined in the template invocation. @@ -94,8 +128,7 @@ int main() static_assert(std::atomic::is_always_lock_free == (2 == ATOMIC_INT_LOCK_FREE)); static_assert(std::atomic::is_always_lock_free == (2 == ATOMIC_LONG_LOCK_FREE)); static_assert(std::atomic::is_always_lock_free == (2 == ATOMIC_LONG_LOCK_FREE)); - static_assert(std::atomic::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE)); - static_assert(std::atomic::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE)); + checkLongLongTypes(); static_assert(std::atomic::is_always_lock_free == (2 == ATOMIC_POINTER_LOCK_FREE)); static_assert(std::atomic::is_always_lock_free == (2 == ATOMIC_POINTER_LOCK_FREE)); } -- cgit v1.2.3