Skip to content

Commit

Permalink
[libc++] Workaround linker errors in floating-point atomic tests (#73398
Browse files Browse the repository at this point in the history
)

We now add -latomic whenever we detect that it's supported on the platform,
and we mark the tests as UNSUPPORTED on platforms where non-lockfree
atomics are not supported.
  • Loading branch information
huixie90 authored Nov 30, 2023
1 parent 78237b7 commit 6677f02
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// static constexpr bool is_always_lock_free = implementation-defined;
// bool is_lock_free() const volatile noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// floating-point-type operator=(floating-point-type) volatile noexcept;
// floating-point-type operator=(floating-point-type) noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// bool compare_exchange_strong(T& expected, T desired,
// memory_order success, memory_order failure) volatile noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// bool compare_exchange_weak(T& expected, T desired,
// memory_order success, memory_order failure) volatile noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// constexpr atomic() noexcept;
// constexpr atomic(floating-point-type) noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// Clang's support for atomic operations on long double is broken. See https://github.com/llvm/llvm-project/issues/72893
// XFAIL: tsan
// XFAIL: target={{x86_64-.*}} && tsan
// XFAIL: target={{x86_64-.*}} && msan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// T exchange(T, memory_order = memory_order::seq_cst) volatile noexcept;
// T exchange(T, memory_order = memory_order::seq_cst) noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// XFAIL: LIBCXX-AIX-FIXME
// UNSUPPORTED: LIBCXX-AIX-FIXME
// Clang's support for atomic operations on long double is broken. See https://github.com/llvm/llvm-project/issues/72893
// XFAIL: tsan
// XFAIL: target={{x86_64-.*}} && tsan
// Hangs with msan.
// UNSUPPORTED: msan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// floating-point-type fetch_add(floating-point-type,
// memory_order = memory_order::seq_cst) volatile noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// XFAIL: LIBCXX-AIX-FIXME
// UNSUPPORTED: LIBCXX-AIX-FIXME
// Clang's support for atomic operations on long double is broken. See https://github.com/llvm/llvm-project/issues/72893
// XFAIL: tsan
// XFAIL: target={{x86_64-.*}} && tsan
// Hangs with msan.
// UNSUPPORTED: msan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// floating-point-type fetch_sub(floating-point-type,
// memory_order = memory_order::seq_cst) volatile noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// Clang's support for atomic operations on long double is broken. See https://github.com/llvm/llvm-project/issues/72893
// XFAIL: tsan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// XFAIL: target={{x86_64-.*}} && tsan
// UNSUPPORTED: !non-lockfree-atomics

// floating-point-type load(memory_order = memory_order::seq_cst) volatile noexcept;
// floating-point-type load(memory_order = memory_order::seq_cst) noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// static constexpr bool is_always_lock_free = implementation-defined;
// bool is_lock_free() const volatile noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// UNSUPPORTED: no-threads
// XFAIL: availability-synchronization_library-missing
// UNSUPPORTED: c++03, c++11, c++14, c++17
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// void notify_all() volatile noexcept;
// void notify_all() noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// UNSUPPORTED: no-threads
// XFAIL: availability-synchronization_library-missing
// UNSUPPORTED: c++03, c++11, c++14, c++17
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// void notify_one() volatile noexcept;
// void notify_one() noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// operator floating-point-type() volatile noexcept;
// operator floating-point-type() noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// XFAIL: LIBCXX-AIX-FIXME
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: LIBCXX-AIX-FIXME
// UNSUPPORTED: !non-lockfree-atomics
// Hangs with msan.
// UNSUPPORTED: msan

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: target={{.+}}-windows-gnu
// XFAIL: LIBCXX-AIX-FIXME
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: LIBCXX-AIX-FIXME
// UNSUPPORTED: !non-lockfree-atomics
// Hangs with msan.
// UNSUPPORTED: msan

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// Clang's support for atomic operations on long double is broken. See https://github.com/llvm/llvm-project/issues/72893
// XFAIL: tsan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// XFAIL: target={{x86_64-.*}} && tsan
// UNSUPPORTED: !non-lockfree-atomics

// void store(floating-point-type, memory_order = memory_order::seq_cst) volatile noexcept;
// void store(floating-point-type, memory_order = memory_order::seq_cst) noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// XFAIL: availability-synchronization_library-missing
// Clang's support for atomic operations on long double is broken. See https://github.com/llvm/llvm-project/issues/72893
// XFAIL: tsan
// XFAIL: target={{x86_64-.*}} && tsan
// XFAIL: target={{x86_64-.*}} && msan
// ADDITIONAL_COMPILE_FLAGS(has-latomic): -latomic
// XFAIL: !has-64-bit-atomics
// UNSUPPORTED: !non-lockfree-atomics

// void wait(T old, memory_order order = memory_order::seq_cst) const volatile noexcept;
// void wait(T old, memory_order order = memory_order::seq_cst) const noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ struct TestFn {
A a(T(1));
static_assert(noexcept(std::atomic_notify_all(&a)), "");

std::atomic<bool> is_ready[2] = {false, false};
auto f = [&](int index) {
std::atomic<bool> is_ready[2];
is_ready[0] = false;
is_ready[1] = false;
auto f = [&](int index) {
assert(std::atomic_load(&a) == T(1));
is_ready[index].store(true);

Expand All @@ -63,8 +65,10 @@ struct TestFn {
volatile A a(T(2));
static_assert(noexcept(std::atomic_notify_all(&a)), "");

std::atomic<bool> is_ready[2] = {false, false};
auto f = [&](int index) {
std::atomic<bool> is_ready[2];
is_ready[0] = false;
is_ready[1] = false;
auto f = [&](int index) {
assert(std::atomic_load(&a) == T(2));
is_ready[index].store(true);

Expand Down
9 changes: 3 additions & 6 deletions libcxx/utils/libcxx/test/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,11 @@ def _getAndroidDeviceApi(cfg):
when=lambda cfg: hasCompileFlag(cfg, "-Xclang -verify-ignore-unexpected"),
),
Feature(
name="has-latomic",
name="add-latomic-workaround", # https://github.com/llvm/llvm-project/issues/73361
when=lambda cfg: sourceBuilds(
cfg,
"""
int main(int, char**) { return 0; }
""",
["-latomic"],
cfg, "int main(int, char**) { return 0; }", ["-latomic"]
),
actions=[AddLinkFlag("-latomic")],
),
Feature(
name="non-lockfree-atomics",
Expand Down

0 comments on commit 6677f02

Please sign in to comment.