[libc] [llvm] Fenv types (PR #88467)
Job Henandez Lara via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 11 19:31:00 PDT 2024
https://github.com/Jobhdez created https://github.com/llvm/llvm-project/pull/88467
Hello, here is my pr for #88187.
I have ran he build on overlay mode and full build mode and also ran the tests by doing `ninja check-libc`.
I have also ran the bazel build.
everything looks good.
please let me know of anything I need to change. thanks
>From c96fd7051e79ecb3ead0b9848f0f4045debee35e Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Thu, 11 Apr 2024 19:27:29 -0700
Subject: [PATCH 1/2] [libc] Add proxy headers for fenv.h types
---
libc/hdr/CMakeLists.txt | 18 +++++++++++++++
libc/hdr/fenv_t.h | 22 +++++++++++++++++++
libc/hdr/fexcept_t.h | 22 +++++++++++++++++++
libc/src/__support/FPUtil/CMakeLists.txt | 3 ++-
libc/src/__support/FPUtil/aarch64/FEnvImpl.h | 2 +-
.../FPUtil/aarch64/fenv_darwin_impl.h | 2 +-
libc/src/__support/FPUtil/arm/FEnvImpl.h | 2 +-
libc/src/__support/FPUtil/riscv/FEnvImpl.h | 1 +
libc/src/__support/FPUtil/x86_64/FEnvImpl.h | 2 +-
libc/src/fenv/CMakeLists.txt | 3 ++-
libc/src/fenv/fegetenv.h | 2 +-
libc/src/fenv/fegetexceptflag.cpp | 3 +--
libc/src/fenv/feholdexcept.cpp | 2 +-
libc/src/fenv/feholdexcept.h | 2 +-
libc/src/fenv/fesetenv.h | 2 +-
libc/src/fenv/fesetexceptflag.cpp | 3 ++-
libc/src/fenv/feupdateenv.h | 2 +-
libc/test/UnitTest/FPExceptMatcher.cpp | 2 +-
libc/test/src/fenv/exception_flags_test.cpp | 2 +-
libc/test/src/fenv/feholdexcept_test.cpp | 3 +--
libc/test/src/fenv/feupdateenv_test.cpp | 2 +-
libc/test/src/fenv/getenv_and_setenv_test.cpp | 3 +--
.../llvm-project-overlay/libc/BUILD.bazel | 13 +++++++++++
.../libc/test/src/fenv/BUILD.bazel | 4 ++++
24 files changed, 101 insertions(+), 21 deletions(-)
create mode 100644 libc/hdr/fenv_t.h
create mode 100644 libc/hdr/fexcept_t.h
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 4ca7db5e98d607..a2cd1fc767448f 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -40,3 +40,21 @@ add_proxy_header_library(
libc.include.llvm-libc-macros.fenv_macros
libc.incude.fenv
)
+
+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/fenv_t.h b/libc/hdr/fenv_t.h
new file mode 100644
index 00000000000000..dc2dd0217a16f3
--- /dev/null
+++ b/libc/hdr/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 <fenv.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_FENV_T_H
diff --git a/libc/hdr/fexcept_t.h b/libc/hdr/fexcept_t.h
new file mode 100644
index 00000000000000..7a6702516f0a35
--- /dev/null
+++ b/libc/hdr/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 <fenv.h>
+
+#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 0b5ea836894302..f6de0793558d44 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -3,7 +3,8 @@ add_header_library(
HDRS
FEnvImpl.h
DEPENDS
- libc.include.fenv
+ libc.hdr.fenv_t
+ libc.hdr.fexcept_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 4b593cdd8cc4e4..29cb0ed799c1dd 100644
--- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
@@ -17,10 +17,10 @@
#endif
#include <arm_acle.h>
-#include <fenv.h>
#include <stdint.h>
#include "hdr/fenv_macros.h"
+#include "hdr/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 773d6bfe9f8923..78f0edea2f5a4e 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 <arm_acle.h>
-#include <fenv.h>
#include <stdint.h>
#include "hdr/fenv_macros.h"
+#include "hdr/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 ddb0edcf827800..5897d79b0fb424 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/fenv_t.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/attributes.h" // For LIBC_INLINE
-#include <fenv.h>
#include <stdint.h>
namespace LIBC_NAMESPACE {
diff --git a/libc/src/__support/FPUtil/riscv/FEnvImpl.h b/libc/src/__support/FPUtil/riscv/FEnvImpl.h
index a5224330f339a1..fe6e5b8515d31f 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/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 b73b70e907790f..00615784cb3969 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 <fenv.h>
#include <stdint.h>
+#include "hdr/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 5dcf21de04f1a0..827dcc968e9897 100644
--- a/libc/src/fenv/CMakeLists.txt
+++ b/libc/src/fenv/CMakeLists.txt
@@ -5,7 +5,8 @@ add_entrypoint_object(
HDRS
fegetround.h
DEPENDS
- libc.include.fenv
+ libc.hdr.fenv_t
+ libc.hdr.fexcept_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 658316482984e1..97070afc3f8242 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 <fenv.h>
+#include "hdr/fenv_t.h"
namespace LIBC_NAMESPACE {
diff --git a/libc/src/fenv/fegetexceptflag.cpp b/libc/src/fenv/fegetexceptflag.cpp
index c6160da7afbde2..a80fdef17c3f6a 100644
--- a/libc/src/fenv/fegetexceptflag.cpp
+++ b/libc/src/fenv/fegetexceptflag.cpp
@@ -6,12 +6,11 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/fexcept_t.h"
#include "src/fenv/fegetexceptflag.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/common.h"
-#include <fenv.h>
-
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 f264c5ae251d33..112c20135b90e7 100644
--- a/libc/src/fenv/feholdexcept.cpp
+++ b/libc/src/fenv/feholdexcept.cpp
@@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/fenv_t.h"
#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/libc/src/fenv/feholdexcept.h b/libc/src/fenv/feholdexcept.h
index bbefc4ecbd41b2..5118ce4beee7bc 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 <fenv.h>
+#include "hdr/fenv_t.h"
namespace LIBC_NAMESPACE {
diff --git a/libc/src/fenv/fesetenv.h b/libc/src/fenv/fesetenv.h
index 8b56bebc2e36d4..2b070cb822482f 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 <fenv.h>
+#include "hdr/fenv_t.h"
namespace LIBC_NAMESPACE {
diff --git a/libc/src/fenv/fesetexceptflag.cpp b/libc/src/fenv/fesetexceptflag.cpp
index 3ff8e270dc0a74..b5a546875e531b 100644
--- a/libc/src/fenv/fesetexceptflag.cpp
+++ b/libc/src/fenv/fesetexceptflag.cpp
@@ -6,10 +6,11 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/fexcept_t.h"
#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/libc/src/fenv/feupdateenv.h b/libc/src/fenv/feupdateenv.h
index 294c041ddeae79..f1314c64ded8de 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 <fenv.h>
+#include "hdr/fenv_t.h"
namespace LIBC_NAMESPACE {
diff --git a/libc/test/UnitTest/FPExceptMatcher.cpp b/libc/test/UnitTest/FPExceptMatcher.cpp
index 1601b7e53f2be1..1fba118b3fd0f6 100644
--- a/libc/test/UnitTest/FPExceptMatcher.cpp
+++ b/libc/test/UnitTest/FPExceptMatcher.cpp
@@ -8,7 +8,7 @@
#include "FPExceptMatcher.h"
-#include <fenv.h>
+#include "hdr/fenv_t.h"
#include <memory>
#include <setjmp.h>
#include <signal.h>
diff --git a/libc/test/src/fenv/exception_flags_test.cpp b/libc/test/src/fenv/exception_flags_test.cpp
index 434adc06b1a36a..19f9ab1bf0b1ba 100644
--- a/libc/test/src/fenv/exception_flags_test.cpp
+++ b/libc/test/src/fenv/exception_flags_test.cpp
@@ -6,13 +6,13 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/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 <fenv.h>
TEST(LlvmLibcFenvTest, GetExceptFlagAndSetExceptFlag) {
// We will disable all exceptions to prevent invocation of the exception
diff --git a/libc/test/src/fenv/feholdexcept_test.cpp b/libc/test/src/fenv/feholdexcept_test.cpp
index 735c7705ff49c6..714368aecb5cd5 100644
--- a/libc/test/src/fenv/feholdexcept_test.cpp
+++ b/libc/test/src/fenv/feholdexcept_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/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 <fenv.h>
-
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 96f253f76077a0..ddc60dd8b2f3c3 100644
--- a/libc/test/src/fenv/feupdateenv_test.cpp
+++ b/libc/test/src/fenv/feupdateenv_test.cpp
@@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/fenv_t.h"
#include "src/fenv/feupdateenv.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "test/UnitTest/Test.h"
-#include <fenv.h>
#include <signal.h>
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 8184a5c3bb9997..8bbff66377cd6b 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/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 <fenv.h>
-
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 d38dc3029f74ff..9fb3c1645ff5f0 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -118,6 +118,16 @@ libc_support_library(
hdrs = ["hdr/fenv_macros.h"],
)
+libc_support_library(
+ name = "hdr_fenv_t",
+ hdrs = ["hdr/fenv_t.h"],
+)
+
+libc_support_library(
+ name = "hdr_fexcept_t",
+ hdrs = ["hdr/fexcept_t.h"],
+)
+
############################### Support libraries ##############################
libc_support_library(
@@ -749,6 +759,7 @@ libc_support_library(
":errno",
":hdr_fenv_macros",
":hdr_math_macros",
+ ":hdr_fenv_t"
],
)
@@ -1224,6 +1235,7 @@ libc_function(
deps = [
":__support_common",
":__support_fputil_fenv_impl",
+ ":hdr_fexcept_t"
],
)
@@ -1234,6 +1246,7 @@ libc_function(
deps = [
":__support_common",
":__support_fputil_fenv_impl",
+ ":hdr_fexcept_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 bce1dd786a8508..8bebd644baa76e 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:hdr_fenv_t",
],
)
@@ -77,6 +78,7 @@ libc_test(
],
deps = [
"//libc:__support_fputil_fenv_impl",
+ "//libc:hdr_fexcept_t",
],
)
@@ -115,6 +117,7 @@ libc_test(
],
deps = [
"//libc:__support_fputil_fenv_impl",
+ "//libc:hdr_fenv_t",
],
)
@@ -129,5 +132,6 @@ libc_test(
],
deps = [
"//libc:__support_fputil_fenv_impl",
+ "//libc:hdr_fenv_t",
],
)
>From 94cd81ec00de4daa09a69040d986f1f6464fa638 Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Thu, 11 Apr 2024 19:28:22 -0700
Subject: [PATCH 2/2] format code
---
libc/src/fenv/fegetexceptflag.cpp | 2 +-
libc/src/fenv/feholdexcept.cpp | 2 +-
libc/src/fenv/fesetexceptflag.cpp | 3 +--
libc/test/src/fenv/exception_flags_test.cpp | 1 -
4 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/libc/src/fenv/fegetexceptflag.cpp b/libc/src/fenv/fegetexceptflag.cpp
index a80fdef17c3f6a..2a5c25f382bbbc 100644
--- a/libc/src/fenv/fegetexceptflag.cpp
+++ b/libc/src/fenv/fegetexceptflag.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "hdr/fexcept_t.h"
#include "src/fenv/fegetexceptflag.h"
+#include "hdr/fexcept_t.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/common.h"
diff --git a/libc/src/fenv/feholdexcept.cpp b/libc/src/fenv/feholdexcept.cpp
index 112c20135b90e7..41835f4d5ad051 100644
--- a/libc/src/fenv/feholdexcept.cpp
+++ b/libc/src/fenv/feholdexcept.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "hdr/fenv_t.h"
#include "src/fenv/feholdexcept.h"
+#include "hdr/fenv_t.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/common.h"
diff --git a/libc/src/fenv/fesetexceptflag.cpp b/libc/src/fenv/fesetexceptflag.cpp
index b5a546875e531b..5ef887c0824a6b 100644
--- a/libc/src/fenv/fesetexceptflag.cpp
+++ b/libc/src/fenv/fesetexceptflag.cpp
@@ -6,12 +6,11 @@
//
//===----------------------------------------------------------------------===//
-#include "hdr/fexcept_t.h"
#include "src/fenv/fesetexceptflag.h"
+#include "hdr/fexcept_t.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/common.h"
-
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(int, fesetexceptflag,
diff --git a/libc/test/src/fenv/exception_flags_test.cpp b/libc/test/src/fenv/exception_flags_test.cpp
index 19f9ab1bf0b1ba..b0ce6e8cdff017 100644
--- a/libc/test/src/fenv/exception_flags_test.cpp
+++ b/libc/test/src/fenv/exception_flags_test.cpp
@@ -13,7 +13,6 @@
#include "src/__support/FPUtil/FEnvImpl.h"
#include "test/UnitTest/Test.h"
-
TEST(LlvmLibcFenvTest, GetExceptFlagAndSetExceptFlag) {
// We will disable all exceptions to prevent invocation of the exception
// handler.
More information about the llvm-commits
mailing list