Skip to content

Commit

Permalink
Expand std::atomic feature tests to include compare_exchange, fetch_a…
Browse files Browse the repository at this point in the history
…dd, etc.

E.g. clang 18 with libstdc++ 14 can do loads and stores of 128-bit atomics without libatomic, but
can't do compare_exchange without libatomic. libatomic does not seem to support 128-bit
fetch_add/sub, but we don't need it so leave it out of the 128-bit feature test.
  • Loading branch information
msimberg committed Nov 4, 2024
1 parent 5646a76 commit 04f9d59
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
29 changes: 27 additions & 2 deletions cmake/tests/cxx11_std_atomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,34 @@ template <typename T>
void test_atomic()
{
std::atomic<T> a;

a.store(T{});
T i = a.load();
(void) i;

{
[[maybe_unused]] T i = a.load();

Check notice on line 20 in cmake/tests/cxx11_std_atomic.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cmake/tests/cxx11_std_atomic.cpp#L20

Variable 'i' is assigned a value that is never used.
}

{
[[maybe_unused]] T i = a.exchange(T{});

Check notice on line 24 in cmake/tests/cxx11_std_atomic.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cmake/tests/cxx11_std_atomic.cpp#L24

Variable 'i' is assigned a value that is never used.
}

{
T expected{};
[[maybe_unused]] bool b = a.compare_exchange_weak(expected, T{});
}

{
T expected{};
[[maybe_unused]] bool b = a.compare_exchange_strong(expected, T{});
}

{
[[maybe_unused]] T i = a.fetch_sub(T{1});

Check notice on line 38 in cmake/tests/cxx11_std_atomic.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cmake/tests/cxx11_std_atomic.cpp#L38

Variable 'i' is assigned a value that is never used.
}

{
[[maybe_unused]] T i = a.fetch_add(T{1});

Check notice on line 42 in cmake/tests/cxx11_std_atomic.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cmake/tests/cxx11_std_atomic.cpp#L42

Variable 'i' is assigned a value that is never used.
}
}

int main()
Expand Down
21 changes: 19 additions & 2 deletions cmake/tests/cxx11_std_atomic_128bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,26 @@ template <typename T>
void test_atomic()
{
std::atomic<T> a;

a.store(T{});
T i = a.load();
(void) i;

{
[[maybe_unused]] T i = a.load();

Check notice on line 20 in cmake/tests/cxx11_std_atomic_128bit.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cmake/tests/cxx11_std_atomic_128bit.cpp#L20

Variable 'i' is assigned a value that is never used.
}

{
[[maybe_unused]] T i = a.exchange(T{});

Check notice on line 24 in cmake/tests/cxx11_std_atomic_128bit.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

cmake/tests/cxx11_std_atomic_128bit.cpp#L24

Variable 'i' is assigned a value that is never used.
}

{
T expected{};
[[maybe_unused]] bool b = a.compare_exchange_weak(expected, T{});
}

{
T expected{};
[[maybe_unused]] bool b = a.compare_exchange_strong(expected, T{});
}
}

struct uint128_type
Expand Down

0 comments on commit 04f9d59

Please sign in to comment.