From d27b61e88e0980ef0d22fed0780fe7d928b55d34 Mon Sep 17 00:00:00 2001 From: LLVM Packaging Team Date: Thu, 16 Jun 2022 11:00:08 +0100 Subject: [PATCH] libcxx-test-fix-lockfree-test-for-i386 Lock is_always_lock free test fails on i386 because std::atomic is aligned Lock is_always_lock free test fails on i386 because std::atomic is aligned to 8 bytes while long long is aligned to 4 bytes. clang can't generate inline code for unaligned 8 byte atomics even tough instruction set and gcc support it. That makes it expected thaqt ATOMIC_LLONG_LOCK_FREE and std::atomic::is_always_lock_free don't match on i386. Correct test for std::atomic is to check if target cpu support cmpxchg8 instruction. To set instruction support one can check __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 define. Bug: https://llvm.org/bugs/show_bug.cgi?id=19355 Gbp-Pq: Topic libcxx Gbp-Pq: Name libcxx-test-fix-lockfree-test-for-i386.patch --- .../atomics/atomics.lockfree/isalwayslockfree.pass.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp b/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp index d9ec69eebb..001949c8c8 100644 --- a/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp +++ b/libcxx/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp @@ -21,6 +21,14 @@ # error Feature test macro missing. #endif +#if defined(__i386__) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) +/* Fix for clang setting __GCC_ATOMIC_LLONG_LOCK_FREE incorecctly for x86 + * https://llvm.org/bugs/show_bug.cgi?id=19355 + */ +#undef ATOMIC_LLONG_LOCK_FREE +#define ATOMIC_LLONG_LOCK_FREE 2 +#endif + template void checkAlwaysLockFree() { if (std::atomic::is_always_lock_free) assert(std::atomic().is_lock_free()); -- 2.30.2