Skip to content
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

[libc] Add float.h header. #78737

Merged
merged 2 commits into from
Jan 19, 2024
Merged

[libc] Add float.h header. #78737

merged 2 commits into from
Jan 19, 2024

Conversation

lntue
Copy link
Contributor

@lntue lntue commented Jan 19, 2024

No description provided.

@llvmbot
Copy link

llvmbot commented Jan 19, 2024

@llvm/pr-subscribers-libc

Author: None (lntue)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/78737.diff

14 Files Affected:

  • (modified) libc/config/baremetal/arm/headers.txt (+1)
  • (modified) libc/config/baremetal/riscv/headers.txt (+1)
  • (modified) libc/config/darwin/arm/headers.txt (+1)
  • (modified) libc/config/darwin/x86_64/headers.txt (+1)
  • (modified) libc/config/gpu/headers.txt (+1)
  • (modified) libc/config/linux/aarch64/headers.txt (+1)
  • (modified) libc/config/linux/arm/headers.txt (+1)
  • (modified) libc/config/linux/riscv/headers.txt (+1)
  • (modified) libc/config/linux/x86_64/headers.txt (+1)
  • (modified) libc/include/CMakeLists.txt (+8)
  • (added) libc/include/float.h.def (+14)
  • (modified) libc/include/llvm-libc-macros/CMakeLists.txt (+6)
  • (added) libc/include/llvm-libc-macros/float-macros.h (+21)
  • (modified) libc/spec/stdc.td (+10)
diff --git a/libc/config/baremetal/arm/headers.txt b/libc/config/baremetal/arm/headers.txt
index 6ff51f9786772b..38899fabd980c9 100644
--- a/libc/config/baremetal/arm/headers.txt
+++ b/libc/config/baremetal/arm/headers.txt
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.ctype
     libc.include.fenv
     libc.include.errno
+    libc.include.float
     libc.include.inttypes
     libc.include.math
     libc.include.stdio
diff --git a/libc/config/baremetal/riscv/headers.txt b/libc/config/baremetal/riscv/headers.txt
index 6ff51f9786772b..38899fabd980c9 100644
--- a/libc/config/baremetal/riscv/headers.txt
+++ b/libc/config/baremetal/riscv/headers.txt
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.ctype
     libc.include.fenv
     libc.include.errno
+    libc.include.float
     libc.include.inttypes
     libc.include.math
     libc.include.stdio
diff --git a/libc/config/darwin/arm/headers.txt b/libc/config/darwin/arm/headers.txt
index 7366c530304d47..2dd54b7c1f5053 100644
--- a/libc/config/darwin/arm/headers.txt
+++ b/libc/config/darwin/arm/headers.txt
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.ctype
     libc.include.errno
     libc.include.fenv
+    libc.include.float
     libc.include.inttypes
     libc.include.math
     libc.include.stdlib
diff --git a/libc/config/darwin/x86_64/headers.txt b/libc/config/darwin/x86_64/headers.txt
index b33fa45e420802..510d62688a45fa 100644
--- a/libc/config/darwin/x86_64/headers.txt
+++ b/libc/config/darwin/x86_64/headers.txt
@@ -3,6 +3,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.errno
     # Fenv is currently disabled.
     #libc.include.fenv
+    libc.include.float
     libc.include.inttypes
     libc.include.math
     libc.include.stdlib
diff --git a/libc/config/gpu/headers.txt b/libc/config/gpu/headers.txt
index dae01310fe9c31..e68e18b87b10e2 100644
--- a/libc/config/gpu/headers.txt
+++ b/libc/config/gpu/headers.txt
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.assert
     libc.include.ctype
     libc.include.string
+    libc.include.float
     libc.include.inttypes
     libc.include.math
     libc.include.fenv
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index cfca5959b5ffa5..6a4a4aaeb0a8d4 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.errno
     libc.include.features
     libc.include.fenv
+    libc.include.float
     libc.include.inttypes
     libc.include.math
     libc.include.pthread
