[libcxx-commits] [libcxx] [libc++] Avoid redeclaring lgamma_r (PR #153631)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 4 10:11:21 PDT 2025


philnik777 wrote:

> @philnik777 I was going to go down the route of adding `__lgamma_r` to `libc++.dylib` and dancing around back-deployment, but then I found out that GCC provides `__builtin_lgamma_r` while Clang doesn't: https://godbolt.org/z/4jWrWzf6n
> 
> We [already provide](https://github.com/llvm/llvm-project/blob/e90ab31024a7ad906db45e229fdb0f2fda7b2107/libcxx/include/__math/gamma.h#L26) definitions for `std::lgamma` in our headers and those forward to the compiler builtins. It would feel a bit silly to add an indirection through the dylib to implement `__lgamma_r` when Clang just seems to be missing a builtin (which would increase GCC compatibility).
> 
> Do you agree that requesting a Clang builtin seems like the better approach? Then we would simply use the builtin from here unconditionally.

I don't think that's the right approach. Adding a builtin is basically just having `double __builtin_lgamma_r(double, int*) __asm__("lgamma_r")` in the compiler. At that point we might as well just do that ourselves instead of asking for a builtin they have to maintain forever across all platforms. I'm pretty much only comfortable with using the other math builtins because they already exist. I wouldn't ever want to ask for another one of them.

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


More information about the libcxx-commits mailing list