[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-21 Thread via cfe-commits

lntue wrote:

> I think the `errno` change should be extracted into a separate PR since 
> that's related to libc internals and would make the actual change much 
> smaller and easier to review.

Yes, I do plan to split the commits into their own PRs.  But probably I should 
go ahead and do the libc_errno refactoring first to reduce the noise for this 
proof-of-concept PR.

https://github.com/llvm/llvm-project/pull/140841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-21 Thread via cfe-commits

https://github.com/lntue edited https://github.com/llvm/llvm-project/pull/140841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-21 Thread Alexey Samsonov via cfe-commits


@@ -33,7 +33,7 @@ to learn about the defaults for your platform and target.
 * **"general" options**
 - ``LIBC_ADD_NULL_CHECKS``: Add nullptr checks in the library's 
implementations to some functions for which passing nullptr is undefined 
behavior.
 * **"math" options**
-- ``LIBC_CONF_FREXP_INF_NAN_EXPONENT``: The value written back to the 
second parameter when calling frexp/frexpf/frexpl` with `+/-Inf`/`NaN` is 
unspecified.  Configure an explicit exp value for Inf/NaN inputs.
+- ``LIBC_CONF_FREXP_INF_NAN_EXPONENT``: The value written back to the 
second parameter when calling frexp/frexpf/frexpl` with `+/-Inf`/`NaN` is 
unspecified.  Configue an explicit exp value for Inf/NaN inputs.

vonosmas wrote:

Does this reverts a landed fix to docs?

https://github.com/llvm/llvm-project/pull/140841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-20 Thread Petr Hosek via cfe-commits

petrhosek wrote:

I think the `errno` change should be extracted into a separate PR since that's 
related to libc internals and would make the actual change much smaller and 
easier to review.

https://github.com/llvm/llvm-project/pull/140841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-20 Thread Alexey Samsonov via cfe-commits


@@ -0,0 +1,22 @@
+//===-- Floating point math functions ---*- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_H
+#define LLVM_LIBC_SHARED_MATH_H
+
+#include "src/__support/math/expf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::expf;

vonosmas wrote:

I wonder if there's any value in having a per-function (or per-function-group) 
header? E.g. `libc/shared/math/exp.h` . Otherwise the user who wants to use 
just one function will include header with all of them, potentially pulling in 
a bunch of deps they don't want (or won't work on their system).

https://github.com/llvm/llvm-project/pull/140841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-20 Thread Alexey Samsonov via cfe-commits


@@ -83,14 +45,11 @@ Errno::operator int() { return shared_errno; }
 void Errno::operator=(int a) { *__llvm_libc_errno() = a; }
 Errno::operator int() { return *__llvm_libc_errno(); }
 
-#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_SYSTEM

vonosmas wrote:

I think it may be cleaner to add this elif in place, and just leave nothing 
inside, with a comment that in this case the implementation is provided by 
support header.

https://github.com/llvm/llvm-project/pull/140841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-20 Thread Alexey Samsonov via cfe-commits


@@ -117,7 +117,7 @@ followed:
`ErrorOr 
`_
to return error values.
 
-#. The header file ``src/errno/libc_errno.h`` is shipped as part of the target
+#. The header file ``src/__support/libc_errno.h`` is shipped as part of the 
target

vonosmas wrote:

Should this bullet point be revisited? I think that if we're using system 
errno, targets no longer need to depend on errno. For full-build, conversely, 
system errno shouldn't be feasible?

https://github.com/llvm/llvm-project/pull/140841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (lntue)


Changes

A draft PR to make `__builtin_expf` constexpr using LLVM libc math 
implementation.

---

Patch is 244.33 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/140841.diff


