diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt index b685d82fd8cc8..ecb952b60cc06 100644 --- a/libc/hdr/types/CMakeLists.txt +++ b/libc/hdr/types/CMakeLists.txt @@ -21,3 +21,21 @@ add_proxy_header_library( FULL_BUILD_DEPENDS libc.include.llvm-libc-types.struct_timespec ) + +add_proxy_header_library( + fenv_t + HDRS + fenv_t.h + FULL_BUILD_DEPENDS + libc.include.llvm-libc-types.fenv_t + libc.incude.fenv +) + +add_proxy_header_library( + fexcept_t + HDRS + fexcept_t.h + FULL_BUILD_DEPENDS + libc.include.llvm-libc-types.fexcept_t + libc.incude.fenv +) diff --git a/libc/hdr/types/fenv_t.h b/libc/hdr/types/fenv_t.h new file mode 100644 index 0000000000000..dc2dd0217a16f --- /dev/null +++ b/libc/hdr/types/fenv_t.h @@ -0,0 +1,22 @@ +//===-- Definition of macros from fenv_t.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_T_H +#define LLVM_LIBC_HDR_FENV_T_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-types/fenv_t.h" + +#else // Overlay mode + +#include + +#endif // LLVM_LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_FENV_T_H diff --git a/libc/hdr/types/fexcept_t.h b/libc/hdr/types/fexcept_t.h new file mode 100644 index 0000000000000..7a6702516f0a3 --- /dev/null +++ b/libc/hdr/types/fexcept_t.h @@ -0,0 +1,22 @@ +//===-- Definition of macros from fexcept_t.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_FEXCEPT_T_H +#define LLVM_LIBC_HDR_FEXCEPT_T_H + +#ifdef LIBC_FULL_BUILD + +#include "include/llvm-libc-types/fexcept_t.h" + +#else // Overlay mode + +#include + +#endif // LLVM_LIBC_FULL_BUILD + +#endif // LLVM_LIBC_HDR_FENV_T_H diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt index 0b5ea83689430..01ca4254c7996 100644 --- a/libc/src/__support/FPUtil/CMakeLists.txt +++ b/libc/src/__support/FPUtil/CMakeLists.txt @@ -3,7 +3,7 @@ add_header_library( HDRS FEnvImpl.h DEPENDS - libc.include.fenv + libc.hdr.types.fenv_t libc.hdr.fenv_macros libc.hdr.math_macros libc.src.__support.macros.attributes diff --git a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h index 4b593cdd8cc4e..d1d92169475d1 100644 --- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h +++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h @@ -17,10 +17,10 @@ #endif #include -#include #include #include "hdr/fenv_macros.h" +#include "hdr/types/fenv_t.h" #include "src/__support/FPUtil/FPBits.h" namespace LIBC_NAMESPACE { diff --git a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h index 773d6bfe9f892..5b59ba38d67bb 100644 --- a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h +++ b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h @@ -17,10 +17,10 @@ #endif #include -#include #include #include "hdr/fenv_macros.h" +#include "hdr/types/fenv_t.h" #include "src/__support/FPUtil/FPBits.h" namespace LIBC_NAMESPACE { diff --git a/libc/src/__support/FPUtil/arm/FEnvImpl.h b/libc/src/__support/FPUtil/arm/FEnvImpl.h index ddb0edcf82780..78fbda4f7afff 100644 --- a/libc/src/__support/FPUtil/arm/FEnvImpl.h +++ b/libc/src/__support/FPUtil/arm/FEnvImpl.h @@ -10,9 +10,9 @@ #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_ARM_FENVIMPL_H #include "hdr/fenv_macros.h" +#include "hdr/types/fenv_t.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/macros/attributes.h" // For LIBC_INLINE -#include #include namespace LIBC_NAMESPACE { diff --git a/libc/src/__support/FPUtil/riscv/FEnvImpl.h b/libc/src/__support/FPUtil/riscv/FEnvImpl.h index a5224330f339a..6e940453f7a94 100644 --- a/libc/src/__support/FPUtil/riscv/FEnvImpl.h +++ b/libc/src/__support/FPUtil/riscv/FEnvImpl.h @@ -10,6 +10,7 @@ #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FENVIMPL_H #include "hdr/fenv_macros.h" +#include "hdr/types/fenv_t.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/libc/src/__support/FPUtil/x86_64/FEnvImpl.h b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h index b73b70e907790..0595658d7df32 100644 --- a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h +++ b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h @@ -16,9 +16,9 @@ #error "Invalid include" #endif -#include #include +#include "hdr/types/fenv_t.h" #include "src/__support/macros/sanitizer.h" namespace LIBC_NAMESPACE { diff --git a/libc/src/fenv/CMakeLists.txt b/libc/src/fenv/CMakeLists.txt index 5dcf21de04f1a..a28a7ca4c2d82 100644 --- a/libc/src/fenv/CMakeLists.txt +++ b/libc/src/fenv/CMakeLists.txt @@ -5,7 +5,6 @@ add_entrypoint_object( HDRS fegetround.h DEPENDS - libc.include.fenv libc.src.__support.FPUtil.fenv_impl COMPILE_OPTIONS -O2 @@ -71,6 +70,7 @@ add_entrypoint_object( fegetenv.h DEPENDS libc.hdr.fenv_macros + libc.hdr.types.fenv_t libc.src.__support.FPUtil.fenv_impl COMPILE_OPTIONS -O2 @@ -84,6 +84,7 @@ add_entrypoint_object( fesetenv.h DEPENDS libc.hdr.fenv_macros + libc.hdr.types.fenv_t libc.src.__support.FPUtil.fenv_impl COMPILE_OPTIONS -O2 @@ -97,6 +98,7 @@ add_entrypoint_object( fegetexceptflag.h DEPENDS libc.hdr.fenv_macros + libc.hdr.types.fexcept_t libc.src.__support.FPUtil.fenv_impl COMPILE_OPTIONS -O2 @@ -123,6 +125,7 @@ add_entrypoint_object( fesetexceptflag.h DEPENDS libc.hdr.fenv_macros + libc.hdr.types.fexcept_t libc.src.__support.FPUtil.fenv_impl COMPILE_OPTIONS -O2 @@ -136,6 +139,7 @@ add_entrypoint_object( feholdexcept.h DEPENDS libc.hdr.fenv_macros + libc.hdr.types.fenv_t libc.src.__support.FPUtil.fenv_impl COMPILE_OPTIONS -O2 @@ -149,6 +153,7 @@ add_entrypoint_object( feupdateenv.h DEPENDS libc.hdr.fenv_macros + libc.hdr.types.fenv_t libc.src.__support.FPUtil.fenv_impl COMPILE_OPTIONS -O2 diff --git a/libc/src/fenv/fegetenv.h b/libc/src/fenv/fegetenv.h index 658316482984e..8d33029647402 100644 --- a/libc/src/fenv/fegetenv.h +++ b/libc/src/fenv/fegetenv.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_FENV_FEGETENV_H #define LLVM_LIBC_SRC_FENV_FEGETENV_H -#include +#include "hdr/types/fenv_t.h" namespace LIBC_NAMESPACE { diff --git a/libc/src/fenv/fegetexceptflag.cpp b/libc/src/fenv/fegetexceptflag.cpp index c6160da7afbde..72f31bf7abd52 100644 --- a/libc/src/fenv/fegetexceptflag.cpp +++ b/libc/src/fenv/fegetexceptflag.cpp @@ -7,11 +7,10 @@ //===----------------------------------------------------------------------===// #include "src/fenv/fegetexceptflag.h" +#include "hdr/types/fexcept_t.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/common.h" -#include - namespace LIBC_NAMESPACE { LLVM_LIBC_FUNCTION(int, fegetexceptflag, (fexcept_t * flagp, int excepts)) { diff --git a/libc/src/fenv/feholdexcept.cpp b/libc/src/fenv/feholdexcept.cpp index f264c5ae251d3..e5ca257e2be5d 100644 --- a/libc/src/fenv/feholdexcept.cpp +++ b/libc/src/fenv/feholdexcept.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "src/fenv/feholdexcept.h" +#include "hdr/types/fenv_t.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/common.h" -#include namespace LIBC_NAMESPACE { diff --git a/libc/src/fenv/feholdexcept.h b/libc/src/fenv/feholdexcept.h index bbefc4ecbd41b..e53619e12feaf 100644 --- a/libc/src/fenv/feholdexcept.h +++ b/libc/src/fenv/feholdexcept.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_FENV_FEHOLDEXCEPT_H #define LLVM_LIBC_SRC_FENV_FEHOLDEXCEPT_H -#include +#include "hdr/types/fenv_t.h" namespace LIBC_NAMESPACE { diff --git a/libc/src/fenv/fesetenv.h b/libc/src/fenv/fesetenv.h index 8b56bebc2e36d..8636711cb1fee 100644 --- a/libc/src/fenv/fesetenv.h +++ b/libc/src/fenv/fesetenv.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_FENV_FESETENV_H #define LLVM_LIBC_SRC_FENV_FESETENV_H -#include +#include "hdr/types/fenv_t.h" namespace LIBC_NAMESPACE { diff --git a/libc/src/fenv/fesetexceptflag.cpp b/libc/src/fenv/fesetexceptflag.cpp index 3ff8e270dc0a7..628f33dcb9c4b 100644 --- a/libc/src/fenv/fesetexceptflag.cpp +++ b/libc/src/fenv/fesetexceptflag.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "src/fenv/fesetexceptflag.h" +#include "hdr/types/fexcept_t.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/common.h" -#include namespace LIBC_NAMESPACE { diff --git a/libc/src/fenv/feupdateenv.h b/libc/src/fenv/feupdateenv.h index 294c041ddeae7..3c9c88b36e728 100644 --- a/libc/src/fenv/feupdateenv.h +++ b/libc/src/fenv/feupdateenv.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_FENV_FEUPDATEENV_H #define LLVM_LIBC_SRC_FENV_FEUPDATEENV_H -#include +#include "hdr/types/fenv_t.h" namespace LIBC_NAMESPACE { diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt index 4411170502ed6..9113eca388e05 100644 --- a/libc/test/UnitTest/CMakeLists.txt +++ b/libc/test/UnitTest/CMakeLists.txt @@ -135,6 +135,7 @@ add_unittest_framework_library( LibcTest libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.fenv_impl + libc.hdr.types.fenv_t ) add_unittest_framework_library( diff --git a/libc/test/UnitTest/FPExceptMatcher.cpp b/libc/test/UnitTest/FPExceptMatcher.cpp index 1601b7e53f2be..53ea72ad9ddd8 100644 --- a/libc/test/UnitTest/FPExceptMatcher.cpp +++ b/libc/test/UnitTest/FPExceptMatcher.cpp @@ -8,7 +8,8 @@ #include "FPExceptMatcher.h" -#include +#include "hdr/types/fenv_t.h" +#include "src/__support/FPUtil/FEnvImpl.h" #include #include #include @@ -36,12 +37,12 @@ FPExceptMatcher::FPExceptMatcher(FunctionCaller *func) { caughtExcept = false; fenv_t oldEnv; - fegetenv(&oldEnv); + fputil::get_env(&oldEnv); if (sigsetjmp(jumpBuffer, 1) == 0) funcUP->call(); // We restore the previous floating point environment after // the call to the function which can potentially raise SIGFPE. - fesetenv(&oldEnv); + fputil::set_env(&oldEnv); signal(SIGFPE, oldSIGFPEHandler); exceptionRaised = caughtExcept; } diff --git a/libc/test/src/fenv/exception_flags_test.cpp b/libc/test/src/fenv/exception_flags_test.cpp index 434adc06b1a36..d1d8bfcc53db5 100644 --- a/libc/test/src/fenv/exception_flags_test.cpp +++ b/libc/test/src/fenv/exception_flags_test.cpp @@ -6,14 +6,13 @@ // //===----------------------------------------------------------------------===// +#include "hdr/types/fexcept_t.h" #include "src/fenv/fegetexceptflag.h" #include "src/fenv/fesetexceptflag.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "test/UnitTest/Test.h" -#include - TEST(LlvmLibcFenvTest, GetExceptFlagAndSetExceptFlag) { // We will disable all exceptions to prevent invocation of the exception // handler. diff --git a/libc/test/src/fenv/feholdexcept_test.cpp b/libc/test/src/fenv/feholdexcept_test.cpp index 735c7705ff49c..0689d89ab233a 100644 --- a/libc/test/src/fenv/feholdexcept_test.cpp +++ b/libc/test/src/fenv/feholdexcept_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/types/fenv_t.h" #include "src/fenv/feholdexcept.h" #include "src/__support/FPUtil/FEnvImpl.h" @@ -13,8 +14,6 @@ #include "test/UnitTest/FPExceptMatcher.h" #include "test/UnitTest/Test.h" -#include - TEST(LlvmLibcFEnvTest, RaiseAndCrash) { #if defined(LIBC_TARGET_ARCH_IS_ANY_ARM) || \ defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) diff --git a/libc/test/src/fenv/feupdateenv_test.cpp b/libc/test/src/fenv/feupdateenv_test.cpp index 96f253f76077a..251b8566aac3d 100644 --- a/libc/test/src/fenv/feupdateenv_test.cpp +++ b/libc/test/src/fenv/feupdateenv_test.cpp @@ -6,12 +6,12 @@ // //===----------------------------------------------------------------------===// +#include "hdr/types/fenv_t.h" #include "src/fenv/feupdateenv.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "test/UnitTest/Test.h" -#include #include TEST(LlvmLibcFEnvTest, UpdateEnvTest) { diff --git a/libc/test/src/fenv/getenv_and_setenv_test.cpp b/libc/test/src/fenv/getenv_and_setenv_test.cpp index 8184a5c3bb999..f767e8ab9b2fb 100644 --- a/libc/test/src/fenv/getenv_and_setenv_test.cpp +++ b/libc/test/src/fenv/getenv_and_setenv_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/types/fenv_t.h" #include "src/fenv/fegetenv.h" #include "src/fenv/fegetround.h" #include "src/fenv/fesetenv.h" @@ -14,8 +15,6 @@ #include "src/__support/FPUtil/FEnvImpl.h" #include "test/UnitTest/Test.h" -#include - TEST(LlvmLibcFenvTest, GetEnvAndSetEnv) { // We will disable all exceptions to prevent invocation of the exception // handler. diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 9270a9d75b01c..fb37f113b310a 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -130,6 +130,16 @@ libc_support_library( ############################ Type Proxy Header Files ########################### +libc_support_library( + name = "types_fenv_t", + hdrs = ["hdr/types/fenv_t.h"], +) + +libc_support_library( + name = "types_fexcept_t", + hdrs = ["hdr/types/fexcept_t.h"], +) + libc_support_library( name = "types_sigset_t", hdrs = ["hdr/types/sigset_t.h"], @@ -776,6 +786,7 @@ libc_support_library( ":errno", ":hdr_fenv_macros", ":hdr_math_macros", + ":types_fenv_t" ], ) @@ -1251,6 +1262,7 @@ libc_function( deps = [ ":__support_common", ":__support_fputil_fenv_impl", + ":types_fexcept_t" ], ) @@ -1261,6 +1273,7 @@ libc_function( deps = [ ":__support_common", ":__support_fputil_fenv_impl", + ":types_fexcept_t", ], ) diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel index 82c015a7eeda0..b1140a5a16090 100644 --- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel @@ -87,6 +87,7 @@ libc_support_library( "//libc:__support_fputil_rounding_mode", "//libc:hdr_math_macros", "//libc:hdr_fenv_macros", + "//libc:types_fenv_t", ], ) diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel index bce1dd786a850..359db0723dfd3 100644 --- a/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel @@ -65,6 +65,7 @@ libc_test( "//libc:__support_fputil_fenv_impl", "//libc:__support_macros_properties_architectures", "//libc/test/UnitTest:fp_test_helpers", + "//libc:types_fenv_t", ], ) @@ -77,6 +78,7 @@ libc_test( ], deps = [ "//libc:__support_fputil_fenv_impl", + "//libc:types_fexcept_t", ], ) @@ -115,6 +117,7 @@ libc_test( ], deps = [ "//libc:__support_fputil_fenv_impl", + "//libc:types_fenv_t", ], ) @@ -129,5 +132,6 @@ libc_test( ], deps = [ "//libc:__support_fputil_fenv_impl", + "//libc:types_fenv_t", ], )