Commit Graph

3663 Commits

Author SHA1 Message Date
Nick Desaulniers
89560cd612 [libc] disable failing include tests (#114619)
These are failing to link for some buildbots. It's not immediately clear
why,
disable these and add a todo to investigate.

Link: #111403
Link: #114566
Link: #114618
2024-11-01 15:32:48 -07:00
Nick Desaulniers
acd04c2e18 [libc][cmake] disable include tests in overlay mode (#114566)
This avoids -Wmacro-redefinition diagnostics observed when building the
libc_include_tests ninja target.

For example, the signbit_test will attempt to include BOTH our math-macros.h
(via math-function-macros.h), and the system's math.h (via hdr/math_macros.h).

While it's nice that we can get some coverage of the headers we will provide to
end users of fullbuilds in CI of overlay builds, it's not worth chasing each
individual conflict and disabling some include tests as conflicts arise.

Disable the include tests unless `-DLLVM_LIBC_FULL_BUILD=ON` is specified.
2024-11-01 15:01:11 -07:00
Oleksandr T.
21895a84cf [libc] rename LLVM_LIBC_SRC___SUPPORT_UINT_H to LLVM_LIBC_SRC___SUPPORT_BIG_INT_H for consistent naming (#114592)
Fixes #114572
2024-11-01 13:48:39 -07:00
lntue
88a0a318e8 [libc] Use relative inclusion for public headers. (#114324)
We are finalizing the header inclusion policy, and for our public
headers in the `libc/include` folder, they must use relative path in
`"..."` when including each other.

This PR does the cleanup making sure that all the public header
inclusions in `libc/include` folder use relative paths.

---------

Co-authored-by: Nick Desaulniers <nickdesaulniers@users.noreply.github.com>
2024-11-01 14:33:30 -04:00
c8ef
b57b3f6425 [NFC] Simple typo correction. (#114548) 2024-11-02 00:40:57 +08:00
Nick Desaulniers
e083a33478 [libc][cmake] make i386 distinct from x86_64 (#114477)
Configured via:

    $ cmake ../runtimes -G Ninja -DLLVM_ENABLE_LLD=ON \
      -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libc" \
      -DLIBC_TARGET_TRIPLE=i386-linux-gnu -DCMAKE_C_COMPILER=clang \
      -DCMAKE_CXX_COMPILER=clang++

Link: #93709
2024-11-01 08:31:05 -07:00
lntue
5cb730594a [libc] Remove FE_ALL_EXCEPT check in hdr/fenv_macros.h. (#114446)
FE_ALL_EXCEPT macro might not be a valid preprocessor constant
expression in some environment.
Moreover, FE_ALL_EXCEPT might not be defined as int.
2024-10-31 22:24:06 -04:00
Michael Jones
3af87d4c57 [libc] Remove asm-generic includes from tests (#114479)
We shouldn't be including headers directly from asm-generic for macros.
It's safer to get those through the correct primary header where
possible (e.g. fcntl instead of asm-generic/fcntl).

For our public headers we may need to include the asm-generic
headers instead of defining all the macros ourselves, but that's
something for a followup PR.
2024-10-31 15:56:58 -07:00
Michael Jones
e241964b93 [libc] Fix macro definition hermeticity (#114467)
Previously shm_test was including <asm-generic/fcntl.h> for the macro
FD_CLOEXEC. This patch adds that macro to the list we have defined, and
redirects the test to use the correct proxy header.
2024-10-31 14:42:50 -07:00
Michael Jones
0b2b87bf34 [libc] Fix path to fcntl_overlay in cmake (#114464)
The proxy header definition for mode_t was using an incorrect form for
its dependency on fcntl_overlay. The relative paths for dependencies can
only go down, not up so "../" doesn't work. This patch fixes it to be
absolute.
2024-10-31 14:03:02 -07:00
Nick Desaulniers
8413599b59 [libc][i386] syscall support (#114264)
Link: #93709
2024-10-31 13:41:55 -07:00
lntue
296a9ba77d [libc] Fix memory leak in MPFRWrapper cospif with MPFR pre 4.2. (#114415) 2024-10-31 11:19:54 -04:00
lntue
a39fb30a49 [libc] Fix usage of std::nullptr_t in LibcTest.h. (#114321) 2024-10-30 19:08:47 -04:00
George Burgess IV
50c44478fe [libc] fix behavior of strrchr(x, '\0') (#112620)
`strrchr("foo", '\0')` is defined to point to the end of `foo`, rather
than returning NULL. This wasn't caught by tests, since llvm-libc's
`ASSERT_STREQ(nullptr, "");` is not an assertion error.

While I'm here, refactor the test slightly to check for NULL more
specifically. I considered adding fancier `ASSERT`s (and changing the
semantics of `ASSERT_STREQ`), but opted for a more local fix by fair
dice roll.
2024-10-30 15:08:03 -07:00
Michael Jones
5d35747f6d [libc] Refactor statvfs tests (#114147)
The previous statvfs tests had several issues, this patch updates them
to meet current standards.
2024-10-30 15:05:13 -07:00
Nick Desaulniers
b1320d3633 [libc][i386] setjmp/longjmp (#112437)
Link: #93709
2024-10-30 12:59:59 -07:00
George Burgess IV
b03c8c4fdd libc: strlcpy/strlcat shouldn't bzero the rest of buf (#114259)
When running Bionic's testsuite over llvm-libc, tests broke because
e.g.,

```
const char *str = "abc";
char buf[7]{"111111"};
strlcpy(buf, str, 7);
ASSERT_EQ(buf, {'1', '1', '1', '\0', '\0', '\0', '\0'});
```

On my machine (Debian w/ glibc and clang-16), a `printf` loop over `buf`
gets unrolled into a series of const `printf` at compile-time:
```
printf("%d\n", '1');
printf("%d\n", '1');
printf("%d\n", '1');
printf("%d\n", 0);
printf("%d\n", '1');
printf("%d\n", '1');
printf("%d\n", 0);
```

Seems best to match existing precedent here.
2024-10-30 12:28:32 -07:00
Nick Desaulniers
dc1ff883ca [libc][i386] define MINSIGSTKSZ & SIGSTKSZ (#114249)
Link: #93709
2024-10-30 11:56:41 -07:00
Roland McGrath
0c8e12fc64 [libc] Fix fexcept_t type to match canonical ABI and API (#113666)
In glibc and musl, fexcept_t is unsigned short int on x86 and
unsigned int on other machines that llvm-libc supports.  Match
that ABI (only different from before on x86) and API (different
everywhere as it was previously signed).
2024-10-30 10:09:34 -07:00
Alexey Samsonov
d90a0d1d98 Remove spurious includes from sinpif_test.cpp
MPFR functionality is provided by the MPFRWrapper instead, and the direct "mpfr.h" inclusion is not needed - this test doesn't rely on it (similar to its sibling libc/test/src/math/exhaustive/cospif_test.cpp that doesn't have it).
2024-10-29 16:00:08 -07:00
wldfngrs
7395ef5419 [libc][math][c23] Add cospif16 function (#113001)
Implementation of `cos` for half precision floating point inputs scaled
by pi (i.e., `cospi`), correctly rounded for all rounding modes.

---------

Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-10-29 03:39:57 -07:00
Job Henandez Lara
e873b415a2 [libc] add the rest of the hdr/fcntl_macro.h headers (#113972) 2024-10-28 18:32:45 -04:00
Job Henandez Lara
7b663bd917 [libc] Fix the remaining fcntl.h proxy header includes. (#113961) 2024-10-28 17:49:36 -04:00
Joseph Huber
03dcefe08e [libc] Fix leftover LIBC_NAMESPACE after porting it (#113960)
Summary:
There are a few of these leftover, they should all use the
`LIBC_NAMESPACE_DECL` version because that implies visibility.
2024-10-28 13:47:31 -07:00
Job Henandez Lara
abc49cc194 [libc] remove #include <fcntl.h> and add proxy or type (#113836) 2024-10-28 13:29:16 -07:00
goldsteinn
45c84d59c4 [libc] Add __builtin_expect tag on assert conditions; NFC (#99498) 2024-10-27 08:49:20 -05:00
lntue
0f4b3c409f [libc][math] Add tests and fix some issues with FTZ/DAZ modes. (#113744) 2024-10-26 10:55:20 -04:00
lntue
a879073494 [libc][math] Fix a bug in cbrt when the result is rounded to the next exponent. (#113749) 2024-10-25 22:11:07 -04:00
Roland McGrath
2e6d451d15 [libc] Use idiomatic main() function in newhdrgen/yaml_to_classes.py (#113419)
This changes the entry-point Python script of newhdrgen to use
the idiomatic main() function of no arguments that does the whole
job of the script.  This replaces the unusual pattern of having
an idiosyncratic main(...) signature and having the script's
direct code do argument parsing outside the main function.  The
idiomatic pattern makes it possible to usefully wrap the script
in Python and still use its full command-line functionality.
2024-10-24 22:17:57 -07:00
Simon Tatham
c7aff2ab4c [libc] Pass through LIBC_CONF_MATH_OPTIMIZATIONS correctly (#113540)
It's checked in a cmake function that builds up a list called
`config_options`. But the check was appending to a list called
`compile_options`, so the intended `-DLIBC_MATH=whatever` didn't end up
on the actual compile command lines.
2024-10-24 14:51:38 +01:00
Roland McGrath
100720cc4b [libc] Use if constexpr for compile-time conditionals (#113417)
Don't use plain `if` for things that are compile-time constants.
Instead, use `if constexpr`.  This both ensures that these are
properly wired up constant expressions as intended, and prevents
warnings from the compiler about useless `if` checks that look in
the source like they're meant to do something at runtime but will
just be compiled away.
2024-10-22 22:43:32 -07:00
Michael Jones
4275a73124 [libc] Fix long double is double double const (#113258)
Turns out for double double LDBL_MANT_DIG == 106. This patch fixes the
constant. Should fix the ppc buildbot.

Previously:
https://github.com/llvm/llvm-project/pull/113235
https://github.com/llvm/llvm-project/issues/113237
https://github.com/llvm/llvm-project/pull/91651
2024-10-22 07:31:57 -07:00
Guillaume Chatelet
2f58ac4a22 [libc][x86] copy one cache line at a time to prevent the use of rep;movsb (#113161)
When using `-mprefer-vector-width=128` with `-march=sandybridge` copying
3 cache lines in one go (192B) gets converted into `rep;movsb` which
translate into a 60% hit in performance.

Consecutive calls to `__builtin_memcpy_inline` (implementation behind
`builtin::Memcpy::block_offset`) are not coalesced by the compiler and
so calling it three times in a row generates the desired assembly. It
only differs in the interleaving of the loads and stores and does not
affect performance.

This is needed to reland
https://github.com/llvm/llvm-project/pull/108939.
2024-10-22 10:48:43 +02:00
Michael Jones
7eb3264413 [libc] Add handling for long double=double double (#113235)
For Hand-In-Hand we need float to string to support a wider set of
architectures, specifically the ones that libc++ supports. This includes
powerpc, which apparently uses "double double" as its long double type.
Since Hand-In-Hand isn't currently using long double, this just opts
them out.
2024-10-21 17:07:58 -07:00
Michael Jones
6c4267fb17 [libcxx][libc] Hand in Hand PoC with from_chars (#91651)
Implements std::from_chars for float and double.

The implementation uses LLVM-libc to do the real parsing. Since this is
the first time libc++
uses LLVM-libc there is a bit of additional infrastructure code. The
patch is based on the
[RFC] Project Hand In Hand (LLVM-libc/libc++ code sharing)

https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701
2024-10-21 15:04:06 -07:00
Job Henandez Lara
2ce10f0491 [libc] Remove the <string.h> header in libc/src and libc/test (#113076) 2024-10-20 09:05:41 -07:00
OverMighty
e6c01432b6 [libc][math][c23] Update newhdrgen for new _Float16 math functions (#113005) 2024-10-20 09:49:19 +02:00
Job Henandez Lara
cf4442e6b1 [libc] temporaliy disable __USE_EXTERN_INLINES and set __USE_FORITFY_LEVEL to 1 before including in overlay mode (#113012) 2024-10-18 19:41:22 -07:00
OverMighty
d97f6d1ae9 [libc][math][c23] Add sqrtf16 C23 math function (#112406)
Part of #95250.
2024-10-19 01:41:52 +02:00
OverMighty
69d3a44ede [libc][math][c23] Add log10f16 C23 math function (#106091)
Part of #95250.
2024-10-19 01:40:40 +02:00
OverMighty
6d347fdfbd [libc][math][c23] Add log2f16 C23 math function (#106084)
Part of #95250.
2024-10-19 01:10:32 +02:00
Michael Jones
0afe6e42fb [libc] Scanf shouldn't match just "0x" for hex int (#112440)
Scanf parsing reads the longest possibly valid prefix for a given
conversion. Then, it performs the conversion on that string. In the case
of "0xZ" with a hex conversion (either "%x" or "%i") the longest
possibly valid prefix is "0x", which makes it the "input item" (per the
standard). The sequence "0x" is not a "matching sequence" for a hex
conversion, meaning it results in a matching failure, and parsing ends.
This is because to know that there's no valid digit after "0x" it reads
the 'Z', but it can only put back one character (the 'Z') leaving it
with consuming an invalid sequence.

(inspired by a thread on the libc-coord mailing list: 
https://www.openwall.com/lists/libc-coord/2024/10/15/1, see 7.32.6.2 in
the standard for more details.)
2024-10-18 15:48:15 -07:00
OverMighty
65cf7afb6d [libc][math][c23] Add logf16 C23 math function (#106072)
Part of #95250.
2024-10-18 22:35:12 +02:00
lntue
952dafb08e [libc][math] Add test and fix atan2f crashing when flush-denorm-to-zero (FTZ) and denorm-as-zero (DAZ) modes are set. (#112828) 2024-10-18 14:56:23 -04:00
lntue
170dab9972 [libc][math] Fix signed zeros for powf when underflow happens. (#112601) 2024-10-18 14:26:05 -04:00
Joseph Huber
00d30bd61e [libc] Commit document formatting change someone left 2024-10-18 10:09:28 -05:00
wldfngrs
803220db43 [libc] changed the return cast from static_cast<float16> to fputil::cast<float16> in exp10f16.cpp. (#112889)
switch to fputil::cast to fix rounding with compiler-rt
2024-10-18 10:24:19 -04:00
lntue
b0dbd2ca5b [libc][math] Add option to set a specific exponent for frexp with Inf/NaN inputs. (#112387)
In IEEE 754 and C standards, when calling `frexp` with Inf/Nan inputs,
the exponent result is unspecified. In this case, FreeBSD libc and musl
just passthrough `exp`, while glibc, FreeBSD libm set exp = 0, and MSVC
set exp = -1.

By default, LLVM libc will passthrough `exp` just as FreeBSD libc and
musl, but we also allow users to explicitly choose the return exp value
in this case for compatibility with other libc.

Notice that, gcc did generate passthrough `exp` for `frexp(NaN/Inf,
exp)`: https://godbolt.org/z/sM8fEej4E
2024-10-18 09:58:15 -04:00
OverMighty
fdd7c0353f [libc][math][c23] Add tanhf16 C23 math function (#106006)
Part of #95250.
2024-10-18 14:22:45 +02:00
Shourya Goel
d508701249 [libc][complex] add additonal header guards for CFP16 and CFP128 (#112879)
Fixes build errors due to #112594
2024-10-18 16:29:07 +05:30