[libcxx-commits] [libcxx] [libc++][In progress] Floating Point Atomic (PR #67799)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 2 08:59:18 PDT 2023


================
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+//   static constexpr bool is_always_lock_free = implementation-defined;
+//   bool is_lock_free() const volatile noexcept;
+//   bool is_lock_free() const noexcept;
+
+#include <atomic>
+#include <cassert>
+#include <concepts>
+
+#include "test_macros.h"
+
+template <class T>
+concept isLockFreeNoexcept = requires(T t) {
+  { t.is_lock_free() } noexcept;
+};
+
+template <class T>
+void test() {
+  static_assert(isLockFreeNoexcept<const std::atomic<T>>);
+  static_assert(isLockFreeNoexcept<const volatile std::atomic<T>>);
+
+  //   static constexpr bool is_always_lock_free = implementation-defined;
+  { [[maybe_unused]] constexpr std::same_as<const bool> decltype(auto) r = std::atomic<T>::is_always_lock_free; }
----------------
ldionne wrote:

Right now we're not testing the actual value of `is_lock_free`, but I think it would be useful to check it.

I can see 3 approaches:
1. Hardcode the result we expect for a few platforms / architectures, like x86_64, arm64, etc..
2. Test that the value matches the value of the compiler builtins `__atomic_is_lock_free` and `__atomic_is_always_lock_free`
3. Test that `atomic<FloatingPoint>::is_lock_free` matches `atomic<Integral>::is_lock_free` when their sizes match.

Any of these approaches would improve the coverage in a "portable" way, in the sense that the tests would pass everywhere (but option (1)) would give us added coverage only on some platforms.

https://github.com/llvm/llvm-project/pull/67799


More information about the libcxx-commits mailing list