171 Commits

Author SHA1 Message Date
Joseph Huber
ffed34e025 [libc] Fix getauxval being defined in a namespace 2024-06-17 19:52:06 -05:00
Joseph Huber
44ca65661e
[libc] Only include getauxval on AARCH64 targets (#95844)
Summary:
Not all platforms support this function or header, but it was being
included by every test. Move it inside of the `ifdef` for the only user,
which is aarch64.
2024-06-17 15:51:26 -05:00
Schrodinger ZHU Yifan
2efe3d7fc0
Reland "[libc] fix aarch64 linux full build (#95358)" (#95423)
Reverts llvm/llvm-project#95419 and Reland #95358.

This PR is full of temporal fixes. After a discussion with @lntue, it is
better to avoid further changes to the cmake infrastructure for now as a
rework to the cmake utilities will be landed in the future.
2024-06-13 20:34:32 -07:00
OverMighty
f5dcfb9968
[libc][math][c23] Add {totalorder,totalordermag}f16 C23 math functions (#95014)
Part of #93566.
2024-06-11 11:04:48 -04:00
Nick Desaulniers (paternity leave)
6f576d957e
[libc] android atest compat (#93852)
These changes slighly modify the output of the unittests so that they better
match GTest, so that utilities that parse the expected output from GTest (such
as Android's unit test harness) can read the output from our unit tests.

This allows our unit tests to be run on Android devices.

Add very primitive command line parsing to:
- support --gtest_color=no to disable printing terminal colors.
- recognize --gtest_print_time and print the test time in milliseconds.
  - most of our unit tests run on the order of microseconds, so its useful to
    preserve the existing behavior.  But upsteram GTest ONLY prints time tests
    in milliseconds, and Android's atest expects to be able to parse exactly
    that. Atest always passes --gtest_print_time. The word `took` is removed as
    that also differs from upstream GTest, tripping up parsers.
- ignore other --gtest_* flags

Do so so that atest can parse the output correctly.

Print the test number count before
each run, so that atest can parse this value correctly.

Link: https://android-review.googlesource.com/c/platform/external/llvm-libc/+/3107252
Link: https://google.github.io/googletest/advanced.html#colored-terminal-output
Link: https://google.github.io/googletest/advanced.html#suppressing-the-elapsed-time
2024-05-30 13:28:11 -07:00
Michael Flanders
ecfb5d9951
[libc][math] fix loose except check in {EXPECT,ASSERT}_FP_EXCEPTION macros (#88816)
Adds more FP test macros for the upcoming test adds for #61092 and the
issues opened from it: #88768, #88769, #88770, #88771, #88772.

Fix bug in `{EXPECT,ASSERT}_FP_EXCEPTION`. `EXPECT_FP_EXCEPTION(0)`
seems to be used to test that an exception did not happen, but it always
does `EXPECT_GE(... & 0, 0)` which never fails.

Update and refactor tests that break after the above bug fix. An
interesting way things broke after the above change is that
`ForceRoundingMode` and `quick_get_round()` were raising the inexact
exception, breaking a lot of the `atan*` tests.

The changes for all files other than `FPMatcher.h` and
`libc/test/src/math/smoke/RoundToIntegerTest.h` should have the same
semantics as before. For `RoundToIntegerTest.h`, lines 56-58 before the
changes do not always hold since this test is used for functions with
different exception and errno behavior like `lrint` and `lround`. I've
deleted those lines for now, but tests for those cases should be added
for the different nearest int functions to account for this.

Adding @nickdesaulniers for review.
2024-05-06 09:05:22 -04:00
Michael Flanders
5e9937d1b3
[libc][math] Adds entrypoint and tests for nearbyintf128,scalbnf128 (#88443)
Closes #84689.

Adding @lntue for review.

I was curious about the implementation of
`round_using_current_rounding_mode` used for the `nearbyint` functions.
It has one of the rounding modes as unreachable
([here](https://github.com/llvm/llvm-project/blob/main/libc/src/__support/FPUtil/NearestIntegerOperations.h#L243)),
and I was wondering if this was okay for the `nearbyint` functions.

---------

Co-authored-by: Michael Flanders <mkf727@cs.washington.edu>
2024-04-29 19:25:45 -04:00
Roland McGrath
859de94536
[libc] Fix aarch64 build error in FEnvSafeTest change (#89826) 2024-04-23 13:50:55 -07:00
Roland McGrath
837dab96d6
[libc] Make fenv and math tests preserve fenv_t state (#89658)
This adds a new test fixture class FEnvSafeTest (usable as a base
class for other fixtures) that ensures each test doesn't perturb
the `fenv_t` state that the next test will start with.  It also
provides types and methods tests can use to explicitly wrap code
under test either to check that it doesn't perturb the state or
to save and restore the state around particular test code.

All the fenv and math tests are updated to use this so that none
can affect another.  Expectations that code under test and/or
tests themselves don't perturb state can be added later.
2024-04-23 13:21:25 -07:00
Roland McGrath
d2be9826dd
[libc] Clean up alternate test framework support (#89659)
This replaces the old macros LIBC_COPT_TEST_USE_FUCHSIA and
LIBC_COPT_TEST_USE_PIGWEED with LIBC_COPT_TEST_ZXTEST and
LIBC_COPT_TEST_GTEST, respectively.  These are really not about
whether the code is in the Fuchsia build or in the Pigweed build,
but just about what test framework is being used.  The gtest
framework can be used in many contexts, and the zxtest framework
is not always what's used in the Fuchsia build.

The test/UnitTest/Test.h wrapper header now provides the macro
LIBC_TEST_HAS_MATCHERS() for use in `#if` conditionals on use of
gmock-style matchers, replacing `#if` conditionals that test the
framework selection macros directly.
2024-04-22 15:18:02 -07:00
Job Henandez Lara
75bbf4dd7c
[libc] Add proxy headers for fenv types. (#88467)
Fixes #88187
2024-04-15 11:45:16 -07:00
Job Henandez Lara
49561181bd
[libc] Add proxy header for fenv.h macro constants. #87863 (#87896)
Hello, this addresses #87863.
2024-04-09 12:55:10 -04:00
lntue
312b9297bb
[libc] Increase timeout for death tests. (#87959)
Fix test timeout on RISCV bots.
Fixes https://github.com/llvm/llvm-project/issues/87096
2024-04-08 11:31:07 -04:00
Guillaume Chatelet
09efe848cf
[libc][NFC] Rename UInt.h to big_int.h and UInt128.h to uint128.h for consistency (#87808) 2024-04-06 10:39:55 +02:00
lntue
5748ad84e5
[libc] Add proxy header math_macros.h. (#87598)
Context: https://github.com/llvm/llvm-project/pull/87017

- Add proxy header `libc/hdr/math_macros.h` that will:
  - include `<math.h>` in overlay mode,
- include `"include/llvm-libc-macros/math-macros.h"` in full build mode.
- Its corresponding CMake target `libc.hdr.math_macros` will only depend
on `libc.include.math` and `libc.include.llvm-libc-macros.math_macros`
in full build mode.
- Replace all `#include "include/llvm-libc-macros/math-macros.h"` with
`#include "hdr/math_macros.h"`.
- Add dependency to `libc.hdr.math_macros` CMake target when using
`add_fp_unittest`.
- Update the remaining dependency.
- Update bazel overlay: add `libc:hdr_math_macros` target, and replacing
all dependency on `libc:llvm_libc_macros_math_macros` with
`libc:hdr_math_macros`.
2024-04-05 18:21:16 -04:00
Om Prakaash
fdef5c4f45
Add bit width length modifier to printf (#82461)
Resolves #81685. This adds support for wN and wfN length modifiers in
fprintf.
2024-03-29 10:15:22 -07:00
OverMighty
b282259711
[libc][math][c23] Add {,u}fromfp{,x}{,f,l,f128} functions (#86003)
Fixes #85279.

cc @lntue
2024-03-25 10:26:22 -04:00
Guillaume Chatelet
2137894a6f
[libc][NFC] Move Sign type to separate header (#85930) 2024-03-20 15:10:19 +01:00
Michael Jones
5d56b34807
[libc] Remove direct math.h includes (#85324)
Reland of #84991

A downstream overlay mode user ran into issues with the isnan macro not
working in our sources with a specific libc configuration. This patch
replaces the last direct includes of math.h with our internal
math_macros.h, along with the necessary build system changes.
2024-03-18 14:19:33 -07:00
OverMighty
8ff96eb100
[libc][math][c23] Add nextup{,f,f128} and nextdown{,f,f128} functions (#85431)
See https://github.com/llvm/llvm-project/issues/85283.

I had a test for `nextdownl` that was failing and I thought I should add
`nextupl` and `nextdownl` later and first make a PR for the other
functions.

cc @lntue
2024-03-15 16:46:48 -04:00
Guillaume Chatelet
23c397c7c9
[libc] Provide LIBC_TYPES_HAS_INT128 (#84149)
Umbrella bug #83182
2024-03-08 16:06:56 +01:00
Guillaume Chatelet
6a8e6c9a31
[libc][NFC] Move BigInt out of the cpp namespace (#84445)
As noted in
https://github.com/llvm/llvm-project/pull/84035#discussion_r1516817755
only files under the CPP folder should be in the `cpp` namespace.
2024-03-08 09:41:23 +01:00
Guillaume Chatelet
c103d573e7
[libc] Fix forward missing BigInt specialization of mask_leading_ones / mask_trailing_ones (#84325)
#84299 broke the arm32 build, this patch fixes it forward.
2024-03-07 20:00:05 +01:00
Guillaume Chatelet
245d669f1d
[reland][libc] Remove UB specializations of type traits for BigInt (#84299)
Note: This is a reland of #84035.

The standard specifies that it it UB to specialize the following traits:
 - `std::is_integral`
 - `std::is_unsigned`
 - `std::make_unsigned`
 - `std::make_signed`

This patch:
 - Removes specializations for `BigInt`
 - Transforms SFINAE for `bit.h` functions from template parameter to
   return type (This makes specialization easier).
 - Adds `BigInt` specialization for `bit.h` functions.
 - Fixes code depending on previous specializations.
2024-03-07 11:41:35 +01:00
Guillaume Chatelet
27844cb2fa
Revert "[libc] Remove UB specializations of type traits for BigInt" (#84297)
Reverts llvm/llvm-project#84035

Several bots are failing:
 - https://lab.llvm.org/buildbot/#/builders/223/builds/37522
 - https://lab.llvm.org/buildbot/#/builders/162/builds/51978
 - https://lab.llvm.org/buildbot/#/builders/163/builds/52560
 - https://lab.llvm.org/buildbot/#/builders/250/builds/19619
2024-03-07 11:06:50 +01:00
Guillaume Chatelet
84f483dbee
[libc] Remove UB specializations of type traits for BigInt (#84035)
The standard specifies that it it UB to specialize the following traits:
 - `std::is_integral`
 - `std::is_unsigned`
 - `std::make_unsigned`
 - `std::make_signed`

This patch:
 - Removes specializations for `BigInt`
 - Transforms SFINAE for `bit.h` functions from template parameter to
   return type (This makes specialization easier).
 - Adds `BigInt` specialization for `bit.h` functions.
 - Fixes code depending on previous specializations.
2024-03-07 11:01:09 +01:00
lntue
73aab2f697
[libc] Revert https://github.com/llvm/llvm-project/pull/83199 since it broke Fuchsia. (#83374)
With some header fix forward for GPU builds.
2024-02-29 14:43:53 -05:00
Nick Desaulniers
330793c91d
[libc] fix clang-tidy llvm-header-guard warnings (#82679)
Towards the goal of getting `ninja libc-lint` back to green, fix the numerous
instances of:

    warning: header guard does not follow preferred style [llvm-header-guard]

This is because many of our header guards start with `__LLVM` rather than
`LLVM`.

To filter just these warnings:

    $ ninja -k2000 libc-lint 2>&1 | grep llvm-header-guard

To automatically apply fixits:

    $ find libc/src libc/include libc/test -name \*.h | \
        xargs -n1 -I {} clang-tidy {} -p build/compile_commands.json \
        -checks='-*,llvm-header-guard' --fix --quiet

Some manual cleanup is still necessary as headers that were missing header
guards outright will have them inserted before the license block (we prefer
them after).
2024-02-28 12:53:56 -08:00
Joseph Huber
04e8653f18
[libc] Add "include/" to the LLVM include directories (#83199)
Summary:
Recent changes added an include path in the float128 type that used the
internal `libc` path to find the macro. This doesn't work once it's
installed because we need to search from the root of the install dir.
This patch adds "include/" to the include path so that our inclusion
of installed headers always match the internal use.
2024-02-27 17:45:15 -06:00
Joseph Huber
47b7c91abe
[libc] Rework the GPU build to be a regular target (#81921)
Summary:
This is a massive patch because it reworks the entire build and
everything that depends on it. This is not split up because various bots
would fail otherwise. I will attempt to describe the necessary changes
here.

This patch completely reworks how the GPU build is built and targeted.
Previously, we used a standard runtimes build and handled both NVPTX and
AMDGPU in a single build via multi-targeting. This added a lot of
divergence in the build system and prevented us from doing various
things like building for the CPU / GPU at the same time, or exporting
the startup libraries or running tests without a full rebuild.

The new appraoch is to handle the GPU builds as strict cross-compiling
runtimes. The first step required
https://github.com/llvm/llvm-project/pull/81557 to allow the `LIBC`
target to build for the GPU without touching the other targets. This
means that the GPU uses all the same handling as the other builds in
`libc`.

The new expected way to build the GPU libc is with
`LLVM_LIBC_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda`.

The second step was reworking how we generated the embedded GPU library
by moving it into the library install step. Where we previously had one
`libcgpu.a` we now have `libcgpu-amdgpu.a` and `libcgpu-nvptx.a`. This
patch includes the necessary clang / OpenMP changes to make that not
break the bots when this lands.

We unfortunately still require that the NVPTX target has an `internal`
target for tests. This is because the NVPTX target needs to do LTO for
the provided version (The offloading toolchain can handle it) but cannot
use it for the native toolchain which is used for making tests.

This approach is vastly superior in every way, allowing us to treat the
GPU as a standard cross-compiling target. We can now install the GPU
utilities to do things like use the offload tests and other fun things.

Some certain utilities need to be built with 
`--target=${LLVM_HOST_TRIPLE}` as well. I think this is a fine
workaround as we
will always assume that the GPU `libc` is a cross-build with a
functioning host.

Depends on https://github.com/llvm/llvm-project/pull/81557
2024-02-22 15:29:29 -06:00
Joseph Huber
5454991c29
[libc] Cleanup of hermetic test flag handling (#82384)
Summary:
This cleans up the handling of hermetic test flags. Primarily done to
simplify the GPU rework patch.
2024-02-20 12:23:48 -06:00
Michael Jones
d0c2c0ab6d
[libc] Move compile options to new cmake file (#81917)
The cmake test generator needed to be updated to support the same flags
as the source. To simplify the code, I moved it to a new file.
2024-02-15 16:07:21 -08:00
lntue
82a4a41614
[libc][stdfix] Add support for fixed point types in the testing infrastructure. (#81819) 2024-02-15 14:55:20 -05:00
lntue
271e07321b
[libc] Fix fixed point detection and add compile option. (#81788) 2024-02-14 17:12:51 -05:00
michaelrj-google
3eb1e6d8e9
[libc] Move libc_errno inside of LIBC_NAMESPACE (#80774)
Having libc_errno outside of the namespace causes versioning issues when
trying to link the tests against LLVM-libc. Most of this patch is just
moving libc_errno inside the namespace in tests. This isn't necessary in
the function implementations since those are already inside the
namespace.
2024-02-06 10:36:05 +01:00
Guillaume Chatelet
ace383df52
[libc][NFC] Rename FPBits nan functions (#79998)
- [libc][NFC] Rename FPBits nan functions
- rename build_signaling_nan in signaling_nan
- rename build_quiet_nan to quiet_nan
2024-01-30 15:01:27 +01:00
Guillaume Chatelet
eb56bc2b10
[libc] Remove specific nan payload in math functions (#79165) 2024-01-29 15:28:46 +01:00
Caslyn Tonelli
6f97e6bcf7
[fuchsia][libc] Include missing macro definitions (#79639)
PR 79573 introduced `ASSERT_ERRNO_*` macros for use in libc tests.
Introduce these macro definitions to FuchsiaTest.h for string tests to
compile on Fuchsia.
2024-01-26 13:20:57 -08:00
Guillaume Chatelet
73874f7a39
[libc][NFC] Use specific ASSERT macros to test errno (#79573)
This patch provides specific test macros to deal with `errno`.
This will help abstract away the differences between unit test and integration/hermetic tests in #79319.
In one case we use `libc_errno` which is a struct, in the other case we deal directly with `errno`.
2024-01-26 15:18:22 +01:00
Guillaume Chatelet
2856db0d3b
[libc][NFC] Remove FPBits cast operator (#79142)
The semantics for casting can range from "bitcast" (same representation)
to "different representation", to "type promotion". Here we remove the
cast operator and force usage of `get_val` as the only function to get
the floating point value, making the intent clearer and more consistent.
2024-01-23 17:30:19 +01:00
Schrodinger ZHU Yifan
2cff46f8c0
[libc][NFC] use builder pattern for ErrnoSetterMatcher (#79153)
ErrnoSetterMatcher::returns can be misleading as it does not initialize
the errno. This is made worse as later on there is a switch statement on
the errno comparator using __builtin_unreachable(). This patch make
ErrnoSetterMatcher::returns give back a builder that is nomially
different from ErrnoSetterMatcher.
2024-01-23 10:43:24 -05:00
Guillaume Chatelet
dffa8039b1
[libc] Remove specific nan payload in math functions (#79133) 2024-01-23 16:37:36 +01:00
Guillaume Chatelet
6b02d2f863
[reland][libc] Remove unnecessary FPBits functions and properties (#79128)
- reland #79113
- Fix aarch64 RISC-V build
2024-01-23 13:48:03 +01:00
Guillaume Chatelet
b524eed925
Revert "[libc] Remove unnecessary FPBits functions and properties" (#79118)
Reverts llvm/llvm-project#79113
It broke aarch64 build bot machines.
2024-01-23 11:51:18 +01:00
Guillaume Chatelet
3bc86bf3bf
[libc] Remove unnecessary FPBits functions and properties (#79113)
This patch reduces the surface of `FPBits`.
2024-01-23 11:48:28 +01:00
lntue
029bfd6329
[libc] Replace -nostdlib++ flag when building with gcc and add placement new operator to HermeticTestUtils.cpp. (#78906)
`-nostdlib++` is a clang-only flag. Replacing it with `-nostdlib` when
building with gcc.
2024-01-22 19:27:27 -05:00
Guillaume Chatelet
11ec512f44
[libc][NFC] Introduce a Sign type for FPBits (#78500)
Another patch is needed to cover `DyadicFloat` and `NormalFloat`
constructors.
2024-01-18 13:40:49 +01:00
michaelrj-google
b932f03bda
[libc] Disable Death Tests While Hermetic (#77388)
The death test infrastructure seems to depend on operator new, which
isn't currently supported in our hermetic tests. This patch just
disables the death tests in hermetic mode since they only overlap in the
nan tests.
2024-01-09 15:04:22 -08:00
Guillaume Chatelet
57fcc23896
[libc] Fix improper initialization of StorageType (#75610)
`StorageType` may be a `BigInt` under the hood. Initializing it with
`-1` does not yields the maximum value.
2023-12-15 15:51:10 +01:00
Guillaume Chatelet
3546f4da19
[libc][NFC] Rename MANTISSA_WIDTH in FRACTION_LEN (#75489)
This one might be a bit controversial since the terminology has been
introduced from the start but I think `FRACTION_LEN` is a better name
here. AFAICT it really is "the number of bits after the decimal dot when
the number is in normal form."

`MANTISSA_WIDTH` is less precise as it's unclear whether we take the
leading bit into account.
This patch also renames most of the properties to use the `_LEN` suffix
and fixes useless casts or variables.
2023-12-15 13:57:35 +01:00