diff --git a/libc/config/linux/arm/headers.txt b/libc/config/linux/arm/headers.txt
index bd08d8f8fa437f..9e6ee51675916e 100644
--- a/libc/config/linux/arm/headers.txt
+++ b/libc/config/linux/arm/headers.txt
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.ctype
     libc.include.fenv
     libc.include.errno
+    libc.include.float
     libc.include.inttypes
     libc.include.math
     libc.include.stdlib
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index 9c70a3bde74f05..dc1daa48f6c875 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -6,6 +6,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.fcntl
     libc.include.features
     libc.include.fenv
+    libc.include.float
     libc.include.inttypes
     libc.include.math
     libc.include.pthread
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index a85f87b2a3ee98..b0e0219a30e673 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -6,6 +6,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.fcntl
     libc.include.features
     libc.include.fenv
+    libc.include.float
     libc.include.inttypes
     libc.include.math
     libc.include.pthread
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 9a06f829eee18a..14aa9ec6d73f3e 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -75,6 +75,14 @@ add_gen_header(
     .llvm-libc-types.imaxdiv_t
 )
 
+add_gen_header(
+  float
+  DEF_FILE float.h.def
+  GEN_HDR float.h
+  DEPENDS
+    .llvm-libc-macros.float_macros
+)
+
 add_gen_header(
   math
   DEF_FILE math.h.def
diff --git a/libc/include/float.h.def b/libc/include/float.h.def
new file mode 100644
index 00000000000000..6d3599d78c69e3
--- /dev/null
+++ b/libc/include/float.h.def
@@ -0,0 +1,14 @@
+//===-- C standard library header float.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_FLOAT_H
+#define LLVM_LIBC_FLOAT_H
+
+#include <llvm-libc-macros/float-macros.h>
+
+#endif // LLVM_LIBC_FLOAT_H
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 7b2616d4311d94..d965a6a9443ed2 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -67,6 +67,12 @@ add_macro_header(
     file-seek-macros.h
 )
 
+add_macro_header(
+  float_macros
+  HDR
+    float-macros.h
+)
+
 add_macro_header(
   math_macros
   HDR
diff --git a/libc/include/llvm-libc-macros/float-macros.h b/libc/include/llvm-libc-macros/float-macros.h
new file mode 100644
index 00000000000000..0f262c1dd3fdda
--- /dev/null
+++ b/libc/include/llvm-libc-macros/float-macros.h
@@ -0,0 +1,21 @@
+//===-- Definition of macros from float.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_MACROS_FLOAT_MACROS_H
+#define __LLVM_LIBC_MACROS_FLOAT_MACROS_H
+
+#undef FLT_MANT_DIG
+#define FLT_MANT_DIG __FLT_MANT_DIG__
+
+#undef DBL_MANT_DIG
+#define DBL_MANT_DIG __DBL_MANT_DIG__
+
+#undef LDBL_MANT_DIG
+#define LDBL_MANT_DIG __LDBL_MANT_DIG__
+
+#endif // __LLVM_LIBC_MACROS_FLOAT_MACROS_H
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 714dc21f95ba54..99e9b3ca65ca59 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -847,6 +847,15 @@ def StdC : StandardSpec<"stdc"> {
       ]
   >;
 
+  HeaderSpec Float = HeaderSpec<
+      "float.h",
+      [
+        Macro<"FLT_MANT_DIG">,
+        Macro<"DBL_MANT_DIG">,
+        Macro<"LDBL_MANT_DIG">,
+      ]
+  >;
+
   NamedType SigAtomicT = NamedType<"sig_atomic_t">;
   HeaderSpec Signal = HeaderSpec<
       "signal.h",
@@ -1149,6 +1158,7 @@ def StdC : StandardSpec<"stdc"> {
     CType,
     Errno,
     Fenv,
+    Float,
     Math,
     String,
     StdIO,

Copy link

github-actions bot commented Jan 19, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@gchatelet gchatelet left a comment

Choose a reason for hiding this comment

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

LGTM

@lntue lntue merged commit c80d68a into llvm:main Jan 19, 2024
4 checks passed
@lntue lntue deleted the float branch January 19, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants