4759 Commits

Author SHA1 Message Date
Alexey Samsonov
1136239561
[libc] Add missing dependencies for arpa/inet.h header. (#168951)
Add dependency on headers with `in_addr` and `in_addr_t` type
definitions to ensure that these headers will be properly installed by
"install-libc" CMake target.
2025-11-20 22:04:05 +00:00
Petr Hosek
91e777f26d
[libc] Removed unused flags from baremetal cache files (#168942)
These flags are not needed for building libc.
2025-11-20 20:44:17 +00:00
lntue
aa3f930931
[libc][math] Add float-only implementation for atanf. (#167004)
Algorithm:
```
  1)  atan(x) = sign(x) * atan(|x|)

  2)  If |x| > 1 + 1/32, atan(|x|) = pi/2 - atan(1/|x|)

  3)  For 1/16 < |x| < 1 + 1/32, we find k such that: | |x| - k/16 | <= 1/32.
      Let y = |x| - k/16, then using the angle summation formula, we have:
    atan(|x|) = atan(k/16) + atan( (|x| - k/16) / (1 + |x| * k/16) )
              = atan(k/16) + atan( y / (1 + (y + k/16) * k/16 )
              = atan(k/16) + atan( y / ((1 + k^2/256) + y * k/16) )

  4)  Let u = y / (1 + k^2/256), then we can rewritten the above as:
    atan(|x|) = atan(k/16) + atan( u / (1 + u * k/16) )
              ~ atan(k/16) + (u - k/16 * u^2 + (k^2/256 - 1/3) * u^3 +
                              + (k/16 - (k/16)^3) * u^4) + O(u^5)
```

With all the computations are done in single precision (float), the
total of approximation errors and rounding errors is bounded by 4 ULPs.
2025-11-20 09:42:13 -05:00
Joseph Huber
7fe3564167
[Clang] Gut the libc wrapper headers and simplify (#168438)
Summary:
These were originally intended to represent the functions that are
present on the GPU as to be provided by the LLVM libc implementation.
The original plan was that LLVM libc would report which functions were
supported and then the offload interface would mark those as supported.
The problem is that these wrapper headers are very difficult to make
work given the various libc extensions everyone does so they were
extremely fragile.

OpenMP already declares all functions used inside of a target region as
implicitly host / device, while these headers weren't even used for CUDA
/ HIP yet anyway. The only things we need to define right now are the
stdio FILE types. If we want to make this work for CUDA we'd need to
define these manually, but we're a ways off and that's way easier
because they do proper overloading.
2025-11-19 07:18:13 -06:00
Alexey Samsonov
5bba4fd75d
[libc] Fix -Wshorten-64-to-32 in fileop_test. (#168451)
Explicitly cast 0 to size_t type to match fread() return type. This
follows the pattern used elsewhere in this file, and fixes
-Wshorten-64-to-32 warnings when building the test.
2025-11-18 21:41:55 -08:00
Jackson Stogel
db71cc58ec
[libc] Implement pkey_alloc/free/get/set/mprotect for x86_64 linux (#162362)
This patch provides definitions for `pkey_*` functions for linux x86_64.

`pkey_alloc`, `pkey_free`, and `pkey_mprotect` are simple syscall
wrappers. `pkey_set` and `pkey_get` modify architecture-specific
registers. The logic for these live in architecture specific
directories:

* `libc/src/sys/mman/linux/x86_64/pkey_common.h` has a real
implementation
* `libc/src/sys/mman/linux/generic/pkey_common.h` contains stubs that
just return `ENOSYS`.
2025-11-18 14:30:15 -08:00
Connector Switch
a5590a2aab
[libc] implement inet_addr (#167708)
This patch adds the posix function `inet_addr`. Since most of the
parsing logic is delegated to `inet_aton`, I have only included some
basic smoke tests for testing purposes.
2025-11-18 10:17:19 +08:00
Alexey Samsonov
da61dd28c6
[libc] Move mbtowc, mbstowcs and inverse functions to stdlib.h (#168455)
These functions should be declared in `stdlib.h`, not `wchar.h`, as
confusing as it is. Move them to the proper header file and matching
directories in src/ and test/ trees.

This was discovered while testing libc++ build against llvm-libc, which
re-declares functions like mbtowc in std-namespace in `<cstdlib>`
header, and then uses those functions in its locale implementation.
2025-11-17 15:43:42 -08:00
Alexey Samsonov
92c8c87c49
[libc] Implement wcstod and wcstold. (#168020)
These are simply implemented as specializations of strtofloatingpoint
for double / long double and for wchar_t. The unit tests are copied from
the strtod / strtold ones.
2025-11-17 13:42:12 -08:00
Prabhu Rajasekaran
b32c434426
[libc][Github] Perform baremetal libc builds (#167583)
Currently there are no 32 bit presubmit builds for libc. This PR
performs 32 bit build only (no test) to check any changes that land in
libc break 32 bit builds.

Co-authored-by: Aiden Grossman <aidengrossman@google.com>
2025-11-17 12:08:39 -08:00
Anton Shepelev
9d7e341032
[libc][POSIX][RISCV] Disabled clock_settime on RV32 (#168006) 2025-11-14 13:39:20 -05:00
Shreeyash Pandey
b9c769bae5
[libc] fix EXPECT_EXIT suspend/timeout for darwin (#166065)
Fixes: https://github.com/llvm/llvm-project/issues/166059

---------

Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-11-14 13:37:37 -05:00
Schrodinger ZHU Yifan
5b798df8c4
Revert "[libc][test] split exit tests into two separate tests" (#168102)
Reverts llvm/llvm-project#166355
2025-11-14 13:36:05 -05:00
lntue
cfce4a6b9e
[libc] Allow user-defined LIBC_ASSERT macro. (#168087)
By only defining it if LIBC_ASSERT macro is not defined.

Fixes https://github.com/llvm/llvm-project/issues/162392
2025-11-14 13:28:09 -05:00
Shreeyash Pandey
e7db040b79
[libc][test] split exit tests into two separate tests (#166355)
_Exit(3) is a fairly simple syscall wrapper whereas exit(3) calls
atexit-registered functions + whole lot of stuff that require support
for sync primitives.

Splitting the tests allows testing the former easily (especially for new
port projects)

---------

Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-11-14 13:27:32 -05:00
Shreeyash Pandey
bbece4b78b
[libc] replace for loops with a call to memcpy in File (#165219)
Addresses `TODO`s in file.cpp by replacing data copies via for loops
with calls to inline_memcpy.

Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-11-14 10:26:11 -08:00
Alexey Samsonov
e797ec6476
[libc] Templatize strtofloatingpoint and implement wcstof. (#167755)
This change follows the pattern of
315dfe5865962d8a3d60e21d1fffce5214fe54ef by making strtofloat also
accept wchar_t* strings
(in addition to regular char*). It uses overloads from wctype_utils or
specialized functions to ensure comparison with literal characters (or
literal strings) pick char or wchar_t variants based on the argument
type.

The wcstof implementation is added, with unit test cases copied from
strtof test suite.
2025-11-13 11:38:33 -08:00
Joseph Huber
6b49e6a14f [libc][NFC] Fix warnings in RPC server code 2025-11-13 11:01:44 -06:00
Jeff Bailey
56eef98a93
[libc][stdlib] Simplify getenv_test by using strcmp instead of custom helper (#163055)
[libc][stdlib] Simplify getenv_test by using inline_strcmp instead of custom helper

Replace the custom `my_streq` helper function with LLVM libc's
`inline_strcmp` utility from `src/string/memory_utils/inline_strcmp.h`.

Changes:
- Remove 18-line custom `my_streq` implementation
- Use `inline_strcmp` with a simple comparator lambda for string comparisons
- Replace `my_streq(..., nullptr)` checks with direct `== nullptr` comparisons
- Maintain identical test coverage while reducing code duplication

Benefits:
- Uses existing, well-tested LLVM libc infrastructure
- Clearer test assertions with standard comparison functions
- More concise code (reduced from ~48 to ~33 lines)
- Consistent with LLVM libc coding practices

The test continues to verify:
- Empty string handling
- Invalid name handling ('=')
- Missing environment variable queries
- Correct retrieval of existing variables (FRANCE, GERMANY, PATH)
- Partial name matching behavior (FRANC vs FRANCE, FRANCE1 vs FRANCE)
2025-11-13 13:47:07 +00:00
Shreeyash Pandey
8c0dadf7b3
[libc] allow UnitTest suite to be compiled on darwin (#166062)
ExecuteFunctionUnix.cpp which is guarded by this check should reliably
work
on darwin as it only uses POSIX API - nothing specific to linux.
2025-11-12 18:57:52 -05:00
Petr Hosek
242a6cbc5f
[libc] Handle the unknown default target in CMake (#115122)
When the backend for the host target isn't enabled, Clang would report
the default target as `unknown`. This currently breaks the libc CMake
build, but shouldn't in the case where we're cross-compiling since we're
given an explicit target and the default one isn't being used.
2025-11-12 11:36:54 -08:00
Victor Campos
5932477af4
[libc] Add support for MVE to Arm startup code (#167338)
In order to have MVE support, the same bits of the CPACR register that
enable the floating-point extension must be set.
2025-11-12 15:33:41 +00:00
Michael Kruse
0957656a40
[runtimes][GTest] LLVM-independent unittests (#164794)
The LLVM-customized GTest has a dependency on LLVM to support
`llvm::raw_ostream` and hence has to link to LLVMSupport. The runtimes
use the LLVMSupport from the bootstrapping LLVM build. The problem is
that the boostrapping compiler and the runtimes target can diverge in
their ABI, even in the runtimes default build. For instance, Clang is
built using gcc which uses libstdc++, but the runtimes is built by Clang
which can be configured to use libcxx by default. Altough it does not
use gcc, this issue has caused
[flang-aarch64-libcxx](https://lab.llvm.org/buildbot/#/builders/89)) to
break, and is still (again?) broken.

This patch makes the runtimes' GTest independent from LLVMSupport so we
do not link any runtimes component with LLVM components.

Runtime projects that use GTest unittests:
 * flang-rt
 * libc
* compiler-rt: Adds `gtest-all.cpp` with
[GTEST_NO_LLVM_SUPPORT=1](f801b6f67e/compiler-rt/CMakeLists.txt (L723))
to each unittest without using `llvm_gtest`. Not touched by this PR.
* openmp: Handled by #159416. Not touched for now by this PR to avoid
conflict.

The current state of this PR tries to reuse
https://github.com/llvm/llvm-project/blob/main/third-party/unittest/CMakeLists.txt
as much as possible, altough personally I would prefer to make it use
"modern CMake" style. third-party/unittest/CMakeLists.txt will detect
whether it is used in runtimes build and adjaust accordingly. It creates
a different target for LLVM (`llvm_gtest`, NFCI) and another one for the
runtimes (`runtimes_gtest`). It is not possible to reuse `llvm_gtest`
for both since `llvm_gtest` is imported using `find_package(LLVM)` if
configured using LLVM_INSTALL_GTEST. An alias `default_gtest` is used to
select between the two. `default_gtest` could also be used for openmp
which also supports standalone and
[LLVM_ENABLE_PROJECTS](https://github.com/llvm/llvm-project/pull/152189)
build mode.
2025-11-12 11:50:33 +01:00
Alexey Samsonov
124bfdf365
[libc] Use function overloads to make string parsing code more generic. (#167417)
ctype_utils/wctype_utils were chaged in
120689e46679c6db37cd9e839ec0721e80a22d4f and
e7f7973899f76773ae6e9a6b1e8c7e9f9cc5cb56, respectively to operate on
char/wchar_t. Now we can switch to the overloaded names (e.g. have noth
`isspace(char` and `isspace(wchar_t)`) to simplify the templatized
strtointeger implementation from
315dfe5865962d8a3d60e21d1fffce5214fe54ef and make it easier to
potentially add templatized strtofloat implementation.
2025-11-11 22:52:00 -08:00
Sterling-Augustine
e77001c9f5
[libc] Use a sensible default when TEST_UNDECLARED_OUTPUTS_DIR is unset. (#167422)
There is no guarantee that this environment variable is set. Eg, when
running a test outside of the build system, such as under a debugger.
And passing a nullptr to the string constructor is undefined.

Use an empty string, which seems like it is close to the original
intent.
2025-11-11 11:49:10 -08:00
Victor Campos
49dc49e125
[libc][math] Add asin to baremetal Arm and AArch64 (#167339)
This patch adds `asin` to the entry points for Arm and AArch64.

Tests have been run using Arm Toolchain for Embedded, a downstream
toolchain.
2025-11-11 13:29:22 -05:00
Anton Shepelev
79601cec33
[libc][POSIX] Add clock_settime() function for Linux (#161729)
Closes #161461
- This is my first time contributing to libc's POSIX, so for reference I
used `clock_gettime` implementation for Linux. For convenience, here is
the description of `clock_settime` function
[behavior](https://www.man7.org/linux/man-pages/man3/clock_settime.3.html)
2025-11-11 09:54:34 -08:00
Anshul Nigham
497dc100c9
[libc] Implement fchown (#167286)
Implements fchown

fixes: #166856
2025-11-11 09:54:21 -08:00
Marcell Leleszi
a4a6b5ff63
[libc] Refactor strftime internals to handle size_t return values (#166901)
Now that https://github.com/llvm/llvm-project/pull/166517 has landed and
[Writer](https://github.com/llvm/llvm-project/blob/main/libc/src/stdio/printf_core/writer.h#L130)
has been refactored to track bytes written as size_t, strftime can be
refactored as well to handle size_t return values.

Can't think of a proper way to test this without creating a 2GB+ string,
but existing tests cover most cases.
2025-11-11 09:54:09 -08:00
Schrodinger ZHU Yifan
8751f26a1b
[libc] add an SVE implementation of strlen (#167259)
This PR creates an SVE-based implementation for strlen by translating
from the AOR code in tree. Microbenchmark shows improvements against
NEON when N>=64. Although both implementations fall behind glibc by a
large margin,
this may be a good start point to explore SVE implementations.

Together with the PR:

1. Added two more tests of strlen with special nul symbols.
2. Added strlen's fuzzer and fix a typo in previous heap fuzzer.

```
=== strlen(16 bytes) ===
libc: 1.56115 ns/call, 9.54499 GiB/s
neon: 1.59393 ns/call, 9.34867 GiB/s
sve: 1.66097 ns/call, 8.97134 GiB/s

=== strlen(64 bytes) ===
libc: 2.06967 ns/call, 28.7991 GiB/s
neon: 2.59914 ns/call, 22.9325 GiB/s
sve: 2.58628 ns/call, 23.0465 GiB/s

=== strlen(256 bytes) ===
libc: 3.74165 ns/call, 63.7202 GiB/s
neon: 8.98243 ns/call, 26.5428 GiB/s
sve: 7.36426 ns/call, 32.3751 GiB/s

=== strlen(1024 bytes) ===
libc: 10.5327 ns/call, 90.5438 GiB/s
neon: 34.363 ns/call, 27.7529 GiB/s
sve: 26.9329 ns/call, 35.4092 GiB/s

=== strlen(4096 bytes) ===
libc: 37.7304 ns/call, 101.104 GiB/s
neon: 145.911 ns/call, 26.144 GiB/s
sve: 103.208 ns/call, 36.9612 GiB/s

=== strlen(1048576 bytes) ===
libc: 9623.4 ns/call, 101.478 GiB/s
neon: 36138.2 ns/call, 27.023 GiB/s
sve: 26605.6 ns/call, 36.7051 GiB/s
```
2025-11-10 19:15:34 -05:00
Sterling-Augustine
c5ce8021da
[libc] fwrite_unlocked: only return errno if an actual error occurred. (#167350)
fwrite and friends don't modify errno if no error occurred. Therefore
frite_unlocked's return value shouldn't be constructed from errno
without checking if an error actually occurred.

This fixes an error introduced by
9e2f73fe90
2025-11-10 14:58:26 -08:00
Jackson Stogel
4b9d7e167b
Reapply "[libc] Return errno from OFD failure paths in fcntl." (#166658) (#166846)
The previous implementation in #166252 (rolled back in #166658) caused
buildbot failures due to a bug in an added test. The modified
`UseAfterClose` did not pass a `struct flock` value to `fcntl`:


2d51705941/libc/test/src/fcntl/fcntl_test.cpp (L175)

Which ASAN caught and errored in the `fcntl` implementation when the
unspecified argument was accessed:


c12cb2892c/libc/src/__support/OSUtil/linux/fcntl.cpp (L59)
2025-11-10 13:39:34 -08:00
Connector Switch
ffb5831fce
[libc] add various macros relate to *ADDR* (#164830)
This patch adds 4 macros in the `netinet/in.h` header, as specified by
POSIX standards.
2025-11-08 20:39:26 +08:00
Schrodinger ZHU Yifan
2dd77050d4
[libc] add cpu feature flags for SVE/SVE2/MOPS (#166884)
Add in SVE/SVE2/MOPS features for aarch64 cpus. These features may be
interesting for future memory/math routines.

SVE/SVE2 are now being accepted in more implementations:

```
❯ echo | clang-21 -dM -E - -march=native | grep -i ARM_FEAT
#define __ARM_FEATURE_ATOMICS 1
#define __ARM_FEATURE_BF16 1
#define __ARM_FEATURE_BF16_SCALAR_ARITHMETIC 1
#define __ARM_FEATURE_BF16_VECTOR_ARITHMETIC 1
#define __ARM_FEATURE_BTI 1
#define __ARM_FEATURE_CLZ 1
#define __ARM_FEATURE_COMPLEX 1
#define __ARM_FEATURE_CRC32 1
#define __ARM_FEATURE_DIRECTED_ROUNDING 1
#define __ARM_FEATURE_DIV 1
#define __ARM_FEATURE_DOTPROD 1
#define __ARM_FEATURE_FMA 1
#define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
#define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1
#define __ARM_FEATURE_FRINT 1
#define __ARM_FEATURE_IDIV 1
#define __ARM_FEATURE_JCVT 1
#define __ARM_FEATURE_LDREX 0xF
#define __ARM_FEATURE_MATMUL_INT8 1
#define __ARM_FEATURE_NUMERIC_MAXMIN 1
#define __ARM_FEATURE_PAUTH 1
#define __ARM_FEATURE_QRDMX 1
#define __ARM_FEATURE_RCPC 1
#define __ARM_FEATURE_SVE 1
#define __ARM_FEATURE_SVE2 1
#define __ARM_FEATURE_SVE_BF16 1
#define __ARM_FEATURE_SVE_MATMUL_INT8 1
#define __ARM_FEATURE_SVE_VECTOR_OPERATORS 2
#define __ARM_FEATURE_UNALIGNED 1
```
MOPS is another set of extension for string operations, but may not be
generally available for now:
```
❯ echo | clang-21 -dM -E - -march=armv9.2a+mops | grep -i MOPS
#define __ARM_FEATURE_MOPS 1
```
2025-11-07 13:58:54 -05:00
Victor Campos
3a8f6979ce
[libc][math] Enable math acos for baremetal Arm and AArch64 (#166749)
This patch adds `acos` to the entrypoints of baremetal Arm and AArch64.

Tests have been run with Arm Toolchain for Embedded, a downstream
toolchain, in conjunction with qemu, across several configurations of
FPUs and architecture versions. All tests run are passing.
2025-11-07 09:23:00 +00:00
Prabhu Rajasekaran
bf1b86698b
[libc] Add localtime_r to baremetal entrypoints (#166677) 2025-11-06 21:18:26 -08:00
Marcell Leleszi
6adf993388
[libc] Disable overflow test in strfromtest on riscv32 (#166719)
Looks like https://github.com/llvm/llvm-project/pull/166517 is breaking
libc-riscv32-qemu-yocto-fullbuild-dbg build due to failing overflow test
for strfrom.
https://lab.llvm.org/buildbot/#/changes/58668

```
int result = func(buff, sizeof(buff), "%.2147483647f", 1.0f);
EXPECT_LT(result, 0);
ASSERT_ERRNO_FAILURE();
```

```
[ RUN      ] LlvmLibcStrfromdTest.CharsWrittenOverflow
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/test/src/stdlib/StrfromTest.h:493: FAILURE
       Expected: result
       Which is: 0
To be less than: 0
       Which is: 0
/home/libcrv32buildbot/bbroot/libc-riscv32-qemu-yocto-fullbuild-dbg/llvm-project/libc/test/src/stdlib/StrfromTest.h:494: FAILURE
          Expected: 0
          Which is: 0
To be not equal to: static_cast<int>(libc_errno)
          Which is: 0
[  FAILED  ] LlvmLibcStrfromdTest.CharsWrittenOverflow
Ran 8 tests.  PASS: 7  FAIL: 1
```

At first glance it seem like there is some kind of overflow in
internal::strfromfloat_convert on 32bit archs because the other overflow
test case is passing for snprintf. Interestingly, it passes on all other
buildbots, including libc-arm32-qemu-debian-dbg.

This issue likely wasn't introduced by
https://github.com/llvm/llvm-project/pull/166517 and was probably
already present, so I'm not reverting the change just disabling the test
case on riscv32 until I can debug properly.
2025-11-06 12:55:16 -08:00
Sterling-Augustine
7ff8a51754
[libc] Fix stale char_ptr for find_first_character_wide read (#166594)
On exit from the loop, char_ptr had not been updated to match block_ptr,
resulting in erroneous results. Moving all updates out of the loop fixes
that.

Adjust derefences to always be inside bounds checks.
2025-11-06 06:48:14 -08:00
Victor Campos
22b6c491d6
[libc] Enable the FPU in Arm startup code (#166349)
This patch enables the FPU in Arm startup code, which is required to run
tests on Arm configurations with hardware floating-point support.
2025-11-06 10:45:45 +00:00
Karlo Basioli
fc179af520
Fix bazel build issue caused in #166517 (#166734) 2025-11-06 10:57:18 +01:00
Jackson Stogel
597cd767d6
Revert "[libc] Return errno from OFD failure paths in fcntl." (#166658)
Reverts llvm/llvm-project#166252

Causing buildbot failures on `libc-x86_64-debian-dbg-asan`.
2025-11-05 23:08:55 +00:00
Jackson Stogel
81dede888a
[libc] Return errno from OFD failure paths in fcntl. (#166252)
This patch also configures fcntl lock tests to run with F_OFD_* command
variants, as all existing lock tests do not exercise process-associated-
or OFD-specific functionality.
2025-11-05 14:35:20 -08:00
Jackson Stogel
c3b2849191
[libc] Allow openat and creat to return fd 0. (#166466)
Previously, if the `open` or `openat` syscalls returned 0 as a (valid)
file descriptor, the `creat` and `openat` wrappers would erroneously
return -1.
2025-11-05 13:21:18 -08:00
Marcell Leleszi
9e2f73fe90
[libc] Add printf error handling (with fixes #2) (#166517)
https://github.com/llvm/llvm-project/issues/159474

Another try of trying to land
https://github.com/llvm/llvm-project/pull/166382
- Fix some leftover tests checking for specific  errnos
- Guard errno checking tests to not run on the GPU

@michaelrj-google
2025-11-05 16:09:53 -05:00
Marcell Leleszi
3d0a3674d9
[libc] Make errno asserts noop on gpu targets (#166606)
This patch defines errno unit and integration test asserts as noop on
GPU targets. Checking for errnos is tests has caused build breakages in
previous patches.
2025-11-05 11:17:13 -08:00
Alexey Samsonov
e7f7973899
[libc] Migrate wctype_utils to use wchar_t where applicable. (#166234)
This is a counterpart of
https://github.com/llvm/llvm-project/pull/166225 but for wctype_utils
(which are not yet widely used). For now, I'm just changing the types
from wint_t to wchar_t to match the regular ctype_utils change. The next
change may rename most of the functions to match the name of ctype_utils
variants, so that we could be calling them from the templated code
operating on "const char*" and "const wchar_t*" strings, and the right
function signature would be picked up.
2025-11-05 11:03:25 -08:00
Alexey Samsonov
120689e466
[libc] Migrate ctype_utils to use char instead of int where applicable. (#166225)
Functions like isalpha / tolower can operate on chars internally. This
allows us to get rid of unnecessary casts and open a way to creating
wchar_t overloads with the same names (e.g. for isalpha), that would
simplify templated code for conversion functions (see
315dfe5865962d8a3d60e21d1fffce5214fe54ef).

Add the int->char converstion to public entrypoints implementation
instead. We also need to introduce bounds check on the input argument
values - these functions' behavior is unspecified if the argument is
neither EOF nor fits in "unsigned char" range, but the tests we've had
verified that they always return false for small negative values. To
preserve this behavior, cover it explicitly.
2025-11-05 11:02:28 -08:00
Victor Campos
0b72899f6d
[libc][math] Refactor the math_errhandling macro definition (#166350)
This patch refactors the logic to define each component of the
`math_errhandling` macro.

It assumes that math error handling is supported by the target and the C
library unless otherwise disabled in the preprocessor logic.

In addition to the refactoring, the support for error handling via
exceptions is explicitly disabled for Arm targets with no FPU, that is,
where `__ARM_FP` is not defined. This is because LLVM libc does not
provide a floating-point environment for Arm no-FP configurations (or at
least one with support for FP exceptions).
2025-11-05 16:59:55 +00:00
Muhammad Bassiouni
0d77cba6e1
[libc][math] Refactor exp2m1f16 implementation to header-only in src/__support/math folder. (#162019)
Part of #147386

in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-11-05 14:50:40 +02:00
Victor Campos
d249e67a6a
[libc][math] Disable FEnvSafeTest.cpp if AArch64 target has no FP support (#166370)
The `FEnvSafeTest.cpp` test fails on AArch64 soft nofp configurations
because LLVM libc does not provide a floating-point environment in these
configurations.

This patch adds another preprocessor guard on `__ARM_FP` to disable the
test on those.
2025-11-05 11:14:02 +00:00