Commit Graph

1576 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
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
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
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
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
7b663bd917 [libc] Fix the remaining fcntl.h proxy header includes. (#113961) 2024-10-28 17:49:36 -04:00
Job Henandez Lara
abc49cc194 [libc] remove #include <fcntl.h> and add proxy or type (#113836) 2024-10-28 13:29:16 -07: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
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
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
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
7be4ab0a86 [libc][complex] Added support for CFP16 and CFP128 (#112594)
Fixes: #112217
2024-10-18 11:55:57 +05:30
OverMighty
ed3d051782 [libc][math][c23] Add sinhf16 and coshf16 C23 math functions (#105947)
Part of #95250.
2024-10-17 20:44:23 +02:00
OverMighty
95c24cb9de [libc][math][c23] Add exp10m1f16 C23 math function (#105706)
Part of #95250.
2024-10-16 16:33:13 +02:00
Joseph Huber
08ed19994b [libc] Fix incorrect RPC usage in tests 2024-10-15 18:02:26 -05:00
wldfngrs
ddc3f2dd26 [libc] Add sinpif16 function (#110994)
Half-precision floating point (16-bit) implementation of the
trigonometric function Sin for inputs scaled by pi
2024-10-15 18:40:08 -04:00
Michael Jones
87db0c0601 [libc] Add bigint casting between word types (#111914)
Previously you could cast between bigints with different numbers of
bits, but only if they had the same underlying type. This patch adds the
ability to cast between bigints with different underlying types, which
is needed for #110894
2024-10-15 11:18:38 -07:00
Aly ElAshram
76173b1b67 [libc] Add Linux mman extension remap_file_pages. (#110307)
Fixes https://github.com/llvm/llvm-project/issues/110122
- Create remap_file_pages.h/.cpp wrapper for the linux sys call.
- Add UnitTests for remap_file_pages
- Add function to libc/spec/linux.td
- Add Function spec to mman.yaml
2024-10-14 14:04:32 -07:00
Shourya Goel
f4ba6a654d [libc][complex] Set up headers and add documentation for complex.h. (#111659)
Refer: 7.3.1 from [ISO
SPEC](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)

I have added complex variants of F16 and F128 in libc doc but have
omitted support for them since we will have to first investigate how
their support matrix for clang and gcc looks like, and then add header
guards for them accordingly. Planning to add them in follow up PRs once
this gets landed.
2024-10-14 13:35:04 -04:00
OverMighty
ce65d4e974 [libc][math][c23] Add exp2m1f16 C23 math function (#105690)
Part of #95250.
2024-10-12 19:31:12 +02:00
Shourya Goel
111b062f63 [libc] Fix for adding macro I (#111872)
We have two (EDIT: 4) files in which we are using `I`. This PR replaces
them with alternatives like `i` and `IDX` etc.
2024-10-11 16:35:01 -04:00
lntue
51e9430a0c [libc][math] Improve performance of double precision trig functions. (#111793)
- Improve the accuracy of fast pass' range reduction.
- Provide tighter error estimations.
- Reduce the table size when `LIBC_MATH_SMALL_TABLES` flag is set.
2024-10-10 23:33:02 -04:00
Joseph Huber
cbfcea1fc2 [libc] Temporarily disable strerror test on NVPTX
Summary:
This is failing on the NVPTX buildbot,
https://lab.llvm.org/buildbot/#/builders/69/builds/6997/. I cannot
reproduce it locally so I'm disabling it temporarily so the bot is
green.
2024-10-10 20:20:05 -05:00
Shourya Goel
4e33afee5a [libc][math] Implement issignaling and iscanonical macro. (#111403)
#109201
2024-10-09 10:25:49 -07:00
Job Henandez Lara
46944b0cbc [libc] remove errno.h includes (#110934) 2024-10-05 19:31:36 -04:00
lntue
7a0a524653 [libc] Fix iscanonical test on aarch64 and riscv64. (#110907) 2024-10-02 14:29:56 -04:00
Michael Jones
e1d64b7662 [libc] Enable dyadic float for float printf (#110765)
Dyadic floats were an existing option for float to string conversion,
but it had become stale. This patch fixes it up as well as adding proper
config options and test support. Due to the test changes this is a
followup to #110759
2024-10-02 09:42:34 -07:00
Shourya Goel
2d784b1946 [libc][math] Implement iscanonical[f|l] as a libc math function (#110565)
This PR implements the iscanonical function as part of the libc math
library.

The addition of this function is crucial for completing the
implementation of remaining math macros, as referenced in #109201
2024-10-02 10:14:04 -04:00
Michael Jones
9c868195da [libc] clean up sprintf macros and float tests (#110759)
The sprintf tests have a macro named "ASSERT_STREQ_LEN" which was used
in about half of the tests. This patch moves all of the tests which can
to using that macro. This patch also enables long double tests for %e
and %g, since those never got finished. There's still some work to do
enabling long double testing for long doubles other than the intel 80
bit format, but that can land in a followup.

The `#ifdef LIBC_COPT_FLOAT_TO_STR_REDUCED_PRECISION` lines are for a
followup patch.
2024-10-01 16:28:41 -07:00
Michael Jones
f6b2a222be [libc] Move struct Sign into LIBC_NAMESPACE (#110709)
The struct Sign should be in the correct namespace. Also update the
various tests that use it.
2024-10-01 10:55:57 -07:00
Shourya Goel
47e3d8dc7e [libc][math] Implement issignaling[f|l] as a libc math function (#110556)
This PR implements the issignaling function as part of the libc math
library, addressing the TODO items mentioned in #110011

The addition of this function is crucial for completing the
implementation of remaining math macros, as referenced in #109201
2024-10-01 13:49:28 -04:00
lntue
c63112a911 [libc][stdio] Use proxy headers of stdio.h in src and test folders. (#110067)
https://github.com/llvm/llvm-project/issues/60481
2024-10-01 11:48:07 -04:00
lntue
cab8c87692 [libc] Fix race conditions in sprintf_test. (#110624) 2024-10-01 08:42:32 -04:00
lntue
79ecb814d0 [libc][math] Fix exceptional cases pow(-0, 1/2) and pow(-inf, 1/2). (#110566) 2024-10-01 06:37:47 -04:00
Joseph Huber
95c0e03376 [libc] Fix 'fgets' test on the GPU for some C libraries (#110118)
Summary:
The GPU handling for a lot of `FILE *` functions pretty much just
forwards it to the host via RPC. This test checks for implementation
defined behavior, which sometimes passes and sometimes doesn't. We just
disable it here so it works on the standard semantics.

We do this forwarding primarily for interopt w/ the host if the user is
compiling from an offloading language (e.g. CUDA).
2024-09-26 07:23:07 -07:00
Shourya Goel
b935d312f1 [libc][math] Reapply and fix issignaling macro. (#110011)
reapply #109615
2024-09-25 15:39:55 -04:00