Skip to content

[libc] Add proxy header for fenv.h macro constants. #87863 #87896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from Apr 9, 2024
Merged
9 changes: 9 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ add_proxy_header_library(
libc.include.llvm-libc-macros.math_macros
libc.include.math
)

add_proxy_header_library(
fenv_macros
HDRS
fenv_macros.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-macros.fenv_macros
libc.incude.fenv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: s/incude/include/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 8cfa72a

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

)
22 changes: 22 additions & 0 deletions libc/hdr/fenv_macros.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion libc/src/__support/FPUtil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_header_library(
FEnvImpl.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.hdr.math_macros
libc.src.__support.macros.attributes
libc.src.errno.errno
Expand All @@ -14,7 +15,7 @@ add_header_library(
HDRS
rounding_mode.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.macros.attributes
libc.src.__support.macros.properties.architectures
libc.src.__support.macros.sanitizer
Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/FPUtil/aarch64/FEnvImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <fenv.h>
#include <stdint.h>

#include "hdr/fenv_macros.h"
#include "src/__support/FPUtil/FPBits.h"

namespace LIBC_NAMESPACE {
Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <fenv.h>
#include <stdint.h>

#include "hdr/fenv_macros.h"
#include "src/__support/FPUtil/FPBits.h"

namespace LIBC_NAMESPACE {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/arm/FEnvImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 0 additions & 1 deletion libc/src/__support/FPUtil/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ add_header_library(
sqrt.h
sqrt_80_bit_long_double.h
DEPENDS
libc.include.fenv
libc.src.__support.common
libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/FPUtil/riscv/FEnvImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions libc/src/__support/FPUtil/rounding_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 14 additions & 14 deletions libc/src/fenv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_entrypoint_object(
HDRS
fesetround.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -31,7 +31,7 @@ add_entrypoint_object(
HDRS
feclearexcept.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -44,7 +44,7 @@ add_entrypoint_object(
HDRS
feraiseexcept.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -57,7 +57,7 @@ add_entrypoint_object(
HDRS
fetestexcept.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -70,7 +70,7 @@ add_entrypoint_object(
HDRS
fegetenv.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -83,7 +83,7 @@ add_entrypoint_object(
HDRS
fesetenv.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -96,7 +96,7 @@ add_entrypoint_object(
HDRS
fegetexceptflag.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -109,7 +109,7 @@ add_entrypoint_object(
HDRS
fesetexcept.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -122,7 +122,7 @@ add_entrypoint_object(
HDRS
fesetexceptflag.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -135,7 +135,7 @@ add_entrypoint_object(
HDRS
feholdexcept.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -148,7 +148,7 @@ add_entrypoint_object(
HDRS
feupdateenv.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -161,7 +161,7 @@ add_entrypoint_object(
HDRS
feenableexcept.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -174,7 +174,7 @@ add_entrypoint_object(
HDRS
fedisableexcept.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand All @@ -187,7 +187,7 @@ add_entrypoint_object(
HDRS
fegetexcept.h
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
Expand Down
1 change: 0 additions & 1 deletion libc/src/fenv/feholdexcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion libc/src/fenv/fesetexceptflag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/UnitTest/RoundingModeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/__support/FPUtil/rounding_mode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/fenv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ if (NOT (LLVM_USE_SANITIZER OR (${LIBC_TARGET_OS} STREQUAL "windows")
SRCS
feholdexcept_test.cpp
DEPENDS
libc.include.fenv
libc.hdr.fenv_macros
libc.src.fenv.feholdexcept
libc.src.__support.FPUtil.fenv_impl
LINK_LIBRARIES
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/fenv/enabled_exceptions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/fenv/exception_status_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#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
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/fenv/feclearexcept_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/fenv/feenableexcept_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) || \
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/fenv/rounding_mode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "test/UnitTest/Test.h"

#include <fenv.h>
#include "hdr/fenv_macros.h"

TEST(LlvmLibcRoundingModeTest, SetAndGet) {
struct ResetDefaultRoundingMode {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/RIntTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#include "hdr/fenv_macros.h"
#include "hdr/math_macros.h"
#include <fenv.h>
#include <stdio.h>

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/NextTowardTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTTOWARDTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_NEXTTOWARDTEST_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); \
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/RIntTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

#include "hdr/fenv_macros.h"
#include "hdr/math_macros.h"
#include <fenv.h>
#include <stdio.h>

static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
Expand Down
1 change: 0 additions & 1 deletion libc/utils/MPFRWrapper/MPFRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "test/UnitTest/FPMatcher.h"

#include "hdr/math_macros.h"
#include <fenv.h>
#include <memory>
#include <stdint.h>

Expand Down
6 changes: 6 additions & 0 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ libc_support_library(
hdrs = ["hdr/math_macros.h"],
)

libc_support_library(
name = "hdr_fenv_macros",
hdrs = ["hdr/fenv_macros.h"],
)

############################### Support libraries ##############################

libc_support_library(
Expand Down Expand Up @@ -752,6 +757,7 @@ libc_support_library(
hdrs = ["src/__support/FPUtil/rounding_mode.h"],
deps = [
":__support_macros_attributes",
":hdr_fenv_macros",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ libc_support_library(
"//libc:__support_fputil_fpbits_str",
"//libc:__support_fputil_rounding_mode",
"//libc:hdr_math_macros",
"//libc:hdr_fenv_macros",
],
)

Expand Down
Loading
Loading