Commit Graph

4784 Commits

Author SHA1 Message Date
Connector Switch
62ee2cf0f4 [libc] Add IN6_IS_ADDR_{LINK, SITE}LOCAL (#168207)
This patch introduces two macros in `netinet/in.h`. The redundant tests
for macro values in the testcases have been removed.
2025-12-13 10:57:38 +08: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
Schrodinger ZHU Yifan
dd6c14742b [libc][darwin] avoid importing macros conflicting with function names in overlay mode (#171691)
MacOS SDK defines certain functions as macros in its stdio header. This
leads to problems in overlay mode.

This patch add undefs to macros that may conflict with function names in
overlay header. We don't expect to import them via overlay macro headers
anyway.

```bash
FAILED: [code=1] libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o 
sccache /usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_22_0_0_git -D_DEBUG -I/Users/runner/work/llvm-project/llvm-project/libc -isystem /Users/runner/work/llvm-project/llvm-project/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -std=gnu++17 -arch arm64 -I /Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk/usr/include -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_COPT_STRING_LENGTH_IMPL=element -DLIBC_COPT_FIND_FIRST_CHARACTER_IMPL=element -DLIBC_ADD_NULL_CHECKS -DLIBC_ERRNO_MODE=LIBC_ERRNO_MODE_DEFAULT -DLIBC_THREAD_MODE=LIBC_THREAD_MODE_PLATFORM -DLIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT=100 -fpie -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -MD -MT libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o -MF libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o.d -o libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o -c /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: expected member name or ';' after declaration specifiers
  260 |   void clearerr_unlocked() { err = false; }
      |   ~~~~ ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked'
  495 | #define clearerr_unlocked(p)    __sclearerr(p)
      |                                 ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:26: note: expanded from macro '__sclearerr'
  383 | #define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
      |                           ^
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: expected ')'
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked'
  495 | #define clearerr_unlocked(p)    __sclearerr(p)
      |                                 ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:26: note: expanded from macro '__sclearerr'
  383 | #define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
      |                           ^
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: note: to match this '('
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked'
  495 | #define clearerr_unlocked(p)    __sclearerr(p)
      |                                 ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:25: note: expanded from macro '__sclearerr'
  383 | #define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
      |                          ^
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: unknown type name '_flags'
  260 |   void clearerr_unlocked() { err = false; }
      |        ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked'
  495 | #define clearerr_unlocked(p)    __sclearerr(p)
      |                                 ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:37: note: expanded from macro '__sclearerr'
  383 | #define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
      |                                      ^
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: a type specifier is required for all declarations
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked'
  495 | #define clearerr_unlocked(p)    __sclearerr(p)
      |                                 ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:34: note: expanded from macro '__sclearerr'
  383 | #define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
      |                                   ^
In file included from /Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:9:
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: error: expected ')'
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked'
  495 | #define clearerr_unlocked(p)    __sclearerr(p)
      |                                 ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:44: note: expanded from macro '__sclearerr'
  383 | #define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
      |                                             ^
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.h:260:8: note: to match this '('
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:495:30: note: expanded from macro 'clearerr_unlocked'
  495 | #define clearerr_unlocked(p)    __sclearerr(p)
      |                                 ^
/Applications/Xcode_16.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_stdio.h:383:31: note: expanded from macro '__sclearerr'
  383 | #define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
      |                                ^
/Users/runner/work/llvm-project/llvm-project/libc/src/__support/File/file.cpp:426:23: error: out-of-line definition of 'mode_flags' does not match any declaration in '__llvm_libc_22_0_0_git::File'
  426 | File::ModeFlags File::mode_flags(const char *mode) {
      |                       ^~~~~~~~~~
6 errors generated.
```
2025-12-11 16:29:49 -05:00
Michael Jones
2797688887 [libc][docs] Add a sunset policy to porting docs (#168936)
As discussed in the monthly meeting, update the porting docs to clarify
what's needed for a target and add a policy for sunsetting targets.
2025-12-11 09:29:26 -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
lntue
14bf95b06a [libc] Remove extra commas in linux/config.json. (#170801) 2025-12-05 05:22:05 +00:00
Sterling-Augustine
89ae817ee0 Add commas for riscv and arm configs. (#170776)
Fix for breakage introduced by pr170738
2025-12-04 16:22:54 -08: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
Marcell Leleszi
d8b43edf55 [libc][wctype] Add cmake flag for configuring wctype implementation used (#170531)
#170525 

Based on our
[RFC](https://discourse.llvm.org/t/rfc-libc-wctype-header-implementation/88941/10),
we are starting the implementation of the wctype header with C.UTF8
support. This implementation will increase the binary size by
approximately ~70KB, so this PR introduces a flag so that this is
configurable, allowing the user to choose between a simple ASCII
implementation or the full Unicode one.
2025-12-04 15:38:42 +01: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
lntue
aa727db23e [libc][docs] Add links to 2025 talks. (#170206) 2025-12-01 16:45:21 -05: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
Shreeyash Pandey
4769122b22 [libc][test] split exit tests into two separate tests (#169820)
_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-28 19:32:29 +05:30
Shreeyash Pandey
fb94261d88 [libc][darwin] add syscall numbers from macos sdk (#166354)
This PR adds support to include syscall.h from MacOS sdk by explicitly including the path to the sdk via `xcrun`.
2025-11-27 21:26:42 +05:30
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
315dfe5865 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
120689e466 and
e7f7973899, 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
315dfe5865 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