diff options
author | LLVM libc <llvm-libc@google.com> | 2024-04-12 23:33:35 +0200 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-04-12 16:15:14 -0700 |
commit | 33e5bf0487e3fb4aa2ce10ef98f1d4d22c1f5146 (patch) | |
tree | ee9f90a0dc321a7080e651ee45ebcce3a5a00454 | |
parent | 3476d15c257337134fd781b0943453fbc585acb1 (diff) | |
download | llvm-libc-33e5bf0487e3fb4aa2ce10ef98f1d4d22c1f5146.tar.gz |
Project import generated by Copybara.
GitOrigin-RevId: 900be9013fdc3bab9fce906f8a71e59ecd8873b4
Change-Id: I8609a042535f410747b4903f2de82e4de8ffebec
223 files changed, 1002 insertions, 458 deletions
diff --git a/include/llvm-libc-macros/linux/sys-epoll-macros.h b/include/llvm-libc-macros/linux/sys-epoll-macros.h new file mode 100644 index 000000000000..f73d690908fd --- /dev/null +++ b/include/llvm-libc-macros/linux/sys-epoll-macros.h @@ -0,0 +1,40 @@ +//===-- Macros defined in sys/epoll.h header file -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H + +#include "fcntl-macros.h" + +// These are also defined in <linux/eventpoll.h> but that also contains a +// different definition of the epoll_event struct that is different from the +// userspace version. + +#define EPOLL_CLOEXEC O_CLOEXEC + +#define EPOLL_CTL_ADD 1 +#define EPOLL_CTL_DEL 2 +#define EPOLL_CTL_MOD 3 + +#define EPOLLIN 0x1 +#define EPOLLPRI 0x2 +#define EPOLLOUT 0x4 +#define EPOLLERR 0x8 +#define EPOLLHUP 0x10 +#define EPOLLRDNORM 0x40 +#define EPOLLRDBAND 0x80 +#define EPOLLWRNORM 0x100 +#define EPOLLWRBAND 0x200 +#define EPOLLMSG 0x400 +#define EPOLLRDHUP 0x2000 +#define EPOLLEXCLUSIVE 0x10000000 +#define EPOLLWAKEUP 0x20000000 +#define EPOLLONESHOT 0x40000000 +#define EPOLLET 0x80000000 + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H diff --git a/include/llvm-libc-macros/math-macros.h b/include/llvm-libc-macros/math-macros.h index 6046ea98cb8a..47838969d59a 100644 --- a/include/llvm-libc-macros/math-macros.h +++ b/include/llvm-libc-macros/math-macros.h @@ -9,11 +9,6 @@ #ifndef LLVM_LIBC_MACROS_MATH_MACROS_H #define LLVM_LIBC_MACROS_MATH_MACROS_H -// TODO: Remove this. This is a temporary fix for a downstream problem. -// This cannot be left permanently since it would require downstream users to -// define this macro. -#ifdef LIBC_FULL_BUILD - #include "limits-macros.h" #define FP_NAN 0 @@ -56,38 +51,9 @@ #define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT) #endif -// These must be type-generic functions. The C standard specifies them as -// being macros rather than functions, in fact. However, in C++ it's important -// that there be function declarations that don't interfere with other uses of -// the identifier, even in places with parentheses where a function-like macro -// will be expanded (such as a function declaration in a C++ namespace). - -#ifdef __cplusplus - -template <typename T> inline constexpr bool isfinite(T x) { - return __builtin_isfinite(x); -} - -template <typename T> inline constexpr bool isinf(T x) { - return __builtin_isinf(x); -} - -template <typename T> inline constexpr bool isnan(T x) { - return __builtin_isnan(x); -} - -#else - +// TODO: Move generic functional math macros to a separate header file. #define isfinite(x) __builtin_isfinite(x) #define isinf(x) __builtin_isinf(x) #define isnan(x) __builtin_isnan(x) -#endif - -#else // LIBC_FULL_BUILD - -#include <math.h> - -#endif // LIBC_FULL_BUILD - #endif // LLVM_LIBC_MACROS_MATH_MACROS_H diff --git a/include/llvm-libc-macros/sys-epoll-macros.h b/include/llvm-libc-macros/sys-epoll-macros.h new file mode 100644 index 000000000000..8212df252b8e --- /dev/null +++ b/include/llvm-libc-macros/sys-epoll-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/epoll.h header file -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_SYS_EPOLL_MACROS_H +#define LLVM_LIBC_MACROS_SYS_EPOLL_MACROS_H + +#ifdef __linux__ +#include "linux/sys-epoll-macros.h" +#endif + +#endif // LLVM_LIBC_MACROS_SYS_EPOLL_MACROS_H diff --git a/include/llvm-libc-types/sigset_t.h b/include/llvm-libc-types/sigset_t.h index 311a92b823ff..5c3e4e6f0431 100644 --- a/include/llvm-libc-types/sigset_t.h +++ b/include/llvm-libc-types/sigset_t.h @@ -13,8 +13,8 @@ // This definition can be adjusted/specialized for different targets and // platforms as necessary. This definition works for Linux on most targets. -typedef struct { +struct sigset_t { unsigned long __signals[__NSIGSET_WORDS]; -} sigset_t; +}; #endif // LLVM_LIBC_TYPES_SIGSET_T_H diff --git a/include/llvm-libc-types/struct_epoll_event.h b/include/llvm-libc-types/struct_epoll_event.h index 66cf86c1e2a0..b7685df20bd7 100644 --- a/include/llvm-libc-types/struct_epoll_event.h +++ b/include/llvm-libc-types/struct_epoll_event.h @@ -11,7 +11,11 @@ #include "llvm-libc-types/struct_epoll_data.h" -typedef struct epoll_event { +typedef struct +#ifdef __x86_64__ + [[gnu::packed]] // Necessary for compatibility. +#endif + epoll_event { __UINT32_TYPE__ events; epoll_data_t data; } epoll_event; diff --git a/libc/hdr/fenv_macros.h b/libc/hdr/fenv_macros.h new file mode 100644 index 000000000000..1ad28cc278a9 --- /dev/null +++ b/libc/hdr/fenv_macros.h @@ -0,0 +1,22 @@ +//===-- Definition of macros from fenv.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_HDR_FENV_MACROS_H +#define LLVM_LIBC_HDR_FENV_MACROS_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-macros/fenv-macros.h" + +#else // Overlay mode + +#include <fenv.h> + +#endif // LLVM_LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_FENV_MACROS_H diff --git a/libc/hdr/math_macros.h b/libc/hdr/math_macros.h new file mode 100644 index 000000000000..d13c5ff7647a --- /dev/null +++ b/libc/hdr/math_macros.h @@ -0,0 +1,43 @@ +//===-- Definition of macros from math.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_HDR_MATH_MACROS_H +#define LLVM_LIBC_HDR_MATH_MACROS_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-macros/math-macros.h" + +#else // Overlay mode + +#include <math.h> + +// Some older math.h header does not have FP_INT_* constants yet. +#ifndef FP_INT_UPWARD +#define FP_INT_UPWARD 0 +#endif // FP_INT_UPWARD + +#ifndef FP_INT_DOWNWARD +#define FP_INT_DOWNWARD 1 +#endif // FP_INT_DOWNWARD + +#ifndef FP_INT_TOWARDZERO +#define FP_INT_TOWARDZERO 2 +#endif // FP_INT_TOWARDZERO + +#ifndef FP_INT_TONEARESTFROMZERO +#define FP_INT_TONEARESTFROMZERO 3 +#endif // FP_INT_TONEARESTFROMZERO + +#ifndef FP_INT_TONEAREST +#define FP_INT_TONEAREST 4 +#endif // FP_INT_TONEAREST + +#endif // LLVM_LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_MATH_MACROS_H diff --git a/libc/hdr/signal_macros.h b/libc/hdr/signal_macros.h new file mode 100644 index 000000000000..867d17a4ca8c --- /dev/null +++ b/libc/hdr/signal_macros.h @@ -0,0 +1,22 @@ +//===-- Definition of macros from signal.h --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_HDR_SIGNAL_MACROS_H +#define LLVM_LIBC_HDR_SIGNAL_MACROS_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-macros/signal-macros.h" + +#else // Overlay mode + +#include <signal.h> + +#endif // LLVM_LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_SIGNAL_MACROS_H diff --git a/libc/hdr/sys_epoll_macros.h b/libc/hdr/sys_epoll_macros.h new file mode 100644 index 000000000000..db047f161634 --- /dev/null +++ b/libc/hdr/sys_epoll_macros.h @@ -0,0 +1,22 @@ +//===-- Definition of macros from sys/epoll.h -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_HDR_SYS_EPOLL_MACROS_H +#define LLVM_LIBC_HDR_SYS_EPOLL_MACROS_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-macros/sys-epoll-macros.h" + +#else // Overlay mode + +#include <sys/epoll.h> + +#endif // LLVM_LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_SYS/EPOLL_MACROS_H diff --git a/libc/hdr/types/sigset_t.h b/libc/hdr/types/sigset_t.h new file mode 100644 index 000000000000..695ec3029f68 --- /dev/null +++ b/libc/hdr/types/sigset_t.h @@ -0,0 +1,21 @@ +//===-- Proxy for sigset_t ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_HDR_TYPES_SIGSET_T_H +#define LLVM_LIBC_HDR_TYPES_SIGSET_T_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-types/sigset_t.h" + +#else + +#include <signal.h> + +#endif // LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_TYPES_SIGSET_T_H diff --git a/libc/hdr/types/struct_epoll_event.h b/libc/hdr/types/struct_epoll_event.h new file mode 100644 index 000000000000..5bb98ce05bb2 --- /dev/null +++ b/libc/hdr/types/struct_epoll_event.h @@ -0,0 +1,21 @@ +//===-- Proxy for struct epoll_event --------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_EPOLL_EVENT_H +#define LLVM_LIBC_HDR_TYPES_STRUCT_EPOLL_EVENT_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-types/struct_epoll_event.h" + +#else + +#include <sys/epoll.h> + +#endif // LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_TYPES_STRUCT_EPOLL_EVENT_H diff --git a/libc/hdr/types/struct_timespec.h b/libc/hdr/types/struct_timespec.h new file mode 100644 index 000000000000..1f121f3d24d8 --- /dev/null +++ b/libc/hdr/types/struct_timespec.h @@ -0,0 +1,21 @@ +//===-- Proxy for struct timespec ----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_TIMESPEC_H +#define LLVM_LIBC_HDR_TYPES_STRUCT_TIMESPEC_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-types/struct_timespec.h" + +#else + +#include <time.h> + +#endif // LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_TYPES_STRUCT_TIMESPEC_H diff --git a/src/__support/CPP/bit.h b/src/__support/CPP/bit.h index 80f50fd221ef..8a8951a18bfa 100644 --- a/src/__support/CPP/bit.h +++ b/src/__support/CPP/bit.h @@ -72,6 +72,14 @@ has_single_bit(T value) { /// Only unsigned integral types are allowed. /// /// Returns cpp::numeric_limits<T>::digits on an input of 0. +// clang-19+, gcc-14+ +#if __has_builtin(__builtin_ctzg) +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +countr_zero(T value) { + return __builtin_ctzg(value, cpp::numeric_limits<T>::digits); +} +#else template <typename T> [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> countr_zero(T value) { @@ -99,6 +107,7 @@ ADD_SPECIALIZATION(countr_zero, unsigned short, __builtin_ctzs) ADD_SPECIALIZATION(countr_zero, unsigned int, __builtin_ctz) ADD_SPECIALIZATION(countr_zero, unsigned long, __builtin_ctzl) ADD_SPECIALIZATION(countr_zero, unsigned long long, __builtin_ctzll) +#endif // __has_builtin(__builtin_ctzg) /// Count number of 0's from the most significant bit to the least /// stopping at the first 1. @@ -106,6 +115,14 @@ ADD_SPECIALIZATION(countr_zero, unsigned long long, __builtin_ctzll) /// Only unsigned integral types are allowed. /// /// Returns cpp::numeric_limits<T>::digits on an input of 0. +// clang-19+, gcc-14+ +#if __has_builtin(__builtin_clzg) +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +countl_zero(T value) { + return __builtin_clzg(value, cpp::numeric_limits<T>::digits); +} +#else template <typename T> [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> countl_zero(T value) { @@ -129,6 +146,7 @@ ADD_SPECIALIZATION(countl_zero, unsigned short, __builtin_clzs) ADD_SPECIALIZATION(countl_zero, unsigned int, __builtin_clz) ADD_SPECIALIZATION(countl_zero, unsigned long, __builtin_clzl) ADD_SPECIALIZATION(countl_zero, unsigned long long, __builtin_clzll) +#endif // __has_builtin(__builtin_clzg) #undef ADD_SPECIALIZATION diff --git a/src/__support/FPUtil/BasicOperations.h b/src/__support/FPUtil/BasicOperations.h index 6e4156497618..e5ac101fedc0 100644 --- a/src/__support/FPUtil/BasicOperations.h +++ b/src/__support/FPUtil/BasicOperations.h @@ -14,9 +14,9 @@ #include "FEnvImpl.h" #include "src/__support/CPP/type_traits.h" -#include "src/__support/UInt128.h" #include "src/__support/common.h" #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY +#include "src/__support/uint128.h" namespace LIBC_NAMESPACE { namespace fputil { diff --git a/src/__support/FPUtil/FEnvImpl.h b/src/__support/FPUtil/FEnvImpl.h index 6086d5d3de2d..4be1a57f0f4b 100644 --- a/src/__support/FPUtil/FEnvImpl.h +++ b/src/__support/FPUtil/FEnvImpl.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/macros/attributes.h" // LIBC_INLINE #include "src/__support/macros/properties/architectures.h" #include "src/errno/libc_errno.h" diff --git a/src/__support/FPUtil/FPBits.h b/src/__support/FPUtil/FPBits.h index 155bff2f5581..ab050360c353 100644 --- a/src/__support/FPUtil/FPBits.h +++ b/src/__support/FPUtil/FPBits.h @@ -11,13 +11,13 @@ #include "src/__support/CPP/bit.h" #include "src/__support/CPP/type_traits.h" -#include "src/__support/UInt128.h" #include "src/__support/common.h" #include "src/__support/libc_assert.h" // LIBC_ASSERT #include "src/__support/macros/attributes.h" // LIBC_INLINE, LIBC_INLINE_VAR #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128 #include "src/__support/math_extras.h" // mask_trailing_ones #include "src/__support/sign.h" // Sign +#include "src/__support/uint128.h" #include <stdint.h> diff --git a/src/__support/FPUtil/Hypot.h b/src/__support/FPUtil/Hypot.h index 2e6996573464..76b1f0797621 100644 --- a/src/__support/FPUtil/Hypot.h +++ b/src/__support/FPUtil/Hypot.h @@ -15,8 +15,8 @@ #include "rounding_mode.h" #include "src/__support/CPP/bit.h" #include "src/__support/CPP/type_traits.h" -#include "src/__support/UInt128.h" #include "src/__support/common.h" +#include "src/__support/uint128.h" namespace LIBC_NAMESPACE { namespace fputil { diff --git a/src/__support/FPUtil/ManipulationFunctions.h b/src/__support/FPUtil/ManipulationFunctions.h index 2c90b4888c2e..a289c2ef7046 100644 --- a/src/__support/FPUtil/ManipulationFunctions.h +++ b/src/__support/FPUtil/ManipulationFunctions.h @@ -15,7 +15,7 @@ #include "dyadic_float.h" #include "rounding_mode.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/bit.h" #include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN #include "src/__support/CPP/type_traits.h" diff --git a/src/__support/FPUtil/NearestIntegerOperations.h b/src/__support/FPUtil/NearestIntegerOperations.h index 6b28e7ffb387..4645ab0b5350 100644 --- a/src/__support/FPUtil/NearestIntegerOperations.h +++ b/src/__support/FPUtil/NearestIntegerOperations.h @@ -13,7 +13,7 @@ #include "FPBits.h" #include "rounding_mode.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/type_traits.h" #include "src/__support/common.h" diff --git a/src/__support/FPUtil/aarch64/FEnvImpl.h b/src/__support/FPUtil/aarch64/FEnvImpl.h index e0eec17e038c..4b593cdd8cc4 100644 --- a/src/__support/FPUtil/aarch64/FEnvImpl.h +++ b/src/__support/FPUtil/aarch64/FEnvImpl.h @@ -20,6 +20,7 @@ #include <fenv.h> #include <stdint.h> +#include "hdr/fenv_macros.h" #include "src/__support/FPUtil/FPBits.h" namespace LIBC_NAMESPACE { diff --git a/src/__support/FPUtil/aarch64/fenv_darwin_impl.h b/src/__support/FPUtil/aarch64/fenv_darwin_impl.h index fd915373020e..773d6bfe9f89 100644 --- a/src/__support/FPUtil/aarch64/fenv_darwin_impl.h +++ b/src/__support/FPUtil/aarch64/fenv_darwin_impl.h @@ -20,6 +20,7 @@ #include <fenv.h> #include <stdint.h> +#include "hdr/fenv_macros.h" #include "src/__support/FPUtil/FPBits.h" namespace LIBC_NAMESPACE { diff --git a/src/__support/FPUtil/arm/FEnvImpl.h b/src/__support/FPUtil/arm/FEnvImpl.h index ac4673cf20f6..ddb0edcf8278 100644 --- a/src/__support/FPUtil/arm/FEnvImpl.h +++ b/src/__support/FPUtil/arm/FEnvImpl.h @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_ARM_FENVIMPL_H #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_ARM_FENVIMPL_H +#include "hdr/fenv_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/macros/attributes.h" // For LIBC_INLINE - #include <fenv.h> #include <stdint.h> diff --git a/src/__support/FPUtil/dyadic_float.h b/src/__support/FPUtil/dyadic_float.h index e0c205f52383..12a69228d36c 100644 --- a/src/__support/FPUtil/dyadic_float.h +++ b/src/__support/FPUtil/dyadic_float.h @@ -12,7 +12,7 @@ #include "FPBits.h" #include "multiply_add.h" #include "src/__support/CPP/type_traits.h" -#include "src/__support/UInt.h" +#include "src/__support/big_int.h" #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY #include <stddef.h> @@ -122,7 +122,8 @@ template <size_t Bits> struct DyadicFloat { int exp_lo = exp_hi - static_cast<int>(PRECISION) - 1; - MantissaType m_hi(mantissa >> shift); + MantissaType m_hi = + shift >= MantissaType::BITS ? MantissaType(0) : mantissa >> shift; T d_hi = FPBits<T>::create_value( sign, exp_hi, @@ -130,7 +131,8 @@ template <size_t Bits> struct DyadicFloat { IMPLICIT_MASK) .get_val(); - MantissaType round_mask = MantissaType(1) << (shift - 1); + MantissaType round_mask = + shift > MantissaType::BITS ? 0 : MantissaType(1) << (shift - 1); MantissaType sticky_mask = round_mask - MantissaType(1); bool round_bit = !(mantissa & round_mask).is_zero(); diff --git a/src/__support/FPUtil/generic/FMA.h b/src/__support/FPUtil/generic/FMA.h index f03af9246337..f403aa7333b3 100644 --- a/src/__support/FPUtil/generic/FMA.h +++ b/src/__support/FPUtil/generic/FMA.h @@ -14,9 +14,9 @@ #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/rounding_mode.h" -#include "src/__support/UInt128.h" #include "src/__support/macros/attributes.h" // LIBC_INLINE #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY +#include "src/__support/uint128.h" namespace LIBC_NAMESPACE { namespace fputil { diff --git a/src/__support/FPUtil/generic/FMod.h b/src/__support/FPUtil/generic/FMod.h index 24fb264b779b..211ab926d28b 100644 --- a/src/__support/FPUtil/generic/FMod.h +++ b/src/__support/FPUtil/generic/FMod.h @@ -15,7 +15,6 @@ #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY -#include "src/math/generic/math_utils.h" namespace LIBC_NAMESPACE { namespace fputil { diff --git a/src/__support/FPUtil/generic/sqrt.h b/src/__support/FPUtil/generic/sqrt.h index b6b4aaecb2cc..7e7600ba6502 100644 --- a/src/__support/FPUtil/generic/sqrt.h +++ b/src/__support/FPUtil/generic/sqrt.h @@ -15,8 +15,8 @@ #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/rounding_mode.h" -#include "src/__support/UInt128.h" #include "src/__support/common.h" +#include "src/__support/uint128.h" namespace LIBC_NAMESPACE { namespace fputil { diff --git a/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h b/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h index 656ade4f7735..6308ffe95493 100644 --- a/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h +++ b/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h @@ -13,8 +13,8 @@ #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/rounding_mode.h" -#include "src/__support/UInt128.h" #include "src/__support/common.h" +#include "src/__support/uint128.h" namespace LIBC_NAMESPACE { namespace fputil { diff --git a/src/__support/FPUtil/riscv/FEnvImpl.h b/src/__support/FPUtil/riscv/FEnvImpl.h index b73c4798b053..a5224330f339 100644 --- a/src/__support/FPUtil/riscv/FEnvImpl.h +++ b/src/__support/FPUtil/riscv/FEnvImpl.h @@ -9,6 +9,7 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FENVIMPL_H #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FENVIMPL_H +#include "hdr/fenv_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/macros/attributes.h" // For LIBC_INLINE_ASM #include "src/__support/macros/config.h" // For LIBC_INLINE diff --git a/src/__support/FPUtil/rounding_mode.h b/src/__support/FPUtil/rounding_mode.h index 91a5b9c50e7c..aa5e00fa560b 100644 --- a/src/__support/FPUtil/rounding_mode.h +++ b/src/__support/FPUtil/rounding_mode.h @@ -9,10 +9,9 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_ROUNDING_MODE_H #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_ROUNDING_MODE_H +#include "hdr/fenv_macros.h" #include "src/__support/macros/attributes.h" // LIBC_INLINE -#include <fenv.h> - namespace LIBC_NAMESPACE::fputil { // Quick free-standing test whether fegetround() == FE_UPWARD. diff --git a/src/__support/UInt.h b/src/__support/big_int.h index c1e55ceef211..e2061c430070 100644 --- a/src/__support/UInt.h +++ b/src/__support/big_int.h @@ -249,19 +249,15 @@ LIBC_INLINE constexpr bool is_negative(cpp::array<word, N> &array) { enum Direction { LEFT, RIGHT }; // A bitwise shift on an array of elements. -// TODO: Make the result UB when 'offset' is greater or equal to the number of -// bits in 'array'. This will allow for better code performance. +// 'offset' must be less than TOTAL_BITS (i.e., sizeof(word) * CHAR_BIT * N) +// otherwise the behavior is undefined. template <Direction direction, bool is_signed, typename word, size_t N> LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array, size_t offset) { static_assert(direction == LEFT || direction == RIGHT); constexpr size_t WORD_BITS = cpp::numeric_limits<word>::digits; - constexpr size_t TOTAL_BITS = N * WORD_BITS; - if (LIBC_UNLIKELY(offset == 0)) - return array; - if (LIBC_UNLIKELY(offset >= TOTAL_BITS)) - return {}; #ifdef LIBC_TYPES_HAS_INT128 + constexpr size_t TOTAL_BITS = N * WORD_BITS; if constexpr (TOTAL_BITS == 128) { using type = cpp::conditional_t<is_signed, __int128_t, __uint128_t>; auto tmp = cpp::bit_cast<type>(array); @@ -272,6 +268,8 @@ LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array, return cpp::bit_cast<cpp::array<word, N>>(tmp); } #endif + if (LIBC_UNLIKELY(offset == 0)) + return array; const bool is_neg = is_signed && is_negative(array); constexpr auto at = [](size_t index) -> int { // reverse iteration when direction == LEFT. diff --git a/src/__support/float_to_string.h b/src/__support/float_to_string.h index 4c59cfd99c2e..09b13324f25b 100644 --- a/src/__support/float_to_string.h +++ b/src/__support/float_to_string.h @@ -15,7 +15,7 @@ #include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/dyadic_float.h" -#include "src/__support/UInt.h" +#include "src/__support/big_int.h" #include "src/__support/common.h" #include "src/__support/libc_assert.h" #include "src/__support/macros/attributes.h" diff --git a/src/__support/hash.h b/src/__support/hash.h index 6b362ba83189..d1218fdc2592 100644 --- a/src/__support/hash.h +++ b/src/__support/hash.h @@ -11,8 +11,8 @@ #include "src/__support/CPP/bit.h" // rotl #include "src/__support/CPP/limits.h" // numeric_limits -#include "src/__support/UInt128.h" // UInt128 #include "src/__support/macros/attributes.h" // LIBC_INLINE +#include "src/__support/uint128.h" // UInt128 #include <stdint.h> // For uint64_t namespace LIBC_NAMESPACE { diff --git a/src/__support/integer_literals.h b/src/__support/integer_literals.h index e99799c3512e..5fb67464090c 100644 --- a/src/__support/integer_literals.h +++ b/src/__support/integer_literals.h @@ -14,8 +14,8 @@ #define LLVM_LIBC_SRC___SUPPORT_INTEGER_LITERALS_H #include "src/__support/CPP/limits.h" // CHAR_BIT -#include "src/__support/UInt128.h" // UInt128 #include "src/__support/macros/attributes.h" // LIBC_INLINE +#include "src/__support/uint128.h" // UInt128 #include <stddef.h> // size_t #include <stdint.h> // uintxx_t diff --git a/src/__support/integer_to_string.h b/src/__support/integer_to_string.h index f72d00d1a745..375f0e82960e 100644 --- a/src/__support/integer_to_string.h +++ b/src/__support/integer_to_string.h @@ -67,7 +67,7 @@ #include "src/__support/CPP/span.h" #include "src/__support/CPP/string_view.h" #include "src/__support/CPP/type_traits.h" -#include "src/__support/UInt.h" // make_integral_or_big_int_unsigned_t +#include "src/__support/big_int.h" // make_integral_or_big_int_unsigned_t #include "src/__support/common.h" namespace LIBC_NAMESPACE { diff --git a/src/__support/str_to_float.h b/src/__support/str_to_float.h index f622b7edaa8a..fa466ca8492f 100644 --- a/src/__support/str_to_float.h +++ b/src/__support/str_to_float.h @@ -17,13 +17,13 @@ #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/dyadic_float.h" #include "src/__support/FPUtil/rounding_mode.h" -#include "src/__support/UInt128.h" #include "src/__support/common.h" #include "src/__support/ctype_utils.h" #include "src/__support/detailed_powers_of_ten.h" #include "src/__support/high_precision_decimal.h" #include "src/__support/str_to_integer.h" #include "src/__support/str_to_num_result.h" +#include "src/__support/uint128.h" #include "src/errno/libc_errno.h" // For ERANGE namespace LIBC_NAMESPACE { @@ -695,10 +695,10 @@ LIBC_INLINE FloatConvertReturn<T> decimal_exp_to_float( // If the mantissa is truncated, then the result may be off by the LSB, so // check if rounding the mantissa up changes the result. If not, then it's // safe, else use the fallback. - auto secound_output = eisel_lemire<T>({mantissa + 1, exp10}, round); - if (secound_output.has_value()) { - if (opt_output->mantissa == secound_output->mantissa && - opt_output->exponent == secound_output->exponent) { + auto second_output = eisel_lemire<T>({mantissa + 1, exp10}, round); + if (second_output.has_value()) { + if (opt_output->mantissa == second_output->mantissa && + opt_output->exponent == second_output->exponent) { return {opt_output.value(), 0}; } } diff --git a/src/__support/str_to_integer.h b/src/__support/str_to_integer.h index 02c71d40a1c0..6db851ab0e65 100644 --- a/src/__support/str_to_integer.h +++ b/src/__support/str_to_integer.h @@ -11,10 +11,10 @@ #include "src/__support/CPP/limits.h" #include "src/__support/CPP/type_traits.h" -#include "src/__support/UInt128.h" #include "src/__support/common.h" #include "src/__support/ctype_utils.h" #include "src/__support/str_to_num_result.h" +#include "src/__support/uint128.h" #include "src/errno/libc_errno.h" // For ERANGE namespace LIBC_NAMESPACE { diff --git a/src/__support/UInt128.h b/src/__support/uint128.h index b6ef9ca18eb0..722e79d0802e 100644 --- a/src/__support/UInt128.h +++ b/src/__support/uint128.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_UINT128_H #define LLVM_LIBC_SRC___SUPPORT_UINT128_H -#include "UInt.h" +#include "big_int.h" #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 #ifdef LIBC_TYPES_HAS_INT128 diff --git a/src/fenv/fegetexceptflag.cpp b/src/fenv/fegetexceptflag.cpp index 71b87ce7315d..c6160da7afbd 100644 --- a/src/fenv/fegetexceptflag.cpp +++ b/src/fenv/fegetexceptflag.cpp @@ -15,7 +15,8 @@ namespace LIBC_NAMESPACE { LLVM_LIBC_FUNCTION(int, fegetexceptflag, (fexcept_t * flagp, int excepts)) { - // TODO: Add a compile time check to see if the excepts actually fit in flagp. + static_assert(sizeof(int) >= sizeof(fexcept_t), + "fexcept_t value cannot fit in an int value."); *flagp = static_cast<fexcept_t>(fputil::test_except(FE_ALL_EXCEPT) & excepts); return 0; } diff --git a/src/fenv/feholdexcept.cpp b/src/fenv/feholdexcept.cpp index 3c73b1f42177..f264c5ae251d 100644 --- a/src/fenv/feholdexcept.cpp +++ b/src/fenv/feholdexcept.cpp @@ -9,7 +9,6 @@ #include "src/fenv/feholdexcept.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/common.h" - #include <fenv.h> namespace LIBC_NAMESPACE { diff --git a/src/fenv/fesetexcept.cpp b/src/fenv/fesetexcept.cpp new file mode 100644 index 000000000000..9afa7b73b4fb --- /dev/null +++ b/src/fenv/fesetexcept.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of fesetexcept function ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/fenv/fesetexcept.h" +#include "src/__support/FPUtil/FEnvImpl.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(int, fesetexcept, (int excepts)) { + return fputil::set_except(excepts); +} + +} // namespace LIBC_NAMESPACE diff --git a/test/src/math/RandUtils.h b/src/fenv/fesetexcept.h index fecbd8eaabf2..40a7303efcb0 100644 --- a/test/src/math/RandUtils.h +++ b/src/fenv/fesetexcept.h @@ -1,4 +1,4 @@ -//===-- RandUtils.h ---------------------------------------------*- C++ -*-===// +//===-- Implementation header for fesetexcept -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,16 +6,13 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_TEST_SRC_MATH_RANDUTILS_H -#define LLVM_LIBC_TEST_SRC_MATH_RANDUTILS_H +#ifndef LLVM_LIBC_SRC_FENV_FESETEXCEPT_H +#define LLVM_LIBC_SRC_FENV_FESETEXCEPT_H namespace LIBC_NAMESPACE { -namespace testutils { -// Wrapper for std::rand. -int rand(); +int fesetexcept(int excepts); -} // namespace testutils } // namespace LIBC_NAMESPACE -#endif // LLVM_LIBC_TEST_SRC_MATH_RANDUTILS_H +#endif // LLVM_LIBC_SRC_FENV_FESETEXCEPT_H diff --git a/src/fenv/fesetexceptflag.cpp b/src/fenv/fesetexceptflag.cpp index 2fe7cb571a8d..3ff8e270dc0a 100644 --- a/src/fenv/fesetexceptflag.cpp +++ b/src/fenv/fesetexceptflag.cpp @@ -9,7 +9,6 @@ #include "src/fenv/fesetexceptflag.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/common.h" - #include <fenv.h> namespace LIBC_NAMESPACE { diff --git a/src/math/generic/exp_utils.cpp b/src/math/generic/exp_utils.cpp index afdaea347478..ad13919578ec 100644 --- a/src/math/generic/exp_utils.cpp +++ b/src/math/generic/exp_utils.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "exp_utils.h" -#include "math_utils.h" namespace LIBC_NAMESPACE { diff --git a/src/math/generic/explogxf.h b/src/math/generic/explogxf.h index 8817ba1011a8..f7d04f517ce5 100644 --- a/src/math/generic/explogxf.h +++ b/src/math/generic/explogxf.h @@ -10,7 +10,6 @@ #define LLVM_LIBC_SRC_MATH_GENERIC_EXPLOGXF_H #include "common_constants.h" -#include "math_utils.h" #include "src/__support/CPP/bit.h" #include "src/__support/CPP/optional.h" #include "src/__support/FPUtil/FEnvImpl.h" diff --git a/src/math/generic/log1p.cpp b/src/math/generic/log1p.cpp index 83bd753cde5d..2b187080a057 100644 --- a/src/math/generic/log1p.cpp +++ b/src/math/generic/log1p.cpp @@ -28,8 +28,9 @@ using LIBC_NAMESPACE::operator""_u128; namespace { -// Extra errors from P is from using x^2 to reduce evaluation latency. -constexpr double P_ERR = 0x1.0p-50; +// Extra errors from P is from using x^2 to reduce evaluation latency and +// directional rounding. +constexpr double P_ERR = 0x1.0p-49; // log(2) with 128-bit precision generated by SageMath with: // def format_hex(value): diff --git a/src/math/generic/log_range_reduction.h b/src/math/generic/log_range_reduction.h index 64c0fc3aa4f5..d12da47a2cfa 100644 --- a/src/math/generic/log_range_reduction.h +++ b/src/math/generic/log_range_reduction.h @@ -11,7 +11,7 @@ #include "common_constants.h" #include "src/__support/FPUtil/dyadic_float.h" -#include "src/__support/UInt128.h" +#include "src/__support/uint128.h" namespace LIBC_NAMESPACE { diff --git a/src/math/generic/math_utils.cpp b/src/math/generic/math_utils.cpp deleted file mode 100644 index 14bbb2babc60..000000000000 --- a/src/math/generic/math_utils.cpp +++ /dev/null @@ -1,21 +0,0 @@ -//===-- Implementation of math utils --------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "math_utils.h" - -namespace LIBC_NAMESPACE { - -constexpr float XFlowValues<float>::OVERFLOW_VALUE = 0x1p97f; -constexpr float XFlowValues<float>::UNDERFLOW_VALUE = 0x1p-95f; -constexpr float XFlowValues<float>::MAY_UNDERFLOW_VALUE = 0x1.4p-75f; - -constexpr double XFlowValues<double>::OVERFLOW_VALUE = 0x1p769; -constexpr double XFlowValues<double>::UNDERFLOW_VALUE = 0x1p-767; -constexpr double XFlowValues<double>::MAY_UNDERFLOW_VALUE = 0x1.8p-538; - -} // namespace LIBC_NAMESPACE diff --git a/src/math/generic/math_utils.h b/src/math/generic/math_utils.h deleted file mode 100644 index cced761fc8c8..000000000000 --- a/src/math/generic/math_utils.h +++ /dev/null @@ -1,95 +0,0 @@ -//===-- Collection of utils for implementing math functions -----*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIBC_SRC_MATH_GENERIC_MATH_UTILS_H -#define LLVM_LIBC_SRC_MATH_GENERIC_MATH_UTILS_H - -#include "include/llvm-libc-macros/math-macros.h" -#include "src/__support/CPP/bit.h" -#include "src/__support/CPP/type_traits.h" -#include "src/__support/common.h" -#include "src/errno/libc_errno.h" - -#include <stdint.h> - -// TODO: evaluate which functions from this file are actually used. - -namespace LIBC_NAMESPACE { - -// TODO: Remove this, or move it to exp_utils.cpp which is its only user. -LIBC_INLINE double as_double(uint64_t x) { return cpp::bit_cast<double>(x); } - -// Values to trigger underflow and overflow. -template <typename T> struct XFlowValues; - -template <> struct XFlowValues<float> { - static const float OVERFLOW_VALUE; - static const float UNDERFLOW_VALUE; - static const float MAY_UNDERFLOW_VALUE; -}; - -template <> struct XFlowValues<double> { - static const double OVERFLOW_VALUE; - static const double UNDERFLOW_VALUE; - static const double MAY_UNDERFLOW_VALUE; -}; - -template <typename T> LIBC_INLINE T with_errno(T x, int err) { - if (math_errhandling & MATH_ERRNO) - libc_errno = err; - return x; -} - -template <typename T> LIBC_INLINE void force_eval(T x) { - volatile T y LIBC_UNUSED = x; -} - -template <typename T> LIBC_INLINE T opt_barrier(T x) { - volatile T y = x; - return y; -} - -template <typename T> struct IsFloatOrDouble { - static constexpr bool - Value = // NOLINT so that this Value can match the ones for IsSame - cpp::is_same_v<T, float> || cpp::is_same_v<T, double>; -}; - -template <typename T> -using EnableIfFloatOrDouble = cpp::enable_if_t<IsFloatOrDouble<T>::Value, int>; - -template <typename T, EnableIfFloatOrDouble<T> = 0> -T xflow(uint32_t sign, T y) { - // Underflow happens when two extremely small values are multiplied. - // Likewise, overflow happens when two large values are multiplied. - y = opt_barrier(sign ? -y : y) * y; - return with_errno(y, ERANGE); -} - -template <typename T, EnableIfFloatOrDouble<T> = 0> T overflow(uint32_t sign) { - return xflow(sign, XFlowValues<T>::OVERFLOW_VALUE); -} - -template <typename T, EnableIfFloatOrDouble<T> = 0> T underflow(uint32_t sign) { - return xflow(sign, XFlowValues<T>::UNDERFLOW_VALUE); -} - -template <typename T, EnableIfFloatOrDouble<T> = 0> -T may_underflow(uint32_t sign) { - return xflow(sign, XFlowValues<T>::MAY_UNDERFLOW_VALUE); -} - -template <typename T, EnableIfFloatOrDouble<T> = 0> -LIBC_INLINE constexpr float invalid(T x) { - T y = (x - x) / (x - x); - return isnan(x) ? y : with_errno(y, EDOM); -} - -} // namespace LIBC_NAMESPACE - -#endif // LLVM_LIBC_SRC_MATH_GENERIC_MATH_UTILS_H diff --git a/src/signal/linux/raise.cpp b/src/signal/linux/raise.cpp index dd6f5eb4b357..2250df547844 100644 --- a/src/signal/linux/raise.cpp +++ b/src/signal/linux/raise.cpp @@ -7,14 +7,15 @@ //===----------------------------------------------------------------------===// #include "src/signal/raise.h" -#include "src/signal/linux/signal_utils.h" +#include "hdr/types/sigset_t.h" #include "src/__support/common.h" +#include "src/signal/linux/signal_utils.h" namespace LIBC_NAMESPACE { LLVM_LIBC_FUNCTION(int, raise, (int sig)) { - ::sigset_t sigset; + sigset_t sigset; block_all_signals(sigset); long pid = LIBC_NAMESPACE::syscall_impl<long>(SYS_getpid); long tid = LIBC_NAMESPACE::syscall_impl<long>(SYS_gettid); diff --git a/src/signal/linux/sigaction.cpp b/src/signal/linux/sigaction.cpp index 7ddc2dc5cbcc..7b220e5c37f6 100644 --- a/src/signal/linux/sigaction.cpp +++ b/src/signal/linux/sigaction.cpp @@ -7,12 +7,11 @@ //===----------------------------------------------------------------------===// #include "src/signal/sigaction.h" -#include "src/errno/libc_errno.h" -#include "src/signal/linux/signal_utils.h" +#include "hdr/types/sigset_t.h" #include "src/__support/common.h" - -#include <signal.h> +#include "src/errno/libc_errno.h" +#include "src/signal/linux/signal_utils.h" namespace LIBC_NAMESPACE { diff --git a/src/signal/linux/sigaddset.cpp b/src/signal/linux/sigaddset.cpp index 536391734e05..8fc5d43180e2 100644 --- a/src/signal/linux/sigaddset.cpp +++ b/src/signal/linux/sigaddset.cpp @@ -7,12 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/signal/sigaddset.h" + +#include "hdr/types/sigset_t.h" #include "src/__support/common.h" #include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" -#include <signal.h> - namespace LIBC_NAMESPACE { LLVM_LIBC_FUNCTION(int, sigaddset, (sigset_t * set, int signum)) { diff --git a/src/signal/linux/sigdelset.cpp b/src/signal/linux/sigdelset.cpp index 5cb645e461cf..997f4574c05d 100644 --- a/src/signal/linux/sigdelset.cpp +++ b/src/signal/linux/sigdelset.cpp @@ -7,12 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/signal/sigdelset.h" + +#include "hdr/types/sigset_t.h" #include "src/__support/common.h" #include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" -#include <signal.h> - namespace LIBC_NAMESPACE { LLVM_LIBC_FUNCTION(int, sigdelset, (sigset_t * set, int signum)) { diff --git a/src/signal/linux/sigfillset.cpp b/src/signal/linux/sigfillset.cpp index e17c85a897ce..d98bbf7f619c 100644 --- a/src/signal/linux/sigfillset.cpp +++ b/src/signal/linux/sigfillset.cpp @@ -7,12 +7,12 @@ //===----------------------------------------------------------------------===// #include "src/signal/sigfillset.h" + +#include "hdr/types/sigset_t.h" #include "src/__support/common.h" #include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" -#include <signal.h> - namespace LIBC_NAMESPACE { LLVM_LIBC_FUNCTION(int, sigfillset, (sigset_t * set)) { diff --git a/src/signal/linux/signal_utils.h b/src/signal/linux/signal_utils.h index 5e9dd9a5c53a..3fd0cc0b7b45 100644 --- a/src/signal/linux/signal_utils.h +++ b/src/signal/linux/signal_utils.h @@ -9,10 +9,11 @@ #ifndef LLVM_LIBC_SRC_SIGNAL_LINUX_SIGNAL_UTILS_H #define LLVM_LIBC_SRC_SIGNAL_LINUX_SIGNAL_UTILS_H +#include "hdr/types/sigset_t.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include <signal.h> +#include <signal.h> // sigaction #include <stddef.h> #include <sys/syscall.h> // For syscall numbers. diff --git a/src/signal/linux/sigprocmask.cpp b/src/signal/linux/sigprocmask.cpp index 79a35dd59d75..0e94efb6400c 100644 --- a/src/signal/linux/sigprocmask.cpp +++ b/src/signal/linux/sigprocmask.cpp @@ -7,13 +7,13 @@ //===----------------------------------------------------------------------===// #include "src/signal/sigprocmask.h" + +#include "hdr/types/sigset_t.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/common.h" #include "src/errno/libc_errno.h" #include "src/signal/linux/signal_utils.h" -#include "src/__support/common.h" - -#include <signal.h> #include <sys/syscall.h> // For syscall numbers. namespace LIBC_NAMESPACE { diff --git a/src/signal/sigaddset.h b/src/signal/sigaddset.h index 626eb20a295c..c703b46bc605 100644 --- a/src/signal/sigaddset.h +++ b/src/signal/sigaddset.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SIGNAL_SIGADDSET_H #define LLVM_LIBC_SRC_SIGNAL_SIGADDSET_H -#include <signal.h> +#include "hdr/types/sigset_t.h" namespace LIBC_NAMESPACE { diff --git a/src/signal/sigdelset.h b/src/signal/sigdelset.h index c4fdb9975fa3..7bdb6e6d18fd 100644 --- a/src/signal/sigdelset.h +++ b/src/signal/sigdelset.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SIGNAL_SIGDELSET_H #define LLVM_LIBC_SRC_SIGNAL_SIGDELSET_H -#include <signal.h> +#include "hdr/types/sigset_t.h" namespace LIBC_NAMESPACE { diff --git a/src/signal/sigemptyset.h b/src/signal/sigemptyset.h index f3763d1f4f3d..661fd33b888e 100644 --- a/src/signal/sigemptyset.h +++ b/src/signal/sigemptyset.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SIGNAL_SIGEMPTYSET_H #define LLVM_LIBC_SRC_SIGNAL_SIGEMPTYSET_H -#include <signal.h> +#include "hdr/types/sigset_t.h" namespace LIBC_NAMESPACE { diff --git a/src/signal/sigfillset.h b/src/signal/sigfillset.h index d8e3168871ea..2849aacf953b 100644 --- a/src/signal/sigfillset.h +++ b/src/signal/sigfillset.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SIGNAL_SIGFILLSET_H #define LLVM_LIBC_SRC_SIGNAL_SIGFILLSET_H -#include <signal.h> +#include "hdr/types/sigset_t.h" namespace LIBC_NAMESPACE { diff --git a/src/signal/sigprocmask.h b/src/signal/sigprocmask.h index e0658860579e..8569578eb68c 100644 --- a/src/signal/sigprocmask.h +++ b/src/signal/sigprocmask.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SIGNAL_SIGPROCMASK_H #define LLVM_LIBC_SRC_SIGNAL_SIGPROCMASK_H -#include <signal.h> +#include "hdr/types/sigset_t.h" namespace LIBC_NAMESPACE { diff --git a/src/stdio/fseeko.h b/src/stdio/fseeko.h index 3202ed2f97d0..77fb41215c31 100644 --- a/src/stdio/fseeko.h +++ b/src/stdio/fseeko.h @@ -10,7 +10,6 @@ #define LLVM_LIBC_SRC_STDIO_FSEEKO_H #include <stdio.h> -#include <unistd.h> namespace LIBC_NAMESPACE { diff --git a/src/stdio/ftello.h b/src/stdio/ftello.h index 0fdf13ab6bdb..5ab17f9244a5 100644 --- a/src/stdio/ftello.h +++ b/src/stdio/ftello.h @@ -10,7 +10,6 @@ #define LLVM_LIBC_SRC_STDIO_FTELLO_H #include <stdio.h> -#include <unistd.h> namespace LIBC_NAMESPACE { diff --git a/src/stdio/printf_core/float_dec_converter.h b/src/stdio/printf_core/float_dec_converter.h index c4e8aaa2f0e2..666e4c9fa75e 100644 --- a/src/stdio/printf_core/float_dec_converter.h +++ b/src/stdio/printf_core/float_dec_converter.h @@ -12,7 +12,7 @@ #include "src/__support/CPP/string_view.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/rounding_mode.h" -#include "src/__support/UInt.h" // is_big_int_v +#include "src/__support/big_int.h" // is_big_int_v #include "src/__support/float_to_string.h" #include "src/__support/integer_to_string.h" #include "src/__support/libc_assert.h" diff --git a/src/sys/epoll/epoll_create.h b/src/sys/epoll/epoll_create.h new file mode 100644 index 000000000000..a1eeabd567e4 --- /dev/null +++ b/src/sys/epoll/epoll_create.h @@ -0,0 +1,18 @@ +//===-- Implementation header for epoll_create function ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE_H +#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE_H + +namespace LIBC_NAMESPACE { + +int epoll_create(int size); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE_H diff --git a/src/sys/epoll/epoll_create1.h b/src/sys/epoll/epoll_create1.h new file mode 100644 index 000000000000..70f446b59266 --- /dev/null +++ b/src/sys/epoll/epoll_create1.h @@ -0,0 +1,18 @@ +//===-- Implementation header for epoll_create1 function --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE1_H +#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE1_H + +namespace LIBC_NAMESPACE { + +int epoll_create1(int flags); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CREATE1_H diff --git a/src/sys/epoll/epoll_ctl.h b/src/sys/epoll/epoll_ctl.h new file mode 100644 index 000000000000..42402949d06b --- /dev/null +++ b/src/sys/epoll/epoll_ctl.h @@ -0,0 +1,21 @@ +//===-- Implementation header for epoll_ctl function ------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CTL_H +#define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CTL_H + +#include "hdr/types/struct_epoll_event.h" + +namespace LIBC_NAMESPACE { + +// TODO: event should be nullable +int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_CTL_H diff --git a/src/sys/epoll/epoll_pwait.h b/src/sys/epoll/epoll_pwait.h index 9dcb55533009..bcae72b3e2c2 100644 --- a/src/sys/epoll/epoll_pwait.h +++ b/src/sys/epoll/epoll_pwait.h @@ -9,17 +9,14 @@ #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT_H -// TODO: Use this include once the include headers are also using quotes. -// #include "include/llvm-libc-types/sigset_t.h" -// #include "include/llvm-libc-types/struct_epoll_event.h" - -#include <sys/epoll.h> +#include "hdr/types/sigset_t.h" +#include "hdr/types/struct_epoll_event.h" namespace LIBC_NAMESPACE { // TODO: sigmask should be nullable -int epoll_pwait(int epfd, epoll_event *events, int maxevents, int timeout, - const sigset_t *sigmask); +int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, + int timeout, const sigset_t *sigmask); } // namespace LIBC_NAMESPACE diff --git a/src/sys/epoll/epoll_pwait2.h b/src/sys/epoll/epoll_pwait2.h index 622ede6a0f9f..7fc528b2fd25 100644 --- a/src/sys/epoll/epoll_pwait2.h +++ b/src/sys/epoll/epoll_pwait2.h @@ -9,12 +9,9 @@ #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_PWAIT2_H -// TODO: Use this include once the include headers are also using quotes. -// #include "include/llvm-libc-types/sigset_t.h" -// #include "include/llvm-libc-types/struct_epoll_event.h" -// #include "include/llvm-libc-types/struct_timespec.h" - -#include <sys/epoll.h> +#include "hdr/types/sigset_t.h" +#include "hdr/types/struct_epoll_event.h" +#include "hdr/types/struct_timespec.h" namespace LIBC_NAMESPACE { diff --git a/src/sys/epoll/epoll_wait.h b/src/sys/epoll/epoll_wait.h index d51c9100846c..b546e91e4c2e 100644 --- a/src/sys/epoll/epoll_wait.h +++ b/src/sys/epoll/epoll_wait.h @@ -9,10 +9,7 @@ #ifndef LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H #define LLVM_LIBC_SRC_SYS_EPOLL_EPOLL_WAIT_H -// TODO: Use this include once the include headers are also using quotes. -// #include "include/llvm-libc-types/struct_epoll_event.h" - -#include <sys/epoll.h> +#include "hdr/types/struct_epoll_event.h" namespace LIBC_NAMESPACE { diff --git a/src/sys/epoll/linux/epoll_create.cpp b/src/sys/epoll/linux/epoll_create.cpp new file mode 100644 index 000000000000..d4995c476074 --- /dev/null +++ b/src/sys/epoll/linux/epoll_create.cpp @@ -0,0 +1,38 @@ +//===---------- Linux implementation of the epoll_create function ---------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/sys/epoll/epoll_create.h" + +#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/common.h" +#include "src/errno/libc_errno.h" +#include <sys/syscall.h> // For syscall numbers. + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(int, epoll_create, ([[maybe_unused]] int size)) { +#ifdef SYS_epoll_create + int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create, size); +#elif defined(SYS_epoll_create1) + int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create1, 0); +#else +#error \ + "epoll_create and epoll_create1 are unavailable. Unable to build epoll_create." +#endif + + // A negative return value indicates an error with the magnitude of the + // value being the error code. + if (ret < 0) { + libc_errno = -ret; + return -1; + } + + return ret; +} + +} // namespace LIBC_NAMESPACE diff --git a/src/sys/epoll/linux/epoll_create1.cpp b/src/sys/epoll/linux/epoll_create1.cpp new file mode 100644 index 000000000000..30f1a9910274 --- /dev/null +++ b/src/sys/epoll/linux/epoll_create1.cpp @@ -0,0 +1,31 @@ +//===---------- Linux implementation of the epoll_create1 function --------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/sys/epoll/epoll_create1.h" + +#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/common.h" +#include "src/errno/libc_errno.h" +#include <sys/syscall.h> // For syscall numbers. + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(int, epoll_create1, (int flags)) { + int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_create1, flags); + + // A negative return value indicates an error with the magnitude of the + // value being the error code. + if (ret < 0) { + libc_errno = -ret; + return -1; + } + + return ret; +} + +} // namespace LIBC_NAMESPACE diff --git a/src/sys/epoll/linux/epoll_ctl.cpp b/src/sys/epoll/linux/epoll_ctl.cpp new file mode 100644 index 000000000000..c111c5e4e0ee --- /dev/null +++ b/src/sys/epoll/linux/epoll_ctl.cpp @@ -0,0 +1,34 @@ +//===---------- Linux implementation of the epoll_ctl function ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/sys/epoll/epoll_ctl.h" + +#include "hdr/types/struct_epoll_event.h" +#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/common.h" +#include "src/errno/libc_errno.h" +#include <sys/syscall.h> // For syscall numbers. + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(int, epoll_ctl, + (int epfd, int op, int fd, epoll_event *event)) { + int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_epoll_ctl, epfd, op, fd, + reinterpret_cast<long>(event)); + + // A negative return value indicates an error with the magnitude of the + // value being the error code. + if (ret < 0) { + libc_errno = -ret; + return -1; + } + + return ret; +} + +} // namespace LIBC_NAMESPACE diff --git a/src/sys/epoll/linux/epoll_pwait.cpp b/src/sys/epoll/linux/epoll_pwait.cpp index ee1b4e66e984..8f498d18d547 100644 --- a/src/sys/epoll/linux/epoll_pwait.cpp +++ b/src/sys/epoll/linux/epoll_pwait.cpp @@ -8,17 +8,14 @@ #include "src/sys/epoll/epoll_pwait.h" +#include "hdr/signal_macros.h" // for NSIG +#include "hdr/types/sigset_t.h" +#include "hdr/types/struct_epoll_event.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" - #include "src/errno/libc_errno.h" -#include <sys/syscall.h> // For syscall numbers. -// TODO: Use this include once the include headers are also using quotes. -// #include "include/llvm-libc-types/sigset_t.h" -// #include "include/llvm-libc-types/struct_epoll_event.h" - -#include <sys/epoll.h> +#include <sys/syscall.h> // For syscall numbers. namespace LIBC_NAMESPACE { @@ -27,7 +24,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait, int timeout, const sigset_t *sigmask)) { int ret = LIBC_NAMESPACE::syscall_impl<int>( SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout, - reinterpret_cast<long>(sigmask), sizeof(sigset_t)); + reinterpret_cast<long>(sigmask), NSIG / 8); // A negative return value indicates an error with the magnitude of the // value being the error code. @@ -36,7 +33,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait, return -1; } - return 0; + return ret; } } // namespace LIBC_NAMESPACE diff --git a/src/sys/epoll/linux/epoll_pwait2.cpp b/src/sys/epoll/linux/epoll_pwait2.cpp index 671dede2a105..bd33cb6325ce 100644 --- a/src/sys/epoll/linux/epoll_pwait2.cpp +++ b/src/sys/epoll/linux/epoll_pwait2.cpp @@ -8,18 +8,15 @@ #include "src/sys/epoll/epoll_pwait2.h" +#include "hdr/signal_macros.h" // for NSIG +#include "hdr/types/sigset_t.h" +#include "hdr/types/struct_epoll_event.h" +#include "hdr/types/struct_timespec.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" - #include "src/errno/libc_errno.h" -#include <sys/syscall.h> // For syscall numbers. -// TODO: Use this include once the include headers are also using quotes. -// #include "include/llvm-libc-types/sigset_t.h" -// #include "include/llvm-libc-types/struct_epoll_event.h" -// #include "include/llvm-libc-types/struct_timespec.h" - -#include <sys/epoll.h> +#include <sys/syscall.h> // For syscall numbers. namespace LIBC_NAMESPACE { @@ -29,7 +26,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait2, int ret = LIBC_NAMESPACE::syscall_impl<int>( SYS_epoll_pwait2, epfd, reinterpret_cast<long>(events), maxevents, reinterpret_cast<long>(timeout), reinterpret_cast<long>(sigmask), - sizeof(sigset_t)); + NSIG / 8); // A negative return value indicates an error with the magnitude of the // value being the error code. @@ -38,7 +35,7 @@ LLVM_LIBC_FUNCTION(int, epoll_pwait2, return -1; } - return 0; + return ret; } } // namespace LIBC_NAMESPACE diff --git a/src/sys/epoll/linux/epoll_wait.cpp b/src/sys/epoll/linux/epoll_wait.cpp index 0c43edf76454..95238d872d52 100644 --- a/src/sys/epoll/linux/epoll_wait.cpp +++ b/src/sys/epoll/linux/epoll_wait.cpp @@ -8,16 +8,14 @@ #include "src/sys/epoll/epoll_wait.h" +#include "hdr/signal_macros.h" // for NSIG +#include "hdr/types/sigset_t.h" +#include "hdr/types/struct_epoll_event.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" #include "src/errno/libc_errno.h" -#include <sys/syscall.h> // For syscall numbers. - -// TODO: Use this include once the include headers are also using quotes. -// #include "include/llvm-libc-types/sigset_t.h" -// #include "include/llvm-libc-types/struct_epoll_event.h" -#include <sys/epoll.h> +#include <sys/syscall.h> // For syscall numbers. namespace LIBC_NAMESPACE { @@ -30,7 +28,7 @@ LLVM_LIBC_FUNCTION(int, epoll_wait, #elif defined(SYS_epoll_pwait) int ret = LIBC_NAMESPACE::syscall_impl<int>( SYS_epoll_pwait, epfd, reinterpret_cast<long>(events), maxevents, timeout, - reinterpret_cast<long>(nullptr), sizeof(sigset_t)); + reinterpret_cast<long>(nullptr), NSIG / 8); #else #error "epoll_wait and epoll_pwait are unavailable. Unable to build epoll_wait." #endif @@ -41,7 +39,7 @@ LLVM_LIBC_FUNCTION(int, epoll_wait, return -1; } - return 0; + return ret; } } // namespace LIBC_NAMESPACE diff --git a/src/sys/select/linux/select.cpp b/src/sys/select/linux/select.cpp index 3f387c14ec56..9034b75e5c29 100644 --- a/src/sys/select/linux/select.cpp +++ b/src/sys/select/linux/select.cpp @@ -8,14 +8,14 @@ #include "src/sys/select/select.h" +#include "hdr/types/sigset_t.h" +#include "hdr/types/struct_timespec.h" #include "src/__support/CPP/limits.h" #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" - #include "src/errno/libc_errno.h" -#include <signal.h> -#include <stddef.h> // For size_t -#include <sys/select.h> + +#include <stddef.h> // For size_t #include <sys/syscall.h> // For syscall numbers. namespace LIBC_NAMESPACE { diff --git a/src/unistd/linux/pipe.cpp b/src/unistd/linux/pipe.cpp new file mode 100644 index 000000000000..b4e8b9b7d9c8 --- /dev/null +++ b/src/unistd/linux/pipe.cpp @@ -0,0 +1,33 @@ +//===-- Linux implementation of pipe --------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/unistd/pipe.h" + +#include "src/__support/OSUtil/syscall.h" // For internal syscall function. +#include "src/__support/common.h" +#include "src/errno/libc_errno.h" +#include <sys/syscall.h> // For syscall numbers. + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(int, pipe, (int pipefd[2])) { +#ifdef SYS_pipe + int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_pipe, + reinterpret_cast<long>(pipefd)); +#elif defined(SYS_pipe2) + int ret = LIBC_NAMESPACE::syscall_impl<int>( + SYS_pipe2, reinterpret_cast<long>(pipefd), 0); +#endif + if (ret < 0) { + libc_errno = -ret; + return -1; + } + return ret; +} + +} // namespace LIBC_NAMESPACE diff --git a/test/src/math/RandUtils.cpp b/src/unistd/pipe.h index 0d09764f6056..0e20bb49c058 100644 --- a/test/src/math/RandUtils.cpp +++ b/src/unistd/pipe.h @@ -1,4 +1,4 @@ -//===-- RandUtils.cpp -----------------------------------------------------===// +//===-- Implementation header for pipe --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,14 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "RandUtils.h" - -#include <cstdlib> +#ifndef LLVM_LIBC_SRC_UNISTD_PIPE_H +#define LLVM_LIBC_SRC_UNISTD_PIPE_H namespace LIBC_NAMESPACE { -namespace testutils { -int rand() { return std::rand(); } +int pipe(int pipefd[2]); -} // namespace testutils } // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_UNISTD_PIPE_H diff --git a/test/UnitTest/FPMatcher.h b/test/UnitTest/FPMatcher.h index f4553eac5c8a..a76e0b8ef6f6 100644 --- a/test/UnitTest/FPMatcher.h +++ b/test/UnitTest/FPMatcher.h @@ -18,7 +18,7 @@ #include "test/UnitTest/StringUtils.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace LIBC_NAMESPACE { namespace testing { diff --git a/test/UnitTest/LibcDeathTestExecutors.cpp b/test/UnitTest/LibcDeathTestExecutors.cpp index e891c4e3c0b5..fa6d16410bb7 100644 --- a/test/UnitTest/LibcDeathTestExecutors.cpp +++ b/test/UnitTest/LibcDeathTestExecutors.cpp @@ -19,7 +19,7 @@ namespace testing { bool Test::testProcessKilled(testutils::FunctionCaller *Func, int Signal, const char *LHSStr, const char *RHSStr, internal::Location Loc) { - testutils::ProcessStatus Result = testutils::invoke_in_subprocess(Func, 500); + testutils::ProcessStatus Result = testutils::invoke_in_subprocess(Func, 1000); if (const char *error = Result.get_error()) { Ctx->markFail(); @@ -31,7 +31,7 @@ bool Test::testProcessKilled(testutils::FunctionCaller *Func, int Signal, if (Result.timed_out()) { Ctx->markFail(); tlog << Loc; - tlog << "Process timed out after " << 500 << " milliseconds.\n"; + tlog << "Process timed out after " << 1000 << " milliseconds.\n"; return false; } @@ -62,7 +62,7 @@ bool Test::testProcessKilled(testutils::FunctionCaller *Func, int Signal, bool Test::testProcessExits(testutils::FunctionCaller *Func, int ExitCode, const char *LHSStr, const char *RHSStr, internal::Location Loc) { - testutils::ProcessStatus Result = testutils::invoke_in_subprocess(Func, 500); + testutils::ProcessStatus Result = testutils::invoke_in_subprocess(Func, 1000); if (const char *error = Result.get_error()) { Ctx->markFail(); @@ -74,7 +74,7 @@ bool Test::testProcessExits(testutils::FunctionCaller *Func, int ExitCode, if (Result.timed_out()) { Ctx->markFail(); tlog << Loc; - tlog << "Process timed out after " << 500 << " milliseconds.\n"; + tlog << "Process timed out after " << 1000 << " milliseconds.\n"; return false; } diff --git a/test/UnitTest/LibcTest.cpp b/test/UnitTest/LibcTest.cpp index 03cd25191ecd..846ad331e523 100644 --- a/test/UnitTest/LibcTest.cpp +++ b/test/UnitTest/LibcTest.cpp @@ -11,9 +11,9 @@ #include "include/llvm-libc-macros/stdfix-macros.h" #include "src/__support/CPP/string.h" #include "src/__support/CPP/string_view.h" -#include "src/__support/UInt128.h" #include "src/__support/fixed_point/fx_rep.h" #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 +#include "src/__support/uint128.h" #include "test/UnitTest/TestLogger.h" #if __STDC_HOSTED__ diff --git a/test/UnitTest/RoundingModeUtils.cpp b/test/UnitTest/RoundingModeUtils.cpp index c8f32f81e713..cb34c5eab421 100644 --- a/test/UnitTest/RoundingModeUtils.cpp +++ b/test/UnitTest/RoundingModeUtils.cpp @@ -10,7 +10,7 @@ #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/rounding_mode.h" -#include <fenv.h> +#include "hdr/fenv_macros.h" namespace LIBC_NAMESPACE { namespace fputil { diff --git a/test/UnitTest/StringUtils.h b/test/UnitTest/StringUtils.h index cab0b58f9690..61d74b49d4c9 100644 --- a/test/UnitTest/StringUtils.h +++ b/test/UnitTest/StringUtils.h @@ -11,7 +11,7 @@ #include "src/__support/CPP/string.h" #include "src/__support/CPP/type_traits.h" -#include "src/__support/UInt.h" +#include "src/__support/big_int.h" namespace LIBC_NAMESPACE { diff --git a/test/UnitTest/TestLogger.cpp b/test/UnitTest/TestLogger.cpp index 4756188b46cb..feba4b5ddd39 100644 --- a/test/UnitTest/TestLogger.cpp +++ b/test/UnitTest/TestLogger.cpp @@ -1,10 +1,10 @@ #include "test/UnitTest/TestLogger.h" #include "src/__support/CPP/string.h" #include "src/__support/CPP/string_view.h" -#include "src/__support/OSUtil/io.h" // write_to_stderr -#include "src/__support/UInt.h" // is_big_int -#include "src/__support/UInt128.h" +#include "src/__support/OSUtil/io.h" // write_to_stderr +#include "src/__support/big_int.h" // is_big_int #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 +#include "src/__support/uint128.h" #include <stdint.h> diff --git a/test/src/__support/CPP/bit_test.cpp b/test/src/__support/CPP/bit_test.cpp index 875b47e6a198..299623d2ca24 100644 --- a/test/src/__support/CPP/bit_test.cpp +++ b/test/src/__support/CPP/bit_test.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "src/__support/CPP/bit.h" -#include "src/__support/UInt.h" +#include "src/__support/big_int.h" #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 #include "test/UnitTest/Test.h" diff --git a/test/src/__support/CPP/limits_test.cpp b/test/src/__support/CPP/limits_test.cpp index efcd6839d073..bcf7d5ed6a6e 100644 --- a/test/src/__support/CPP/limits_test.cpp +++ b/test/src/__support/CPP/limits_test.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "src/__support/CPP/limits.h" -#include "src/__support/UInt.h" +#include "src/__support/big_int.h" #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 #include "test/UnitTest/Test.h" diff --git a/test/src/__support/FPUtil/dyadic_float_test.cpp b/test/src/__support/FPUtil/dyadic_float_test.cpp index 5ee9aaad5638..809381ed47b5 100644 --- a/test/src/__support/FPUtil/dyadic_float_test.cpp +++ b/test/src/__support/FPUtil/dyadic_float_test.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "src/__support/FPUtil/dyadic_float.h" -#include "src/__support/UInt.h" +#include "src/__support/big_int.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" diff --git a/test/src/__support/FPUtil/rounding_mode_test.cpp b/test/src/__support/FPUtil/rounding_mode_test.cpp index 8077a5aab7af..5d62bc8c9ae9 100644 --- a/test/src/__support/FPUtil/rounding_mode_test.cpp +++ b/test/src/__support/FPUtil/rounding_mode_test.cpp @@ -10,7 +10,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include <fenv.h> +#include "hdr/fenv_macros.h" using LIBC_NAMESPACE::testing::mpfr::ForceRoundingMode; using LIBC_NAMESPACE::testing::mpfr::RoundingMode; diff --git a/test/src/__support/uint_test.cpp b/test/src/__support/big_int_test.cpp index 5696e54c73f3..1c4f0ac29171 100644 --- a/test/src/__support/uint_test.cpp +++ b/test/src/__support/big_int_test.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "src/__support/CPP/optional.h" -#include "src/__support/UInt.h" +#include "src/__support/big_int.h" #include "src/__support/integer_literals.h" // parse_unsigned_bigint #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 -#include "include/llvm-libc-macros/math-macros.h" // HUGE_VALF, HUGE_VALF +#include "hdr/math_macros.h" // HUGE_VALF, HUGE_VALF #include "test/UnitTest/Test.h" namespace LIBC_NAMESPACE { @@ -192,7 +192,7 @@ TYPED_TEST(LlvmLibcUIntClassTest, Masks, Types) { TYPED_TEST(LlvmLibcUIntClassTest, CountBits, Types) { if constexpr (!T::SIGNED) { - for (size_t i = 0; i <= T::BITS; ++i) { + for (size_t i = 0; i < T::BITS; ++i) { const auto l_one = T::all_ones() << i; // 0b111...000 const auto r_one = T::all_ones() >> i; // 0b000...111 const int zeros = i; @@ -559,10 +559,6 @@ TEST(LlvmLibcUIntClassTest, ShiftLeftTests) { LL_UInt128 result5({0, 0x2468ace000000000}); EXPECT_EQ((val2 << 100), result5); - LL_UInt128 result6({0, 0}); - EXPECT_EQ((val2 << 128), result6); - EXPECT_EQ((val2 << 256), result6); - LL_UInt192 val3({1, 0, 0}); LL_UInt192 result7({0, 1, 0}); EXPECT_EQ((val3 << 64), result7); @@ -589,10 +585,6 @@ TEST(LlvmLibcUIntClassTest, ShiftRightTests) { LL_UInt128 result5({0x0000000001234567, 0}); EXPECT_EQ((val2 >> 100), result5); - LL_UInt128 result6({0, 0}); - EXPECT_EQ((val2 >> 128), result6); - EXPECT_EQ((val2 >> 256), result6); - LL_UInt128 v1({0x1111222233334444, 0xaaaabbbbccccdddd}); LL_UInt128 r1({0xaaaabbbbccccdddd, 0}); EXPECT_EQ((v1 >> 64), r1); diff --git a/test/src/__support/high_precision_decimal_test.cpp b/test/src/__support/high_precision_decimal_test.cpp index 2bb28bcdab02..7a3c323b06d5 100644 --- a/test/src/__support/high_precision_decimal_test.cpp +++ b/test/src/__support/high_precision_decimal_test.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/UInt128.h" #include "src/__support/high_precision_decimal.h" +#include "src/__support/uint128.h" #include "test/UnitTest/Test.h" diff --git a/test/src/__support/integer_to_string_test.cpp b/test/src/__support/integer_to_string_test.cpp index 270fddd828b6..e644751b56c9 100644 --- a/test/src/__support/integer_to_string_test.cpp +++ b/test/src/__support/integer_to_string_test.cpp @@ -9,10 +9,10 @@ #include "src/__support/CPP/limits.h" #include "src/__support/CPP/span.h" #include "src/__support/CPP/string_view.h" -#include "src/__support/UInt.h" -#include "src/__support/UInt128.h" +#include "src/__support/big_int.h" #include "src/__support/integer_literals.h" #include "src/__support/integer_to_string.h" +#include "src/__support/uint128.h" #include "test/UnitTest/Test.h" diff --git a/test/src/__support/math_extras_test.cpp b/test/src/__support/math_extras_test.cpp index 401e631ea4ba..004788896517 100644 --- a/test/src/__support/math_extras_test.cpp +++ b/test/src/__support/math_extras_test.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/UInt128.h" // UInt<128> #include "src/__support/integer_literals.h" #include "src/__support/math_extras.h" +#include "src/__support/uint128.h" // UInt<128> #include "test/UnitTest/Test.h" namespace LIBC_NAMESPACE { diff --git a/test/src/__support/str_to_fp_test.h b/test/src/__support/str_to_fp_test.h index bddff035fdd1..8d6181cda884 100644 --- a/test/src/__support/str_to_fp_test.h +++ b/test/src/__support/str_to_fp_test.h @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/UInt128.h" #include "src/__support/str_to_float.h" +#include "src/__support/uint128.h" #include "src/errno/libc_errno.h" #include "test/UnitTest/Test.h" diff --git a/test/src/fenv/enabled_exceptions_test.cpp b/test/src/fenv/enabled_exceptions_test.cpp index 8bc2454faf9e..53440b704ca7 100644 --- a/test/src/fenv/enabled_exceptions_test.cpp +++ b/test/src/fenv/enabled_exceptions_test.cpp @@ -15,7 +15,7 @@ #include "test/UnitTest/FPExceptMatcher.h" #include "test/UnitTest/Test.h" -#include <fenv.h> +#include "hdr/fenv_macros.h" #include <signal.h> // This test enables an exception and verifies that raising that exception diff --git a/test/src/fenv/exception_status_test.cpp b/test/src/fenv/exception_status_test.cpp index e4e2240fc374..a7000020b1a3 100644 --- a/test/src/fenv/exception_status_test.cpp +++ b/test/src/fenv/exception_status_test.cpp @@ -1,4 +1,5 @@ -//===-- Unittests for feclearexcept, feraiseexcept and fetestexpect -------===// +//===-- Unittests for feclearexcept, feraiseexcept, fetestexpect ----------===// +//===-- and fesetexcept ---------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,12 +9,13 @@ #include "src/fenv/feclearexcept.h" #include "src/fenv/feraiseexcept.h" +#include "src/fenv/fesetexcept.h" #include "src/fenv/fetestexcept.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "test/UnitTest/Test.h" -#include <fenv.h> +#include "hdr/fenv_macros.h" TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) { // This test raises a set of exceptions and checks that the exception @@ -38,6 +40,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) { ASSERT_EQ(r, 0); s = LIBC_NAMESPACE::fetestexcept(e); ASSERT_EQ(s, 0); + + r = LIBC_NAMESPACE::fesetexcept(e); + ASSERT_EQ(r, 0); + s = LIBC_NAMESPACE::fetestexcept(e); + ASSERT_EQ(s, e); } for (int e1 : excepts) { @@ -52,6 +59,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) { ASSERT_EQ(r, 0); s = LIBC_NAMESPACE::fetestexcept(e); ASSERT_EQ(s, 0); + + r = LIBC_NAMESPACE::fesetexcept(e); + ASSERT_EQ(r, 0); + s = LIBC_NAMESPACE::fetestexcept(e); + ASSERT_EQ(s, e); } } @@ -68,6 +80,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) { ASSERT_EQ(r, 0); s = LIBC_NAMESPACE::fetestexcept(e); ASSERT_EQ(s, 0); + + r = LIBC_NAMESPACE::fesetexcept(e); + ASSERT_EQ(r, 0); + s = LIBC_NAMESPACE::fetestexcept(e); + ASSERT_EQ(s, e); } } } @@ -86,6 +103,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) { ASSERT_EQ(r, 0); s = LIBC_NAMESPACE::fetestexcept(e); ASSERT_EQ(s, 0); + + r = LIBC_NAMESPACE::fesetexcept(e); + ASSERT_EQ(r, 0); + s = LIBC_NAMESPACE::fetestexcept(e); + ASSERT_EQ(s, e); } } } @@ -106,6 +128,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) { ASSERT_EQ(r, 0); s = LIBC_NAMESPACE::fetestexcept(e); ASSERT_EQ(s, 0); + + r = LIBC_NAMESPACE::fesetexcept(e); + ASSERT_EQ(r, 0); + s = LIBC_NAMESPACE::fetestexcept(e); + ASSERT_EQ(s, e); } } } @@ -116,4 +143,9 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) { ASSERT_EQ(r, 0); int s = LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS); ASSERT_EQ(s, ALL_EXCEPTS); + + r = LIBC_NAMESPACE::fesetexcept(ALL_EXCEPTS); + ASSERT_EQ(r, 0); + s = LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS); + ASSERT_EQ(s, ALL_EXCEPTS); } diff --git a/test/src/fenv/feclearexcept_test.cpp b/test/src/fenv/feclearexcept_test.cpp index fa3e856d1ba2..bb42d9070358 100644 --- a/test/src/fenv/feclearexcept_test.cpp +++ b/test/src/fenv/feclearexcept_test.cpp @@ -11,7 +11,7 @@ #include "src/__support/FPUtil/FEnvImpl.h" #include "test/UnitTest/Test.h" -#include <fenv.h> +#include "hdr/fenv_macros.h" #include <stdint.h> TEST(LlvmLibcFEnvTest, ClearTest) { diff --git a/test/src/fenv/feenableexcept_test.cpp b/test/src/fenv/feenableexcept_test.cpp index 41c1945368ed..aeb4f955fd69 100644 --- a/test/src/fenv/feenableexcept_test.cpp +++ b/test/src/fenv/feenableexcept_test.cpp @@ -13,7 +13,7 @@ #include "test/UnitTest/Test.h" -#include <fenv.h> +#include "hdr/fenv_macros.h" TEST(LlvmLibcFEnvTest, EnableTest) { #if defined(LIBC_TARGET_ARCH_IS_ANY_ARM) || \ diff --git a/test/src/fenv/rounding_mode_test.cpp b/test/src/fenv/rounding_mode_test.cpp index 4560160e8e2e..ec2e27ecc818 100644 --- a/test/src/fenv/rounding_mode_test.cpp +++ b/test/src/fenv/rounding_mode_test.cpp @@ -11,7 +11,7 @@ #include "test/UnitTest/Test.h" -#include <fenv.h> +#include "hdr/fenv_macros.h" TEST(LlvmLibcRoundingModeTest, SetAndGet) { struct ResetDefaultRoundingMode { diff --git a/test/src/math/CeilTest.h b/test/src/math/CeilTest.h index 74cc90614dfc..da3f3c0e8f5a 100644 --- a/test/src/math/CeilTest.h +++ b/test/src/math/CeilTest.h @@ -10,7 +10,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/CopySignTest.h b/test/src/math/CopySignTest.h index 206626d66f58..052ff0333438 100644 --- a/test/src/math/CopySignTest.h +++ b/test/src/math/CopySignTest.h @@ -10,7 +10,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/FAbsTest.h b/test/src/math/FAbsTest.h index 942991f23be1..23ad8a26c481 100644 --- a/test/src/math/FAbsTest.h +++ b/test/src/math/FAbsTest.h @@ -13,7 +13,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/FDimTest.h b/test/src/math/FDimTest.h index df8de91b4298..44aba9caf646 100644 --- a/test/src/math/FDimTest.h +++ b/test/src/math/FDimTest.h @@ -6,7 +6,7 @@ // //===---------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/BasicOperations.h" #include "src/__support/FPUtil/FPBits.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/FMaxTest.h b/test/src/math/FMaxTest.h index 2c7dc3dc13ec..e9857f332e65 100644 --- a/test/src/math/FMaxTest.h +++ b/test/src/math/FMaxTest.h @@ -13,7 +13,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/FMinTest.h b/test/src/math/FMinTest.h index a986d5240d0d..c6b9f4439b79 100644 --- a/test/src/math/FMinTest.h +++ b/test/src/math/FMinTest.h @@ -13,7 +13,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/FModTest.h b/test/src/math/FModTest.h index 96ad299258a1..bc909987a161 100644 --- a/test/src/math/FModTest.h +++ b/test/src/math/FModTest.h @@ -14,7 +14,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #define TEST_SPECIAL(x, y, expected, dom_err, expected_exception) \ EXPECT_FP_EQ(expected, f(x, y)); \ diff --git a/test/src/math/FloorTest.h b/test/src/math/FloorTest.h index 21ae291e61bc..679dc26e1248 100644 --- a/test/src/math/FloorTest.h +++ b/test/src/math/FloorTest.h @@ -13,7 +13,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/FmaTest.h b/test/src/math/FmaTest.h index 0c93ec858a12..76bd221fcb1f 100644 --- a/test/src/math/FmaTest.h +++ b/test/src/math/FmaTest.h @@ -10,9 +10,10 @@ #define LLVM_LIBC_TEST_SRC_MATH_FMATEST_H #include "src/__support/FPUtil/FPBits.h" +#include "src/stdlib/rand.h" +#include "src/stdlib/srand.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "test/src/math/RandUtils.h" #include "utils/MPFRWrapper/MPFRUtils.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -43,8 +44,7 @@ private: StorageType get_random_bit_pattern() { StorageType bits{0}; for (StorageType i = 0; i < sizeof(StorageType) / 2; ++i) { - bits = (bits << 2) + - static_cast<uint16_t>(LIBC_NAMESPACE::testutils::rand()); + bits = (bits << 2) + static_cast<uint16_t>(LIBC_NAMESPACE::rand()); } return bits; } @@ -77,6 +77,7 @@ public: void test_subnormal_range(Func func) { constexpr StorageType COUNT = 100'001; constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT; + LIBC_NAMESPACE::srand(1); for (StorageType v = MIN_SUBNORMAL, w = MAX_SUBNORMAL; v <= MAX_SUBNORMAL && w >= MIN_SUBNORMAL; v += STEP, w -= STEP) { T x = FPBits(get_random_bit_pattern()).get_val(), y = FPBits(v).get_val(), @@ -90,6 +91,7 @@ public: void test_normal_range(Func func) { constexpr StorageType COUNT = 100'001; constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT; + LIBC_NAMESPACE::srand(1); for (StorageType v = MIN_NORMAL, w = MAX_NORMAL; v <= MAX_NORMAL && w >= MIN_NORMAL; v += STEP, w -= STEP) { T x = FPBits(v).get_val(), y = FPBits(w).get_val(), diff --git a/test/src/math/FrexpTest.h b/test/src/math/FrexpTest.h index f971b45628f0..5f993f604999 100644 --- a/test/src/math/FrexpTest.h +++ b/test/src/math/FrexpTest.h @@ -11,7 +11,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/HypotTest.h b/test/src/math/HypotTest.h index df69965d5dbc..0c15f02fe371 100644 --- a/test/src/math/HypotTest.h +++ b/test/src/math/HypotTest.h @@ -14,7 +14,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/ILogbTest.h b/test/src/math/ILogbTest.h index ad47b9bb3961..3d1f047a4806 100644 --- a/test/src/math/ILogbTest.h +++ b/test/src/math/ILogbTest.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H #define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/limits.h" // INT_MAX #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/ManipulationFunctions.h" diff --git a/test/src/math/LdExpTest.h b/test/src/math/LdExpTest.h index 8bfd022973b4..2a406feed52f 100644 --- a/test/src/math/LdExpTest.h +++ b/test/src/math/LdExpTest.h @@ -15,7 +15,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include <stdint.h> template <typename T> diff --git a/test/src/math/LogbTest.h b/test/src/math/LogbTest.h index 3859b56582e5..f066d5f9de02 100644 --- a/test/src/math/LogbTest.h +++ b/test/src/math/LogbTest.h @@ -11,7 +11,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/ModfTest.h b/test/src/math/ModfTest.h index 84e26db49695..49b0328753b3 100644 --- a/test/src/math/ModfTest.h +++ b/test/src/math/ModfTest.h @@ -12,7 +12,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/NextAfterTest.h b/test/src/math/NextAfterTest.h index 05803fb45ee2..a7248dd7042d 100644 --- a/test/src/math/NextAfterTest.h +++ b/test/src/math/NextAfterTest.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H #define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/bit.h" #include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/BasicOperations.h" diff --git a/test/src/math/RIntTest.h b/test/src/math/RIntTest.h index 301655c64ed3..c706ff18f186 100644 --- a/test/src/math/RIntTest.h +++ b/test/src/math/RIntTest.h @@ -15,8 +15,8 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" -#include <fenv.h> +#include "hdr/fenv_macros.h" +#include "hdr/math_macros.h" #include <stdio.h> namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/RemQuoTest.h b/test/src/math/RemQuoTest.h index 1cb8cdbe81a2..677772dd9fcc 100644 --- a/test/src/math/RemQuoTest.h +++ b/test/src/math/RemQuoTest.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H #define LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/BasicOperations.h" #include "src/__support/FPUtil/FPBits.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/RoundEvenTest.h b/test/src/math/RoundEvenTest.h index db7263a39c0f..68b8b9ae1d96 100644 --- a/test/src/math/RoundEvenTest.h +++ b/test/src/math/RoundEvenTest.h @@ -13,7 +13,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/RoundTest.h b/test/src/math/RoundTest.h index 17da00f869d3..eecf95982729 100644 --- a/test/src/math/RoundTest.h +++ b/test/src/math/RoundTest.h @@ -13,7 +13,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/RoundToIntegerTest.h b/test/src/math/RoundToIntegerTest.h index d2fabd0b4c9c..7c93451235f2 100644 --- a/test/src/math/RoundToIntegerTest.h +++ b/test/src/math/RoundToIntegerTest.h @@ -15,7 +15,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include <errno.h> namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/SqrtTest.h b/test/src/math/SqrtTest.h index 9811b2767ee3..799b7862a372 100644 --- a/test/src/math/SqrtTest.h +++ b/test/src/math/SqrtTest.h @@ -11,7 +11,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/TruncTest.h b/test/src/math/TruncTest.h index c3a89dbb837b..57c953fad874 100644 --- a/test/src/math/TruncTest.h +++ b/test/src/math/TruncTest.h @@ -13,7 +13,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" namespace mpfr = LIBC_NAMESPACE::testing::mpfr; diff --git a/test/src/math/acosf_test.cpp b/test/src/math/acosf_test.cpp index 6f8321bd7182..0d25a808e0bf 100644 --- a/test/src/math/acosf_test.cpp +++ b/test/src/math/acosf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/acosf.h" diff --git a/test/src/math/acoshf_test.cpp b/test/src/math/acoshf_test.cpp index 41d1166fb430..32761e25b5ce 100644 --- a/test/src/math/acoshf_test.cpp +++ b/test/src/math/acoshf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/acoshf.h" diff --git a/test/src/math/asinf_test.cpp b/test/src/math/asinf_test.cpp index 4e36f03f4895..91e61085e91b 100644 --- a/test/src/math/asinf_test.cpp +++ b/test/src/math/asinf_test.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/asinf.h" diff --git a/test/src/math/asinhf_test.cpp b/test/src/math/asinhf_test.cpp index 9a3bfbed1068..b19e26efd07b 100644 --- a/test/src/math/asinhf_test.cpp +++ b/test/src/math/asinhf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/asinhf.h" diff --git a/test/src/math/atan2f_test.cpp b/test/src/math/atan2f_test.cpp index 343e7601b039..1242b7e66528 100644 --- a/test/src/math/atan2f_test.cpp +++ b/test/src/math/atan2f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/atan2f.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/atanf_test.cpp b/test/src/math/atanf_test.cpp index 58b0eadd63f8..4fa7badaf736 100644 --- a/test/src/math/atanf_test.cpp +++ b/test/src/math/atanf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/atanf.h" diff --git a/test/src/math/atanhf_test.cpp b/test/src/math/atanhf_test.cpp index c659f17d13b0..7fc8c70d1386 100644 --- a/test/src/math/atanhf_test.cpp +++ b/test/src/math/atanhf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/atanhf.h" diff --git a/test/src/math/cos_test.cpp b/test/src/math/cos_test.cpp index 6a1122997c51..9a39616ed16f 100644 --- a/test/src/math/cos_test.cpp +++ b/test/src/math/cos_test.cpp @@ -11,7 +11,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" using LlvmLibcCosTest = LIBC_NAMESPACE::testing::FPTest<double>; diff --git a/test/src/math/cosf_test.cpp b/test/src/math/cosf_test.cpp index 8a5eb17fdcea..dab35fa1a9fe 100644 --- a/test/src/math/cosf_test.cpp +++ b/test/src/math/cosf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/cosf.h" diff --git a/test/src/math/coshf_test.cpp b/test/src/math/coshf_test.cpp index 8792f56b0346..7c5d6630e109 100644 --- a/test/src/math/coshf_test.cpp +++ b/test/src/math/coshf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/array.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" diff --git a/test/src/math/erff_test.cpp b/test/src/math/erff_test.cpp index 1e43c206aef0..5c848d7d5bf7 100644 --- a/test/src/math/erff_test.cpp +++ b/test/src/math/erff_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/erff.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/exp10_test.cpp b/test/src/math/exp10_test.cpp index 778189626a61..4cbdd169d803 100644 --- a/test/src/math/exp10_test.cpp +++ b/test/src/math/exp10_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/exp10.h" diff --git a/test/src/math/exp10f_test.cpp b/test/src/math/exp10f_test.cpp index 9d44e8f65dec..e9b278668104 100644 --- a/test/src/math/exp10f_test.cpp +++ b/test/src/math/exp10f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/exp10f.h" diff --git a/test/src/math/exp2_test.cpp b/test/src/math/exp2_test.cpp index 845fda5451d4..73232ed36077 100644 --- a/test/src/math/exp2_test.cpp +++ b/test/src/math/exp2_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/exp2.h" diff --git a/test/src/math/exp2f_test.cpp b/test/src/math/exp2f_test.cpp index f63f091eab9a..8ff0ce6a6e72 100644 --- a/test/src/math/exp2f_test.cpp +++ b/test/src/math/exp2f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA #include "src/errno/libc_errno.h" diff --git a/test/src/math/exp2m1f_test.cpp b/test/src/math/exp2m1f_test.cpp index a0f0da868117..cb948289b617 100644 --- a/test/src/math/exp2m1f_test.cpp +++ b/test/src/math/exp2m1f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/array.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" diff --git a/test/src/math/exp_test.cpp b/test/src/math/exp_test.cpp index 42018e608ae4..64d8198e64f2 100644 --- a/test/src/math/exp_test.cpp +++ b/test/src/math/exp_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/exp.h" diff --git a/test/src/math/expf_test.cpp b/test/src/math/expf_test.cpp index 634958bdc43e..1dce381918eb 100644 --- a/test/src/math/expf_test.cpp +++ b/test/src/math/expf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/expf.h" diff --git a/test/src/math/explogxf_test.cpp b/test/src/math/explogxf_test.cpp index a536a9f3ab8d..bcca87f590d7 100644 --- a/test/src/math/explogxf_test.cpp +++ b/test/src/math/explogxf_test.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "hdr/math_macros.h" #include "in_float_range_test_helper.h" -#include "include/llvm-libc-macros/math-macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/fabs.h" #include "src/math/fabsf.h" diff --git a/test/src/math/expm1_test.cpp b/test/src/math/expm1_test.cpp index 198e6d5cdd8a..1bf07f19f3a7 100644 --- a/test/src/math/expm1_test.cpp +++ b/test/src/math/expm1_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/expm1.h" diff --git a/test/src/math/expm1f_test.cpp b/test/src/math/expm1f_test.cpp index c72815887ba8..515f988b6264 100644 --- a/test/src/math/expm1f_test.cpp +++ b/test/src/math/expm1f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/expm1f.h" diff --git a/test/src/math/fdim_test.cpp b/test/src/math/fdim_test.cpp index 6c0c3e204c5f..1e8adf036dde 100644 --- a/test/src/math/fdim_test.cpp +++ b/test/src/math/fdim_test.cpp @@ -8,7 +8,7 @@ #include "FDimTest.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/fdim.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/fdimf_test.cpp b/test/src/math/fdimf_test.cpp index a74011b5a224..13e61d9082da 100644 --- a/test/src/math/fdimf_test.cpp +++ b/test/src/math/fdimf_test.cpp @@ -8,7 +8,7 @@ #include "FDimTest.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/fdimf.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/fdiml_test.cpp b/test/src/math/fdiml_test.cpp index d3f2e68a7c1d..2d99d2134c1c 100644 --- a/test/src/math/fdiml_test.cpp +++ b/test/src/math/fdiml_test.cpp @@ -8,7 +8,7 @@ #include "FDimTest.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/fdiml.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/ilogb_test.cpp b/test/src/math/ilogb_test.cpp index 45756ffa3d9a..c8daf2e0adaf 100644 --- a/test/src/math/ilogb_test.cpp +++ b/test/src/math/ilogb_test.cpp @@ -8,7 +8,7 @@ #include "ILogbTest.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/ManipulationFunctions.h" #include "src/math/ilogb.h" diff --git a/test/src/math/ilogbf_test.cpp b/test/src/math/ilogbf_test.cpp index ff19dd145a19..87a2789f6c11 100644 --- a/test/src/math/ilogbf_test.cpp +++ b/test/src/math/ilogbf_test.cpp @@ -8,7 +8,7 @@ #include "ILogbTest.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/ManipulationFunctions.h" #include "src/math/ilogbf.h" diff --git a/test/src/math/ilogbl_test.cpp b/test/src/math/ilogbl_test.cpp index b2c524666994..042a803b024a 100644 --- a/test/src/math/ilogbl_test.cpp +++ b/test/src/math/ilogbl_test.cpp @@ -8,7 +8,7 @@ #include "ILogbTest.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/ManipulationFunctions.h" #include "src/math/ilogbl.h" diff --git a/test/src/math/log10_test.cpp b/test/src/math/log10_test.cpp index dc4ac895546c..fd9a615ca87f 100644 --- a/test/src/math/log10_test.cpp +++ b/test/src/math/log10_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log10.h" diff --git a/test/src/math/log10f_test.cpp b/test/src/math/log10f_test.cpp index f8a137e44c35..4ba118455df4 100644 --- a/test/src/math/log10f_test.cpp +++ b/test/src/math/log10f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/log10f.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/log1p_test.cpp b/test/src/math/log1p_test.cpp index 975fb8e05c35..47dfa406ec25 100644 --- a/test/src/math/log1p_test.cpp +++ b/test/src/math/log1p_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log1p.h" @@ -34,7 +34,7 @@ TEST_F(LlvmLibcLog1pTest, SpecialNumbers) { } TEST_F(LlvmLibcLog1pTest, TrickyInputs) { - constexpr int N = 41; + constexpr int N = 42; constexpr uint64_t INPUTS[N] = { 0x3ff0000000000000, // x = 1.0 0x4024000000000000, // x = 10.0 @@ -65,6 +65,7 @@ TEST_F(LlvmLibcLog1pTest, TrickyInputs) { 0x3c90c40cef04efb5, 0x449d2ccad399848e, 0x4aa12ccdffd9d2ec, 0x5656f070b92d36ce, 0x6db06dcb74f76bcc, 0x7f1954e72ffd4596, 0x5671e2f1628093e4, 0x73dac56e2bf1a951, 0x8001bc6879ea14c5, + 0x45ca5f497ec291df, // x = 0x1.a5f497ec291dfp+93 }; for (int i = 0; i < N; ++i) { double x = FPBits(INPUTS[i]).get_val(); diff --git a/test/src/math/log1pf_test.cpp b/test/src/math/log1pf_test.cpp index a1108fee4819..db0772d3c8b8 100644 --- a/test/src/math/log1pf_test.cpp +++ b/test/src/math/log1pf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log1pf.h" diff --git a/test/src/math/log2_test.cpp b/test/src/math/log2_test.cpp index 876527900579..9992c1340e99 100644 --- a/test/src/math/log2_test.cpp +++ b/test/src/math/log2_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log2.h" diff --git a/test/src/math/log2f_test.cpp b/test/src/math/log2f_test.cpp index c05b6b93cff7..24b51adac94d 100644 --- a/test/src/math/log2f_test.cpp +++ b/test/src/math/log2f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log2f.h" diff --git a/test/src/math/log_test.cpp b/test/src/math/log_test.cpp index 06a0dc574be5..de1e59579419 100644 --- a/test/src/math/log_test.cpp +++ b/test/src/math/log_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log.h" diff --git a/test/src/math/logf_test.cpp b/test/src/math/logf_test.cpp index 1ab480744ba5..28a171d54066 100644 --- a/test/src/math/logf_test.cpp +++ b/test/src/math/logf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/logf.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/powf_test.cpp b/test/src/math/powf_test.cpp index cf674ecf8f99..69135593cd32 100644 --- a/test/src/math/powf_test.cpp +++ b/test/src/math/powf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/powf.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/sin_test.cpp b/test/src/math/sin_test.cpp index fa1c5370c30f..0171b79810d4 100644 --- a/test/src/math/sin_test.cpp +++ b/test/src/math/sin_test.cpp @@ -12,7 +12,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" using LlvmLibcSinTest = LIBC_NAMESPACE::testing::FPTest<double>; diff --git a/test/src/math/sincosf_test.cpp b/test/src/math/sincosf_test.cpp index a7372fd53b31..7c359b345f4c 100644 --- a/test/src/math/sincosf_test.cpp +++ b/test/src/math/sincosf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/sincosf.h" diff --git a/test/src/math/sinf_test.cpp b/test/src/math/sinf_test.cpp index a3c5384e3e62..6a8f8f4ee428 100644 --- a/test/src/math/sinf_test.cpp +++ b/test/src/math/sinf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/sinf.h" diff --git a/test/src/math/sinhf_test.cpp b/test/src/math/sinhf_test.cpp index bea976055dbd..cc0552f72894 100644 --- a/test/src/math/sinhf_test.cpp +++ b/test/src/math/sinhf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/array.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" diff --git a/test/src/math/smoke/CanonicalizeTest.h b/test/src/math/smoke/CanonicalizeTest.h index 4361f7d8ac7a..ab45e0eb8e94 100644 --- a/test/src/math/smoke/CanonicalizeTest.h +++ b/test/src/math/smoke/CanonicalizeTest.h @@ -14,7 +14,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #define TEST_SPECIAL(x, y, expected, expected_exception) \ EXPECT_EQ(expected, f(&x, &y)); \ diff --git a/test/src/math/smoke/CeilTest.h b/test/src/math/smoke/CeilTest.h index ec70258fddec..70e441a849cb 100644 --- a/test/src/math/smoke/CeilTest.h +++ b/test/src/math/smoke/CeilTest.h @@ -12,7 +12,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class CeilTest : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/CopySignTest.h b/test/src/math/smoke/CopySignTest.h index 70a6a419e0a0..fa9da91920f8 100644 --- a/test/src/math/smoke/CopySignTest.h +++ b/test/src/math/smoke/CopySignTest.h @@ -12,7 +12,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class CopySignTest : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/FAbsTest.h b/test/src/math/smoke/FAbsTest.h index 9309c2ada4a1..0c8ca95ba0f7 100644 --- a/test/src/math/smoke/FAbsTest.h +++ b/test/src/math/smoke/FAbsTest.h @@ -12,7 +12,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class FAbsTest : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/FModTest.h b/test/src/math/smoke/FModTest.h index 96ad299258a1..bc909987a161 100644 --- a/test/src/math/smoke/FModTest.h +++ b/test/src/math/smoke/FModTest.h @@ -14,7 +14,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #define TEST_SPECIAL(x, y, expected, dom_err, expected_exception) \ EXPECT_FP_EQ(expected, f(x, y)); \ diff --git a/test/src/math/smoke/FloorTest.h b/test/src/math/smoke/FloorTest.h index 8886e8e75183..12944aa77562 100644 --- a/test/src/math/smoke/FloorTest.h +++ b/test/src/math/smoke/FloorTest.h @@ -12,7 +12,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class FloorTest : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/HypotTest.h b/test/src/math/smoke/HypotTest.h index 80816033f28f..a1b8f8a7fafa 100644 --- a/test/src/math/smoke/HypotTest.h +++ b/test/src/math/smoke/HypotTest.h @@ -13,7 +13,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class HypotTestTemplate : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/ModfTest.h b/test/src/math/smoke/ModfTest.h index 107963665b83..65d61855c9f2 100644 --- a/test/src/math/smoke/ModfTest.h +++ b/test/src/math/smoke/ModfTest.h @@ -11,7 +11,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class ModfTest : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/NextAfterTest.h b/test/src/math/smoke/NextAfterTest.h index 403ea6bd8df6..d9c50c8109d8 100644 --- a/test/src/math/smoke/NextAfterTest.h +++ b/test/src/math/smoke/NextAfterTest.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H #define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/bit.h" #include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/BasicOperations.h" diff --git a/test/src/math/smoke/NextTowardTest.h b/test/src/math/smoke/NextTowardTest.h index 0c2abf815c23..b6c1c8d1797d 100644 --- a/test/src/math/smoke/NextTowardTest.h +++ b/test/src/math/smoke/NextTowardTest.h @@ -9,14 +9,14 @@ #ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTTOWARDTEST_H #define LLVM_LIBC_TEST_SRC_MATH_NEXTTOWARDTEST_H -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/fenv_macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/bit.h" #include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/BasicOperations.h" #include "src/__support/FPUtil/FPBits.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include <fenv.h> #define ASSERT_FP_EQ_WITH_EXCEPTION(result, expected, expected_exception) \ ASSERT_FP_EQ(result, expected); \ diff --git a/test/src/math/smoke/RIntTest.h b/test/src/math/smoke/RIntTest.h index 5a283a8bc0b5..cbed9a3b10ba 100644 --- a/test/src/math/smoke/RIntTest.h +++ b/test/src/math/smoke/RIntTest.h @@ -14,8 +14,8 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" -#include <fenv.h> +#include "hdr/fenv_macros.h" +#include "hdr/math_macros.h" #include <stdio.h> static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO, diff --git a/test/src/math/smoke/RemQuoTest.h b/test/src/math/smoke/RemQuoTest.h index cf56b1d6460f..7df537d8b206 100644 --- a/test/src/math/smoke/RemQuoTest.h +++ b/test/src/math/smoke/RemQuoTest.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H #define LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/BasicOperations.h" #include "src/__support/FPUtil/FPBits.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/smoke/RoundEvenTest.h b/test/src/math/smoke/RoundEvenTest.h index 107052fa0e28..e168d57bdbf3 100644 --- a/test/src/math/smoke/RoundEvenTest.h +++ b/test/src/math/smoke/RoundEvenTest.h @@ -12,7 +12,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class RoundEvenTest : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/RoundTest.h b/test/src/math/smoke/RoundTest.h index 8cf96f456903..49b2a1bf7dfb 100644 --- a/test/src/math/smoke/RoundTest.h +++ b/test/src/math/smoke/RoundTest.h @@ -12,7 +12,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class RoundTest : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/RoundToIntegerTest.h b/test/src/math/smoke/RoundToIntegerTest.h index 44b3f8996df5..863cf75f05ff 100644 --- a/test/src/math/smoke/RoundToIntegerTest.h +++ b/test/src/math/smoke/RoundToIntegerTest.h @@ -14,7 +14,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include <errno.h> static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO, diff --git a/test/src/math/smoke/SqrtTest.h b/test/src/math/smoke/SqrtTest.h index eea5dc1534e0..46382ed58e14 100644 --- a/test/src/math/smoke/SqrtTest.h +++ b/test/src/math/smoke/SqrtTest.h @@ -10,7 +10,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class SqrtTest : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/TruncTest.h b/test/src/math/smoke/TruncTest.h index 5612d27fef21..c0fc87f9313b 100644 --- a/test/src/math/smoke/TruncTest.h +++ b/test/src/math/smoke/TruncTest.h @@ -12,7 +12,7 @@ #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" template <typename T> class TruncTest : public LIBC_NAMESPACE::testing::Test { diff --git a/test/src/math/smoke/acosf_test.cpp b/test/src/math/smoke/acosf_test.cpp index 573a2c39492f..732c29548c60 100644 --- a/test/src/math/smoke/acosf_test.cpp +++ b/test/src/math/smoke/acosf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/acosf.h" diff --git a/test/src/math/smoke/acoshf_test.cpp b/test/src/math/smoke/acoshf_test.cpp index f561f23eb99a..2e94216ede36 100644 --- a/test/src/math/smoke/acoshf_test.cpp +++ b/test/src/math/smoke/acoshf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/acoshf.h" diff --git a/test/src/math/smoke/asinf_test.cpp b/test/src/math/smoke/asinf_test.cpp index 39d25e72c143..c67d07711cd1 100644 --- a/test/src/math/smoke/asinf_test.cpp +++ b/test/src/math/smoke/asinf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/asinf.h" diff --git a/test/src/math/smoke/asinhf_test.cpp b/test/src/math/smoke/asinhf_test.cpp index 9637bfa53948..f95184676303 100644 --- a/test/src/math/smoke/asinhf_test.cpp +++ b/test/src/math/smoke/asinhf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/asinhf.h" diff --git a/test/src/math/smoke/atan2f_test.cpp b/test/src/math/smoke/atan2f_test.cpp index ecac36b3a8c0..f81d140fefc5 100644 --- a/test/src/math/smoke/atan2f_test.cpp +++ b/test/src/math/smoke/atan2f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/atan2f.h" diff --git a/test/src/math/smoke/atanf_test.cpp b/test/src/math/smoke/atanf_test.cpp index abd9835d38a0..3800c2334b92 100644 --- a/test/src/math/smoke/atanf_test.cpp +++ b/test/src/math/smoke/atanf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/atanf.h" diff --git a/test/src/math/smoke/atanhf_test.cpp b/test/src/math/smoke/atanhf_test.cpp index 590a7ab60f04..fc3e2dd9bc54 100644 --- a/test/src/math/smoke/atanhf_test.cpp +++ b/test/src/math/smoke/atanhf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/atanhf.h" diff --git a/test/src/math/smoke/cosf_test.cpp b/test/src/math/smoke/cosf_test.cpp index 62132990ed54..7000fe2f2b07 100644 --- a/test/src/math/smoke/cosf_test.cpp +++ b/test/src/math/smoke/cosf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/cosf.h" diff --git a/test/src/math/smoke/coshf_test.cpp b/test/src/math/smoke/coshf_test.cpp index 9d7ef505ae74..4d915b12dee1 100644 --- a/test/src/math/smoke/coshf_test.cpp +++ b/test/src/math/smoke/coshf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/array.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" diff --git a/test/src/math/smoke/erff_test.cpp b/test/src/math/smoke/erff_test.cpp index 24778f8d653a..102126ee4e23 100644 --- a/test/src/math/smoke/erff_test.cpp +++ b/test/src/math/smoke/erff_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/erff.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/smoke/exp10_test.cpp b/test/src/math/smoke/exp10_test.cpp index fffffeb4c78a..7154cb176038 100644 --- a/test/src/math/smoke/exp10_test.cpp +++ b/test/src/math/smoke/exp10_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/exp10.h" diff --git a/test/src/math/smoke/exp10f_test.cpp b/test/src/math/smoke/exp10f_test.cpp index c0dcc1250332..9fb15ae75348 100644 --- a/test/src/math/smoke/exp10f_test.cpp +++ b/test/src/math/smoke/exp10f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/exp10f.h" diff --git a/test/src/math/smoke/exp2_test.cpp b/test/src/math/smoke/exp2_test.cpp index d362d32f678b..a8ef6cfa7f6a 100644 --- a/test/src/math/smoke/exp2_test.cpp +++ b/test/src/math/smoke/exp2_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/exp2.h" diff --git a/test/src/math/smoke/exp2f_test.cpp b/test/src/math/smoke/exp2f_test.cpp index e2989a6ec4d8..3ef1a4ece4cf 100644 --- a/test/src/math/smoke/exp2f_test.cpp +++ b/test/src/math/smoke/exp2f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA #include "src/errno/libc_errno.h" diff --git a/test/src/math/smoke/exp_test.cpp b/test/src/math/smoke/exp_test.cpp index a2becc74f526..2abaa7230831 100644 --- a/test/src/math/smoke/exp_test.cpp +++ b/test/src/math/smoke/exp_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/exp.h" diff --git a/test/src/math/smoke/expf_test.cpp b/test/src/math/smoke/expf_test.cpp index 42710c5fa404..b954125afd7b 100644 --- a/test/src/math/smoke/expf_test.cpp +++ b/test/src/math/smoke/expf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/expf.h" diff --git a/test/src/math/smoke/expm1_test.cpp b/test/src/math/smoke/expm1_test.cpp index 07963ec2d34c..d5f166d53a50 100644 --- a/test/src/math/smoke/expm1_test.cpp +++ b/test/src/math/smoke/expm1_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/expm1.h" diff --git a/test/src/math/smoke/expm1f_test.cpp b/test/src/math/smoke/expm1f_test.cpp index 82e0b1546350..03b6e47b7c3b 100644 --- a/test/src/math/smoke/expm1f_test.cpp +++ b/test/src/math/smoke/expm1f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/expm1f.h" diff --git a/test/src/math/smoke/log10_test.cpp b/test/src/math/smoke/log10_test.cpp index 36d753419764..37baf89128f2 100644 --- a/test/src/math/smoke/log10_test.cpp +++ b/test/src/math/smoke/log10_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log10.h" diff --git a/test/src/math/smoke/log10f_test.cpp b/test/src/math/smoke/log10f_test.cpp index 53e699417fb7..721045d355da 100644 --- a/test/src/math/smoke/log10f_test.cpp +++ b/test/src/math/smoke/log10f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/log10f.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/smoke/log1p_test.cpp b/test/src/math/smoke/log1p_test.cpp index 5fe9c60f90ab..993dbf8001df 100644 --- a/test/src/math/smoke/log1p_test.cpp +++ b/test/src/math/smoke/log1p_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log1p.h" diff --git a/test/src/math/smoke/log1pf_test.cpp b/test/src/math/smoke/log1pf_test.cpp index e2fb2f057d2e..6127cc89a742 100644 --- a/test/src/math/smoke/log1pf_test.cpp +++ b/test/src/math/smoke/log1pf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log1pf.h" diff --git a/test/src/math/smoke/log2_test.cpp b/test/src/math/smoke/log2_test.cpp index fbeba9527bcb..b59767e668eb 100644 --- a/test/src/math/smoke/log2_test.cpp +++ b/test/src/math/smoke/log2_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log2.h" diff --git a/test/src/math/smoke/log2f_test.cpp b/test/src/math/smoke/log2f_test.cpp index 46906e78dcaf..00bfb7c4abad 100644 --- a/test/src/math/smoke/log2f_test.cpp +++ b/test/src/math/smoke/log2f_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log2f.h" diff --git a/test/src/math/smoke/log_test.cpp b/test/src/math/smoke/log_test.cpp index b1e390599480..fd527dee5084 100644 --- a/test/src/math/smoke/log_test.cpp +++ b/test/src/math/smoke/log_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/log.h" diff --git a/test/src/math/smoke/logf_test.cpp b/test/src/math/smoke/logf_test.cpp index 97b6bdde307b..a27206027614 100644 --- a/test/src/math/smoke/logf_test.cpp +++ b/test/src/math/smoke/logf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/logf.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/smoke/nanf128_test.cpp b/test/src/math/smoke/nanf128_test.cpp index 2a9f57de5b43..652e35ccb53d 100644 --- a/test/src/math/smoke/nanf128_test.cpp +++ b/test/src/math/smoke/nanf128_test.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/UInt128.h" +#include "src/__support/uint128.h" #include "src/math/nanf128.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" diff --git a/test/src/math/smoke/powf_test.cpp b/test/src/math/smoke/powf_test.cpp index e9de1554ec61..98a532f3468c 100644 --- a/test/src/math/smoke/powf_test.cpp +++ b/test/src/math/smoke/powf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/powf.h" #include "test/UnitTest/FPMatcher.h" diff --git a/test/src/math/smoke/sincosf_test.cpp b/test/src/math/smoke/sincosf_test.cpp index 5952b20fc5bf..8c35953240d8 100644 --- a/test/src/math/smoke/sincosf_test.cpp +++ b/test/src/math/smoke/sincosf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/sincosf.h" diff --git a/test/src/math/smoke/sinf_test.cpp b/test/src/math/smoke/sinf_test.cpp index 945089504187..9fc208dd545b 100644 --- a/test/src/math/smoke/sinf_test.cpp +++ b/test/src/math/smoke/sinf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/sinf.h" diff --git a/test/src/math/smoke/sinhf_test.cpp b/test/src/math/smoke/sinhf_test.cpp index 0f005f752e69..1e052988eb28 100644 --- a/test/src/math/smoke/sinhf_test.cpp +++ b/test/src/math/smoke/sinhf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/CPP/array.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" diff --git a/test/src/math/smoke/tanf_test.cpp b/test/src/math/smoke/tanf_test.cpp index 68bf493f7e82..ab3f7c1aeb7e 100644 --- a/test/src/math/smoke/tanf_test.cpp +++ b/test/src/math/smoke/tanf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/tanf.h" diff --git a/test/src/math/smoke/tanhf_test.cpp b/test/src/math/smoke/tanhf_test.cpp index f1ce8b40d43a..ddae021d2bc4 100644 --- a/test/src/math/smoke/tanhf_test.cpp +++ b/test/src/math/smoke/tanhf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/tanhf.h" diff --git a/test/src/math/tan_test.cpp b/test/src/math/tan_test.cpp index 85174db9364e..d813dccc3836 100644 --- a/test/src/math/tan_test.cpp +++ b/test/src/math/tan_test.cpp @@ -11,7 +11,7 @@ #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" using LlvmLibcTanTest = LIBC_NAMESPACE::testing::FPTest<double>; diff --git a/test/src/math/tanf_test.cpp b/test/src/math/tanf_test.cpp index d40bc44d6442..e624d30f1e00 100644 --- a/test/src/math/tanf_test.cpp +++ b/test/src/math/tanf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/tanf.h" diff --git a/test/src/math/tanhf_test.cpp b/test/src/math/tanhf_test.cpp index ef272b17d68c..c34efe8d733b 100644 --- a/test/src/math/tanhf_test.cpp +++ b/test/src/math/tanhf_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" #include "src/errno/libc_errno.h" #include "src/math/tanhf.h" diff --git a/test/src/stdlib/strtold_test.cpp b/test/src/stdlib/strtold_test.cpp index 2066e9635aba..2c9f542930bf 100644 --- a/test/src/stdlib/strtold_test.cpp +++ b/test/src/stdlib/strtold_test.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/UInt128.h" +#include "src/__support/uint128.h" #include "src/errno/libc_errno.h" #include "src/stdlib/strtold.h" diff --git a/test/src/sys/epoll/linux/epoll_create1_test.cpp b/test/src/sys/epoll/linux/epoll_create1_test.cpp new file mode 100644 index 000000000000..4059afe16b80 --- /dev/null +++ b/test/src/sys/epoll/linux/epoll_create1_test.cpp @@ -0,0 +1,31 @@ +//===-- Unittests for epoll_create1 ---------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include "hdr/sys_epoll_macros.h" +#include "src/errno/libc_errno.h" +#include "src/sys/epoll/epoll_create1.h" +#include "src/unistd/close.h" +#include "test/UnitTest/ErrnoSetterMatcher.h" +#include "test/UnitTest/Test.h" + +using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; + +TEST(LlvmLibcEpollCreate1Test, Basic) { + int fd = LIBC_NAMESPACE::epoll_create1(0); + ASSERT_GT(fd, 0); + ASSERT_ERRNO_SUCCESS(); + + ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds()); +} + +TEST(LlvmLibcEpollCreate1Test, CloseOnExecute) { + int fd = LIBC_NAMESPACE::epoll_create1(EPOLL_CLOEXEC); + ASSERT_GT(fd, 0); + ASSERT_ERRNO_SUCCESS(); + + ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds()); +} diff --git a/test/src/sys/epoll/linux/epoll_create_test.cpp b/test/src/sys/epoll/linux/epoll_create_test.cpp new file mode 100644 index 000000000000..fdcdcf8eb427 --- /dev/null +++ b/test/src/sys/epoll/linux/epoll_create_test.cpp @@ -0,0 +1,26 @@ +//===-- Unittests for epoll_create ----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include "src/errno/libc_errno.h" +#include "src/sys/epoll/epoll_create.h" +#include "src/unistd/close.h" +#include "test/UnitTest/ErrnoSetterMatcher.h" +#include "test/UnitTest/Test.h" + +using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; + +TEST(LlvmLibcEpollCreateTest, Basic) { + int fd = LIBC_NAMESPACE::epoll_create(1); + ASSERT_GT(fd, 0); + ASSERT_ERRNO_SUCCESS(); + + ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds()); +} + +TEST(LlvmLibcEpollCreateTest, Fails) { + ASSERT_THAT(LIBC_NAMESPACE::epoll_create(0), Fails(EINVAL)); +} diff --git a/test/src/sys/epoll/linux/epoll_ctl_test.cpp b/test/src/sys/epoll/linux/epoll_ctl_test.cpp new file mode 100644 index 000000000000..fa2d358c5796 --- /dev/null +++ b/test/src/sys/epoll/linux/epoll_ctl_test.cpp @@ -0,0 +1,47 @@ +//===-- Unittests for epoll_ctl -------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "hdr/sys_epoll_macros.h" +#include "hdr/types/struct_epoll_event.h" +#include "src/errno/libc_errno.h" +#include "src/sys/epoll/epoll_create1.h" +#include "src/sys/epoll/epoll_ctl.h" +#include "src/unistd/close.h" +#include "src/unistd/pipe.h" +#include "test/UnitTest/ErrnoSetterMatcher.h" +#include "test/UnitTest/Test.h" + +using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; + +TEST(LlvmLibcEpollCtlTest, Basic) { + int epfd = LIBC_NAMESPACE::epoll_create1(0); + ASSERT_GT(epfd, 0); + ASSERT_ERRNO_SUCCESS(); + + int pipefd[2]; + + ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds()); + + epoll_event event; + event.events = EPOLLOUT; + event.data.fd = pipefd[0]; + + ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event), + Succeeds()); + + // adding the same file fail. + ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event), + Fails(EEXIST)); + + ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event), + Succeeds()); + + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds()); + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds()); + ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds()); +} diff --git a/test/src/sys/epoll/linux/epoll_pwait2_test.cpp b/test/src/sys/epoll/linux/epoll_pwait2_test.cpp index 83fe12bb8eb6..2f4c9854be1a 100644 --- a/test/src/sys/epoll/linux/epoll_pwait2_test.cpp +++ b/test/src/sys/epoll/linux/epoll_pwait2_test.cpp @@ -5,16 +5,53 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// +#include "hdr/sys_epoll_macros.h" +#include "hdr/types/struct_epoll_event.h" +#include "hdr/types/struct_timespec.h" #include "src/errno/libc_errno.h" +#include "src/sys/epoll/epoll_create1.h" +#include "src/sys/epoll/epoll_ctl.h" #include "src/sys/epoll/epoll_pwait2.h" +#include "src/unistd/close.h" +#include "src/unistd/pipe.h" #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; -TEST(LlvmLibcEpollWaitTest, Basic) { - EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait2(-1, nullptr, 0, nullptr, nullptr), - returns(EQ(-1ul)).with_errno(EQ(EINVAL))); -} +TEST(LlvmLibcEpollPwaitTest, Basic) { + int epfd = LIBC_NAMESPACE::epoll_create1(0); + ASSERT_GT(epfd, 0); + ASSERT_ERRNO_SUCCESS(); + + int pipefd[2]; + + ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds()); + + epoll_event event; + event.events = EPOLLOUT; + event.data.fd = pipefd[0]; + + timespec time_spec; + time_spec.tv_sec = 0; + time_spec.tv_nsec = 0; -// TODO: Complete these tests when epoll_create is implemented. + ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event), + Succeeds()); + + // Timeout of 0 causes immediate return. We just need to check that the + // interface works, we're not testing the kernel behavior here. + ASSERT_THAT( + LIBC_NAMESPACE::epoll_pwait2(epfd, &event, 1, &time_spec, nullptr), + Succeeds()); + + ASSERT_THAT(LIBC_NAMESPACE::epoll_pwait2(-1, &event, 1, &time_spec, nullptr), + Fails(EBADF)); + + ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event), + Succeeds()); + + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds()); + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds()); + ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds()); +} diff --git a/test/src/sys/epoll/linux/epoll_pwait_test.cpp b/test/src/sys/epoll/linux/epoll_pwait_test.cpp index 217facbfcebb..8e14aea8b9d5 100644 --- a/test/src/sys/epoll/linux/epoll_pwait_test.cpp +++ b/test/src/sys/epoll/linux/epoll_pwait_test.cpp @@ -5,16 +5,48 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// +#include "hdr/sys_epoll_macros.h" +#include "hdr/types/struct_epoll_event.h" #include "src/errno/libc_errno.h" +#include "src/sys/epoll/epoll_create1.h" +#include "src/sys/epoll/epoll_ctl.h" #include "src/sys/epoll/epoll_pwait.h" +#include "src/unistd/close.h" +#include "src/unistd/pipe.h" + #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; -TEST(LlvmLibcEpollWaitTest, Basic) { - EXPECT_THAT(LIBC_NAMESPACE::epoll_pwait(-1, nullptr, 0, 0, nullptr), - returns(EQ(-1ul)).with_errno(EQ(EINVAL))); -} +TEST(LlvmLibcEpollPwaitTest, Basic) { + int epfd = LIBC_NAMESPACE::epoll_create1(0); + ASSERT_GT(epfd, 0); + ASSERT_ERRNO_SUCCESS(); + + int pipefd[2]; + + ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds()); + + epoll_event event; + event.events = EPOLLOUT; + event.data.fd = pipefd[0]; -// TODO: Complete these tests when epoll_create is implemented. + ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event), + Succeeds()); + + // Timeout of 0 causes immediate return. We just need to check that the + // interface works, we're not testing the kernel behavior here. + ASSERT_THAT(LIBC_NAMESPACE::epoll_pwait(epfd, &event, 1, 0, nullptr), + Succeeds()); + + ASSERT_THAT(LIBC_NAMESPACE::epoll_pwait(-1, &event, 1, 0, nullptr), + Fails(EBADF)); + + ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event), + Succeeds()); + + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds()); + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds()); + ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds()); +} diff --git a/test/src/sys/epoll/linux/epoll_wait_test.cpp b/test/src/sys/epoll/linux/epoll_wait_test.cpp index 57fef3f690b6..f9e855a891b0 100644 --- a/test/src/sys/epoll/linux/epoll_wait_test.cpp +++ b/test/src/sys/epoll/linux/epoll_wait_test.cpp @@ -5,16 +5,45 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// +#include "hdr/sys_epoll_macros.h" +#include "hdr/types/struct_epoll_event.h" #include "src/errno/libc_errno.h" +#include "src/sys/epoll/epoll_create1.h" +#include "src/sys/epoll/epoll_ctl.h" #include "src/sys/epoll/epoll_wait.h" +#include "src/unistd/close.h" +#include "src/unistd/pipe.h" #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; TEST(LlvmLibcEpollWaitTest, Basic) { - EXPECT_THAT(LIBC_NAMESPACE::epoll_wait(-1, nullptr, 0, 0), - returns(EQ(-1ul)).with_errno(EQ(EINVAL))); -} + int epfd = LIBC_NAMESPACE::epoll_create1(0); + ASSERT_GT(epfd, 0); + ASSERT_ERRNO_SUCCESS(); + + int pipefd[2]; + + ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds()); + + epoll_event event; + event.events = EPOLLOUT; + event.data.fd = pipefd[0]; + + ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event), + Succeeds()); -// TODO: Complete these tests when epoll_create is implemented. + // Timeout of 0 causes immediate return. We just need to check that the + // interface works, we're not testing the kernel behavior here. + ASSERT_THAT(LIBC_NAMESPACE::epoll_wait(epfd, &event, 1, 0), Succeeds()); + + ASSERT_THAT(LIBC_NAMESPACE::epoll_wait(-1, &event, 1, 0), Fails(EBADF)); + + ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event), + Succeeds()); + + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds()); + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds()); + ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds()); +} diff --git a/test/src/unistd/pipe_test.cpp b/test/src/unistd/pipe_test.cpp new file mode 100644 index 000000000000..9c633dea1dba --- /dev/null +++ b/test/src/unistd/pipe_test.cpp @@ -0,0 +1,26 @@ +//===-- Unittests for pipe ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include "src/unistd/close.h" +#include "src/unistd/pipe.h" + +#include "test/UnitTest/ErrnoSetterMatcher.h" +#include "test/UnitTest/Test.h" + +using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; + +TEST(LlvmLibcPipeTest, SmokeTest) { + + int pipefd[2]; + + ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds()); + + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds()); + ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds()); +} + +// TODO: Functionality tests diff --git a/test/utils/FPUtil/x86_long_double_test.cpp b/test/utils/FPUtil/x86_long_double_test.cpp index 3b140c6c0266..87796b5c9f5b 100644 --- a/test/utils/FPUtil/x86_long_double_test.cpp +++ b/test/utils/FPUtil/x86_long_double_test.cpp @@ -9,7 +9,7 @@ #include "src/__support/FPUtil/FPBits.h" #include "test/UnitTest/Test.h" -#include "include/llvm-libc-macros/math-macros.h" +#include "hdr/math_macros.h" using FPBits = LIBC_NAMESPACE::fputil::FPBits<long double>; |