[libcxx-commits] [libcxx] [libc++] Add a thread-safe version of std::lgamma in the dylib (PR #153631)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 18 05:19:42 PST 2025


================
@@ -57,6 +57,31 @@ inline _LIBCPP_HIDE_FROM_ABI double tgamma(_A1 __x) _NOEXCEPT {
 
 } // namespace __math
 
+// __lgamma_r
+
+struct __lgamma_result {
+  double __result;
+  int __sign;
+};
+
+#if _LIBCPP_AVAILABILITY_HAS_THREAD_SAFE_LGAMMA
+_LIBCPP_EXPORTED_FROM_ABI __lgamma_result __lgamma_thread_safe_impl(double) _NOEXCEPT;
+
+inline _LIBCPP_HIDE_FROM_ABI __lgamma_result __lgamma_thread_safe(double __d) _NOEXCEPT {
+  return std::__lgamma_thread_safe_impl(__d);
+}
+#else
+// When deploying to older targets, call `lgamma_r` directly but avoid declaring the actual
+// function since different platforms declare the function slightly differently.
+double __lgamma_r_shim(double, int*) _NOEXCEPT __asm__("lgamma_r");
----------------
philnik777 wrote:

```suggestion
double __lgamma_r_shim(double, int*) _NOEXCEPT __asm__("_lgamma_r");
```
I think `__asm__` ignores that on Apple platforms an underscore is prepended to all functions, so this has to be added manually.

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


More information about the libcxx-commits mailing list