Skip to content

Commit 1bfc10f

Browse files
committed
Cleanup and format tests.
1 parent 5394683 commit 1bfc10f

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

libcxx/test/std/atomics/atomics.ref/is_always_lock_free.pass.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,20 @@
2020
#include "test_macros.h"
2121
#include "atomic_helpers.h"
2222

23-
2423
template <typename T>
25-
void check_always_lock_free_subsumes_is_lock_free(std::atomic_ref<T> const a) {
24+
void check_always_lock_free(std::atomic_ref<T> const& a) {
2625
if (is_lock_free_status_known<T>()) {
27-
constexpr LockFreeStatus known_status = get_known_atomic_lock_free_status<T>();
28-
29-
static_assert(std::atomic_ref<T>::is_always_lock_free == (known_status == LockFreeStatus::always),
30-
"is_always_lock_free is inconsistent with known lock-free status");
31-
if (known_status == LockFreeStatus::always) {
32-
assert(a.is_lock_free() && "is_lock_free() is inconsistent with known lock-free status");
33-
} else if (known_status == LockFreeStatus::never) {
34-
assert(!a.is_lock_free() && "is_lock_free() is inconsistent with known lock-free status");
35-
} else {
36-
assert(a.is_lock_free() || !a.is_lock_free()); // This is kinda dumb, but we might as well call the function once.
37-
}
38-
26+
constexpr LockFreeStatus known_status = get_known_atomic_lock_free_status<T>();
27+
28+
static_assert(std::atomic_ref<T>::is_always_lock_free == (known_status == LockFreeStatus::always),
29+
"is_always_lock_free is inconsistent with known lock-free status");
30+
if (known_status == LockFreeStatus::always) {
31+
assert(a.is_lock_free() && "is_lock_free() is inconsistent with known lock-free status");
32+
} else if (known_status == LockFreeStatus::never) {
33+
assert(!a.is_lock_free() && "is_lock_free() is inconsistent with known lock-free status");
34+
} else {
35+
assert(a.is_lock_free() || !a.is_lock_free()); // This is kinda dumb, but we might as well call the function once.
36+
}
3937
}
4038
std::same_as<const bool> decltype(auto) is_always_lock_free = std::atomic_ref<T>::is_always_lock_free;
4139
if (is_always_lock_free) {
@@ -49,11 +47,10 @@ void check_always_lock_free_subsumes_is_lock_free(std::atomic_ref<T> const a) {
4947
do { \
5048
typedef T type; \
5149
type obj{}; \
52-
check_always_lock_free_subsumes_is_lock_free(std::atomic_ref<type>(obj)); \
50+
check_always_lock_free(std::atomic_ref<type>(obj)); \
5351
} while (0)
5452

5553
void check_always_lock_free_types() {
56-
5754
static_assert(std::atomic_ref<int>::is_always_lock_free);
5855
static_assert(std::atomic_ref<char>::is_always_lock_free);
5956
}
@@ -65,13 +62,13 @@ void test() {
6562
check_always_lock_free_types();
6663

6764
int i = 0;
68-
check_always_lock_free_subsumes_is_lock_free(std::atomic_ref<int>(i));
65+
check_always_lock_free(std::atomic_ref<int>(i));
6966

7067
float f = 0.f;
71-
check_always_lock_free_subsumes_is_lock_free(std::atomic_ref<float>(f));
68+
check_always_lock_free(std::atomic_ref<float>(f));
7269

7370
int* p = &i;
74-
check_always_lock_free_subsumes_is_lock_free(std::atomic_ref<int*>(p));
71+
check_always_lock_free(std::atomic_ref<int*>(p));
7572

7673
CHECK_ALWAYS_LOCK_FREE(struct Empty{});
7774
CHECK_ALWAYS_LOCK_FREE(struct OneInt { int i; });

libcxx/test/support/atomic_helpers.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,22 @@ constexpr bool msvc_is_lock_free_macro_value() {
5050
# error "Unknown compiler"
5151
#endif
5252
enum class LockFreeStatus { unknown = -1, never = 0, sometimes = 1, always = 2 };
53-
#define COMPARE_TYPES(T1, T2) \
54-
(sizeof(T1) == sizeof(T2) && alignof(T1) >= alignof(T2))
53+
#define COMPARE_TYPES(T1, T2) (sizeof(T1) == sizeof(T2) && alignof(T1) >= alignof(T2))
5554

5655
template <class T>
5756
constexpr inline LockFreeStatus get_known_atomic_lock_free_status() {
58-
return LockFreeStatus{COMPARE_TYPES(T, char)
59-
? TEST_ATOMIC_CHAR_LOCK_FREE
60-
: (COMPARE_TYPES(T, short)
61-
? TEST_ATOMIC_SHORT_LOCK_FREE
62-
: (COMPARE_TYPES(T, int)
63-
? TEST_ATOMIC_INT_LOCK_FREE
64-
: (COMPARE_TYPES(T, long)
65-
? TEST_ATOMIC_LONG_LOCK_FREE
66-
: (COMPARE_TYPES(T, long long)
67-
? TEST_ATOMIC_LLONG_LOCK_FREE
68-
: (COMPARE_TYPES(T, void*) ? TEST_ATOMIC_POINTER_LOCK_FREE
69-
: -1)))))};
57+
return LockFreeStatus{
58+
COMPARE_TYPES(T, char)
59+
? TEST_ATOMIC_CHAR_LOCK_FREE
60+
: (COMPARE_TYPES(T, short)
61+
? TEST_ATOMIC_SHORT_LOCK_FREE
62+
: (COMPARE_TYPES(T, int)
63+
? TEST_ATOMIC_INT_LOCK_FREE
64+
: (COMPARE_TYPES(T, long)
65+
? TEST_ATOMIC_LONG_LOCK_FREE
66+
: (COMPARE_TYPES(T, long long)
67+
? TEST_ATOMIC_LLONG_LOCK_FREE
68+
: (COMPARE_TYPES(T, void*) ? TEST_ATOMIC_POINTER_LOCK_FREE : -1)))))};
7069
}
7170

7271
template <class T>
@@ -81,7 +80,6 @@ static_assert(is_lock_free_status_known<long>(), "");
8180
static_assert(is_lock_free_status_known<long long>(), "");
8281
static_assert(is_lock_free_status_known<void*>(), "");
8382

84-
8583
// These macros are somewhat suprising to use, since they take the values 0, 1, or 2.
8684
// To make the tests clearer, get rid of them in preference of AtomicInfo.
8785
#undef TEST_ATOMIC_CHAR_LOCK_FREE

0 commit comments

Comments
 (0)