429 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+16-2) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+22) 
- (modified) clang/lib/AST/ExprConstant.cpp (+19) 
- (modified) clang/test/CMakeLists.txt (+1) 
- (modified) clang/test/Preprocessor/feature_tests.cpp (+10) 
- (added) clang/test/Sema/constant-builtins-exp.cpp (+12) 
- (modified) clang/test/lit.cfg.py (+3) 
- (modified) clang/test/lit.site.cfg.py.in (+1) 
- (modified) libc/cmake/modules/LLVMLibCCompileOptionRules.cmake (+4) 
- (modified) libc/cmake/modules/LLVMLibCTestRules.cmake (+3-1) 
- (modified) libc/docs/configure.rst (+1-1) 
- (modified) libc/docs/dev/code_style.rst (+2-2) 
- (added) libc/shared/math.h (+22) 
- (modified) libc/src/__support/CMakeLists.txt (+2) 
- (modified) libc/src/__support/FPUtil/FEnvImpl.h (+1-1) 
- (modified) libc/src/__support/File/dir.cpp (+1-1) 
- (modified) libc/src/__support/File/file.cpp (+1-1) 
- (modified) libc/src/__support/File/linux/file.cpp (+1-1) 
- (modified) libc/src/__support/File/linux/lseekImpl.h (+1-1) 
- (modified) libc/src/__support/HashTable/randomness.h (+1-1) 
- (modified) libc/src/__support/OSUtil/linux/fcntl.cpp (+1-1) 
- (modified) libc/src/__support/OSUtil/linux/vdso.cpp (+1-1) 
- (modified) libc/src/__support/StringUtil/tables/linux_extension_errors.h 
(+1-1) 
- (added) libc/src/__support/libc_errno.h (+93) 
- (added) libc/src/__support/math/CMakeLists.txt () 
- (added) libc/src/__support/math/exp_float_constants.h (+145) 
- (added) libc/src/__support/math/expf.h (+116) 
- (modified) libc/src/__support/threads/linux/thread.cpp (+1-1) 
- (modified) libc/src/dirent/closedir.cpp (+1-1) 
- (modified) libc/src/dirent/opendir.cpp (+1-1) 
- (modified) libc/src/dirent/readdir.cpp (+1-1) 
- (modified) libc/src/errno/CMakeLists.txt (-15) 
- (modified) libc/src/errno/libc_errno.cpp (+5-46) 
- (removed) libc/src/errno/libc_errno.h (-47) 
- (modified) libc/src/fcntl/linux/creat.cpp (+1-1) 
- (modified) libc/src/fcntl/linux/open.cpp (+1-1) 
- (modified) libc/src/fcntl/linux/openat.cpp (+1-1) 
- (modified) libc/src/inttypes/strtoimax.cpp (+1-1) 
- (modified) libc/src/inttypes/strtoumax.cpp (+1-1) 
- (modified) libc/src/math/generic/exp10m1f.cpp (+1-1) 
- (modified) libc/src/math/generic/exp2m1f.cpp (+1-1) 
- (modified) libc/src/math/generic/expf.cpp (+2-95) 
- (modified) libc/src/math/generic/nan.cpp (+1-1) 
- (modified) libc/src/math/generic/nanf.cpp (+1-1) 
- (modified) libc/src/math/generic/nanf128.cpp (+1-1) 
- (modified) libc/src/math/generic/nanf16.cpp (+1-1) 
- (modified) libc/src/math/generic/nanl.cpp (+1-1) 
- (modified) libc/src/poll/linux/poll.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_atfork.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_attr_setdetachstate.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_attr_setguardsize.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_attr_setstack.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_attr_setstacksize.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_condattr_setclock.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_condattr_setpshared.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_create.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_key_create.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_key_delete.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_mutexattr_setpshared.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_mutexattr_setrobust.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_mutexattr_settype.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlock_timedrdlock.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlock_trywrlock.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlock_unlock.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlockattr_setkind_np.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlockattr_setpshared.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_setspecific.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_get_priority_max.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_get_priority_min.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_getaffinity.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_getparam.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_getscheduler.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_rr_get_interval.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_setaffinity.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_setparam.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_setscheduler.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_yield.cpp (+1-1) 
- (modified) libc/src/search/hcreate.cpp (+1-1) 
- (modified) libc/src/search/hcreate_r.cpp (+1-1) 
- (modified) libc/src/search/hdestroy_r.cpp (+1-1) 
- (modi

[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libc

Author: None (lntue)


Changes

A draft PR to make `__builtin_expf` constexpr using LLVM libc math 
implementation.

---

Patch is 244.33 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/140841.diff


429 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+16-2) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+22) 
- (modified) clang/lib/AST/ExprConstant.cpp (+19) 
- (modified) clang/test/CMakeLists.txt (+1) 
- (modified) clang/test/Preprocessor/feature_tests.cpp (+10) 
- (added) clang/test/Sema/constant-builtins-exp.cpp (+12) 
- (modified) clang/test/lit.cfg.py (+3) 
- (modified) clang/test/lit.site.cfg.py.in (+1) 
- (modified) libc/cmake/modules/LLVMLibCCompileOptionRules.cmake (+4) 
- (modified) libc/cmake/modules/LLVMLibCTestRules.cmake (+3-1) 
- (modified) libc/docs/configure.rst (+1-1) 
- (modified) libc/docs/dev/code_style.rst (+2-2) 
- (added) libc/shared/math.h (+22) 
- (modified) libc/src/__support/CMakeLists.txt (+2) 
- (modified) libc/src/__support/FPUtil/FEnvImpl.h (+1-1) 
- (modified) libc/src/__support/File/dir.cpp (+1-1) 
- (modified) libc/src/__support/File/file.cpp (+1-1) 
- (modified) libc/src/__support/File/linux/file.cpp (+1-1) 
- (modified) libc/src/__support/File/linux/lseekImpl.h (+1-1) 
- (modified) libc/src/__support/HashTable/randomness.h (+1-1) 
- (modified) libc/src/__support/OSUtil/linux/fcntl.cpp (+1-1) 
- (modified) libc/src/__support/OSUtil/linux/vdso.cpp (+1-1) 
- (modified) libc/src/__support/StringUtil/tables/linux_extension_errors.h 
(+1-1) 
- (added) libc/src/__support/libc_errno.h (+93) 
- (added) libc/src/__support/math/CMakeLists.txt () 
- (added) libc/src/__support/math/exp_float_constants.h (+145) 
- (added) libc/src/__support/math/expf.h (+116) 
- (modified) libc/src/__support/threads/linux/thread.cpp (+1-1) 
- (modified) libc/src/dirent/closedir.cpp (+1-1) 
- (modified) libc/src/dirent/opendir.cpp (+1-1) 
- (modified) libc/src/dirent/readdir.cpp (+1-1) 
- (modified) libc/src/errno/CMakeLists.txt (-15) 
- (modified) libc/src/errno/libc_errno.cpp (+5-46) 
- (removed) libc/src/errno/libc_errno.h (-47) 
- (modified) libc/src/fcntl/linux/creat.cpp (+1-1) 
- (modified) libc/src/fcntl/linux/open.cpp (+1-1) 
- (modified) libc/src/fcntl/linux/openat.cpp (+1-1) 
- (modified) libc/src/inttypes/strtoimax.cpp (+1-1) 
- (modified) libc/src/inttypes/strtoumax.cpp (+1-1) 
- (modified) libc/src/math/generic/exp10m1f.cpp (+1-1) 
- (modified) libc/src/math/generic/exp2m1f.cpp (+1-1) 
- (modified) libc/src/math/generic/expf.cpp (+2-95) 
- (modified) libc/src/math/generic/nan.cpp (+1-1) 
- (modified) libc/src/math/generic/nanf.cpp (+1-1) 
- (modified) libc/src/math/generic/nanf128.cpp (+1-1) 
- (modified) libc/src/math/generic/nanf16.cpp (+1-1) 
- (modified) libc/src/math/generic/nanl.cpp (+1-1) 
- (modified) libc/src/poll/linux/poll.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_atfork.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_attr_setdetachstate.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_attr_setguardsize.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_attr_setstack.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_attr_setstacksize.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_condattr_setclock.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_condattr_setpshared.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_create.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_key_create.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_key_delete.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_mutexattr_setpshared.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_mutexattr_setrobust.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_mutexattr_settype.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlock_timedrdlock.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlock_trywrlock.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlock_unlock.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlockattr_setkind_np.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_rwlockattr_setpshared.cpp (+1-1) 
- (modified) libc/src/pthread/pthread_setspecific.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_get_priority_max.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_get_priority_min.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_getaffinity.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_getparam.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_getscheduler.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_rr_get_interval.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_setaffinity.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_setparam.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_setscheduler.cpp (+1-1) 
- (modified) libc/src/sched/linux/sched_yield.cpp (+1-1) 
- (modified) libc/src/search/hcreate.cpp (+1-1) 
- (modified) libc/src/search/hcreate_r.cpp (+1-1) 
- (modified) libc/src/search/hdestroy_r.cpp (+1-1) 
- (modif