2729 Commits

Author SHA1 Message Date
Petr Hosek
521080386e
[libc] Cast the error value to int (#172724)
The negative value represents an error and we already use cast in this
scenario elsewhere.
2025-12-17 20:09:35 +00:00
lntue
a450c38012
[libc][fenv] Fix performance regression for x86 mxcsr utilities. (#172717)
In a recent update to x86's fenv, we use `_MM_GET/SET_EXCEPTION_STATE`
macros from `<immintrin.h>` which turn out to do a bit more work than
just read and write the mxcsr register. In this PR we change those to a
direct read and write mxcsr intrinsics.
2025-12-17 15:07:08 -05:00
Petr Hosek
dd63127b56
[libc] Support opaque FILE* on baremetal (#168931)
This change expands the stdio support on baremetal to support opaque
FILE*. This builds on top of the existing baremetal embedding API; we
treat the standard FILE* streams as pointers that point to the cookie
symbols which are a part of the embedding API. This also allows users to
define their own FILE* streams, but we don't (yet) support the API that
return FILE* such as fopen or fopencookie.
2025-12-17 10:56:45 -08:00
Jinsong Ji
1f2818cea3
libc: Prefix Rounding Control Error enum to avoid conflict in windows build (#172562)
Similar to e85a9f5540f5

Somehow conflict with define in wingdi.h.

Fix build failures:
...FPUtil\x86_64\fenv_x86_common.h(78,29): error: expected member name
or
';' after declaration specifiers

78 |   static constexpr uint16_t ERROR = 0xFFFF;
         |   ~~~~~~~~~~~~~~~~~~~~~~~~~ ^
c:\Program files (x86)\Windows
Kits\10\include\10.0.22000.0\um\wingdi.h(118,29):
note: expanded from macro 'ERROR'
      118 | #define ERROR               0
          |
2025-12-17 11:45:19 -05:00
Schrodinger ZHU Yifan
10ed050b34
[libc][CPP] make the string trap on OOM (#172260)
This PR makes the string trap on OOM.

Previously, the `__builtin_unreachable` has made debugging tricky as it
makes the control flow of OOM as an undefined behavior.
We can run into OOM with testing configuration easily where memory is
statically bounded.

We did not settle with the best solution of this but making it trap is
at least better than UB
in this case.
2025-12-17 05:03:39 -05:00
Shreeyash Pandey
3c97829d97
[libc] Add Darwin mutex support via os_sync primitives (#167722)
This patch implements the generic mutex and raw_mutex interfaces on
macOS. A new Futex class is provided that relies on os_sync_wait and
os_sync_wake to emulate futex‑like wait and wake semantics. The
OS‑specific part is moved into futex_utils, which now contains the
Darwin implementation.
2025-12-16 23:22:19 +05:30
lntue
c4a0d71386
[libc] Fix ifdef in compiler.h. (#172324) 2025-12-15 16:11:30 +00:00
Mehdi Amini
efd9dc83f2
Revert "[APFloat] Add exp function for APFloat::IEEESsingle using expf implementation from LLVM libc. (#143959)" (#172325)
This reverts commit 4190d576823c18f45ee0632baee7d798448178ac.

See https://lab.llvm.org/buildbot/#/builders/181/builds/33524

```
                 from /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/lib/Support/APFloat.cpp:32:
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../libc/src/__support/math/asin_utils.h:548:1:   in ‘constexpr’ expansion of ‘__llvm_libc::fputil::DyadicFloat<128>(__llvm_libc::Sign::POS, -127, __llvm_libc::BigInt<128, false, long unsigned int>(__llvm_libc::operator""_u128(((const char*)"0x80000000\'00000000\'00000000\'00000000"))))’
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../libc/src/__support/FPUtil/dyadic_float.h:109:5:   in ‘constexpr’ expansion of ‘((__llvm_libc::fputil::DyadicFloat<128>*)this)->__llvm_libc::fputil::DyadicFloat<128>::normalize()’
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../libc/src/__support/FPUtil/dyadic_float.h:118:16:   in ‘constexpr’ expansion of ‘((__llvm_libc::fputil::DyadicFloat<128>*)this)->__llvm_libc::fputil::DyadicFloat<128>::mantissa.__llvm_libc::BigInt<128, false, long unsigned int>::operator<<=(((size_t)shift_length))’
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../libc/src/__support/big_int.h:829:52:   in ‘constexpr’ expansion of ‘__llvm_libc::multiword::shift<__llvm_libc::multiword::LEFT, false, long unsigned int, 2>(((__llvm_libc::BigInt<128, false, long unsigned int>*)this)->__llvm_libc::BigInt<128, false, long unsigned int>::val, s)’
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../libc/src/__support/big_int.h:264:35: error: ‘constexpr __llvm_libc::cpp::enable_if_t<((((sizeof (To) == sizeof (From)) && __llvm_libc::cpp::is_trivially_constructible<To>::value) && __llvm_libc::cpp::is_trivially_copyable<T>::value) && __llvm_libc::cpp::is_trivially_copyable<From>::value), To> __llvm_libc::cpp::bit_cast(const From&) [with To = __int128 unsigned; From = __llvm_libc::cpp::array<long unsigned int, 2>; __llvm_libc::cpp::enable_if_t<((((sizeof (To) == sizeof (From)) && __llvm_libc::cpp::is_trivially_constructible<To>::value) && __llvm_libc::cpp::is_trivially_copyable<T>::value) && __llvm_libc::cpp::is_trivially_copyable<From>::value), To> = __int128 unsigned]’ called in a constant expression
  264 |     auto tmp = cpp::bit_cast<type>(array);
      |                ~~~~~~~~~~~~~~~~~~~^~~~~~~
                 from /home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/lib/Support/APFloat.cpp:32:
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../libc/src/__support/CPP/bit.h:48:1: note: ‘constexpr __llvm_libc::cpp::enable_if_t<((((sizeof (To) == sizeof (From)) && __llvm_libc::cpp::is_trivially_constructible<To>::value) && __llvm_libc::cpp::is_trivially_copyable<T>::value) && __llvm_libc::cpp::is_trivially_copyable<From>::value), To> __llvm_libc::cpp::bit_cast(const From&) [with To = __int128 unsigned; From = __llvm_libc::cpp::array<long unsigned int, 2>; __llvm_libc::cpp::enable_if_t<((((sizeof (To) == sizeof (From)) && __llvm_libc::cpp::is_trivially_constructible<To>::value) && __llvm_libc::cpp::is_trivially_copyable<T>::value) && __llvm_libc::cpp::is_trivially_copyable<From>::value), To> = __int128 unsigned]’ is not usable as a ‘constexpr’ function because:
   48 | bit_cast(const From &from) {
      | ^~~~~~~~
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu/llvm-project/llvm/../libc/src/__support/CPP/bit.h:56:28: error: call to non-‘constexpr’ function ‘void __llvm_libc::cpp::inline_copy(const char*, char*) [with unsigned int N = 16]’
   56 |   inline_copy<sizeof(From)>(src, dst);
```
2025-12-15 16:57:37 +01:00
lntue
4190d57682
[APFloat] Add exp function for APFloat::IEEESsingle using expf implementation from LLVM libc. (#143959)
Discourse RFC:
https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450

- The implementation in LLVM libc is header-only.
- expf implementation in LLVM libc is correctly rounded for all rounding
modes.
- LLVM libc implementation will round to the floating point
environment's rounding mode.
- No cmake build dependency between LLVM and LLVM libc, only requires
LLVM libc source presents in llvm-project/libc folder.
2025-12-15 10:21:45 -05:00
Michael Jones
b50f6f24fe
[libc] Properly fix printf long double subnormals (#172103)
In a previous PR I fixed one case where subnormal long doubles would
cause an infinite loop in printf. It was an improper fix though. The
problem was that a shift on the fixed point representation would
sometimes go negative, since the effective exponent of a subnormal is
lower than the minimum allowed exponent value. This patch extends the
fixed point representation to have space for subnormals, and adds an
assert to check that lshifts are always positive. The previous fix of
sometimes shifting right instead of left caused a loss of precision
which also sometimes caused infinite loops in the %e code.
2025-12-12 23:25:35 +00:00
Muhammad Bassiouni
3a04e01f34
[libc][wctype][codegen] Add generation script for conversion data (#170868)
Closes #170871
2025-12-12 16:47:51 +02:00
Alexey Samsonov
5e63167965
[libc] Refactor static polymorphism in WriteBuffer (NFC). (#169089)
There are three flavors of WriteBuffer currently, all of which could be
passed into `printf_core::Writer` class. It's a tricky class, since it
chooses a flavor-specific logic either based on runtime dispatch (to
save code size and prevent generating three versions of the entirety of
printf_core), or based on template arguments (to avoid dealing with
function pointers in codegen for `FILL_BUFF_AND_DROP_OVERFLOW` path).

Refactor this somewhat convoluted logic to have three concrete
subclasses inheriting from the templated base class, and use static
polymorphism with `reinterpret_cast` to implement dispatching above. Now
we can actually have flavor-specific fields, constructors, and methods
(e.g. `flush_to_stream` is now a method of `FlushingBuffer`), and the
code on the user side is cleaner: the complexity of enabling/disabling
runtime-dispatch and using proper template arguments is now localized in
`writer.h`.

This code will need to be further templatized to support buffers of type
`wchar_t` to implement `swprintf()` and friends. This change would make
it (ever so slightly) easier.
2025-12-11 15:31:21 -08:00
Sterling-Augustine
a50a7ea2e2
[libc] Add support for getpagesize. (#171713)
As in the description.
2025-12-11 14:27:50 -08:00
Shreeyash Pandey
2a5420ea51
[libc] move abs_timesout and monotonicity out of linux dir (#167719)
This patch moves abs_timeout and monotonicity out of the linux dir into
common. Both of these functions depend on clock_gettime which is the
actual os-dependent component. As other features in `__support/threads`
may want to use these, it's better to share it in common.
2025-12-08 22:14:12 +05:30
Sterling-Augustine
a1eff73a8e
Include inline_strlen.h on aarch64 only if the target has vector instrucions (#170892) 2025-12-05 13:11:19 -08:00
lntue
4c59219fc9
[libc][fenv] Refactor x86 fenv implementations to make it work for various fenv_t. (#165015) 2025-12-05 16:00:10 -05:00
Sterling-Augustine
ed7e66a41d
Reland Refactor WIDE_READ to allow finer control over high-performance function selection (#165613) (#170738)
[Previous commit had an incorrect default case when
FIND_FIRST_CHARACTER_WIDE_READ_IMPL was not specified in config.json.
This PR is identical to that one with one line fixed.]

As we implement more high-performance string-related functions, we have
found a need for better control over their selection than the big-hammer
LIBC_CONF_STRING_LENGTH_WIDE_READ. For example, I have a memchr
implementation coming, and unless I implement it in every variant, a
simple binary value doesn't work.

This PR makes gives finer-grained control over high-performance
functions than the generic LIBC_CONF_UNSAFE_WIDE_READ option. For any
function they like, the user can now select one of four implementations
at build time:

1. element, which reads byte-by-byte (or wchar by wchar)
2. wide, which reads by unsigned long
3. generic, which uses standard clang vector implemenations, if
available
4. arch, which uses an architecture-specific implemenation

(Reading the code carefully, you may note that a user can actually
specify any namespace they want, so we aren't technically limited to
those 4.)

We may also want to switch from command-line #defines as it is currently
done, to something more like
llvm-project/llvm/include/llvm/Config/llvm-config.h.cmake, and
complexity out of the command-line. But that's a future problem.
2025-12-04 15:58:14 -08:00
Sterling-Augustine
4e5b114ce2
Revert "Refactor WIDE_READ to allow finer control over high-performance function selection" (#170717)
Reverts llvm/llvm-project#165613

Breaks build bot
2025-12-04 10:34:46 -08:00
Sterling-Augustine
8701c2a910
Refactor WIDE_READ to allow finer control over high-performance function selection (#165613)
[This is more of a straw-proposal than a ready-for-merging PR. I got
started thinking about what this might look like, and ended up just
implementing something as a proof-of-concept. Totally open to other
methods an ideas.]

As we implement more high-performance string-related functions, we have
found a need for better control over their selection than the big-hammer
LIBC_CONF_STRING_LENGTH_WIDE_READ. For example, I have a memchr
implementation coming, and unless I implement it in every variant, a
simple binary value doesn't work.

This PR makes gives finer-grained control over high-performance
functions than the generic LIBC_CONF_UNSAFE_WIDE_READ option. For any
function they like, the user can now select one of four implementations
at build time:

1. element, which reads byte-by-byte (or wchar by wchar)
2. wide, which reads by unsigned long
3. generic, which uses standard clang vector implemenations, if
available
4. arch, which uses an architecture-specific implemenation

(Reading the code carefully, you may note that a user can actually
specify any namespace they want, so we aren't technically limited to
those 4.)

We may also want to switch from command-line #defines as it is currently
done, to something more like
llvm-project/llvm/include/llvm/Config/llvm-config.h.cmake, and
#including the resulting file, which would move quite a bit of
complexity out of the command-line. But that's a future problem.
2025-12-04 10:21:53 -08:00
Muhammad Bassiouni
e8defb503d
[libc][math] Refactor expm1 implementation to header-only in src/__support/math folder. (#162127)
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-12-04 16:51:43 +02:00
Shreeyash Pandey
6f8e17c905
[libc] make clock_conversion.h common and document it (#167723)
clock_conversion.h implements convert_clock which shifts a timestamp
from one clock domain to another. It naturally does not depend on any OS
specific interface. Making it generic will allow common use.
2025-12-04 18:01:46 +05:30
Daniel Thornburgh
b76300acc5
[libc][malloc] Ensure a minimum block alignment of 4 (#169447)
Most platforms inherently have a size_t alignment of 4, but this isn't
true on every platform LLVM has some degree of backend support for.
Accordingly, it's simple enough to just set the min alignment of Block
to 4 and lose the static_assert.
2025-12-01 14:41:20 -08:00
Alexey Samsonov
b545e54f7a
[libc] Remove btowc / wctob from wctype_utils internal header. (#170200)
They are not used anywhere except for the btowc/wctob entrypoints, so
just move the implementation there. Internal code should probably be
using a safer mbrtowc variants anyway, if applicable.

This allows us to remove the use of wint_t, which is problematic for
some uses through `libc/shared/` when a host system doesn't have
wide-character support (see PR #165884 comments). There's no such
problems with `wchar_t`, since it's a fundamental type in C++.
2025-12-01 13:33:51 -08:00
Shreeyash Pandey
80e4a3f7a6
[libc] Add clock_gettime for Darwin (#167160)
This patch adds support for clock_gettime for Darwin. Darwin syscall
'gettimeofday' is used to query the time from the system.

Many headers in llvm-libc-types, namely clockid_t, struct_timespec,
struct_timeval, suseconds_t, time_t_32, time_t_64, are modified to
include
header guards as Darwin has its own implementation of primitive types.
2025-11-28 20:23:41 +05:30
Shreeyash Pandey
eb323d8656
[libc][darwin] add internal::exit (#166357)
Add internal::exit for MacOS/Darwin
2025-11-28 19:40:01 +05:30
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
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
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
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
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
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
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
Prabhu Rajasekaran
bf1b86698b
[libc] Add localtime_r to baremetal entrypoints (#166677) 2025-11-06 21:18:26 -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
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
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