[libc-commits] [libc] [libc] Create a separate proxy header for math-function-macros.h (PR #98430)

Nhat Nguyen via libc-commits libc-commits at lists.llvm.org
Thu Jul 11 22:08:53 PDT 2024


https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/98430

>From 8a5fa39a71ee782a0ee477e292151cf65a4d5018 Mon Sep 17 00:00:00 2001
From: changkhothuychung <nhat7203 at gmail.com>
Date: Thu, 11 Jul 2024 00:59:47 -0400
Subject: [PATCH 1/3] initial attempt

---
 libc/hdr/CMakeLists.txt         |  7 +++++++
 libc/hdr/math_function_macros.h | 14 ++++++++++++++
 libc/hdr/math_macros.h          |  2 --
 3 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 libc/hdr/math_function_macros.h

diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 7549342514304..4c47f38a1ffe8 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -29,6 +29,13 @@ add_proxy_header_library(
     math_macros.h
   FULL_BUILD_DEPENDS
     libc.include.llvm-libc-macros.math_macros
+)
+
+add_proxy_header_library(
+  math_function_macros
+  HDRS
+    math_function_macros.h
+  FULL_BUILD_DEPENDS
     libc.include.math
 )
 
diff --git a/libc/hdr/math_function_macros.h b/libc/hdr/math_function_macros.h
new file mode 100644
index 0000000000000..c2de468af61b0
--- /dev/null
+++ b/libc/hdr/math_function_macros.h
@@ -0,0 +1,14 @@
+//===-- 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_FUNCTION_MACROS_H
+#define LLVM_LIBC_HDR_MATH_FUNCTION_MACROS_H
+
+#include <math.h>
+
+#endif // LLVM_LIBC_HDR_MATH_MACROS_H
diff --git a/libc/hdr/math_macros.h b/libc/hdr/math_macros.h
index d13c5ff7647ad..135ffd498b9a0 100644
--- a/libc/hdr/math_macros.h
+++ b/libc/hdr/math_macros.h
@@ -15,8 +15,6 @@
 
 #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

>From 1b405c6e2be95b881b238ceab407085610a9f3e5 Mon Sep 17 00:00:00 2001
From: changkhothuychung <nhat7203 at gmail.com>
Date: Thu, 11 Jul 2024 01:03:45 -0400
Subject: [PATCH 2/3] some fix

---
 libc/hdr/math_macros.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libc/hdr/math_macros.h b/libc/hdr/math_macros.h
index d5a823723747c..8dd6862863cd4 100644
--- a/libc/hdr/math_macros.h
+++ b/libc/hdr/math_macros.h
@@ -21,7 +21,6 @@
 #if defined(__GNUC__) && !defined(__clang__)
 #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 #endif
-#include <math.h>
 
 // Some older math.h header does not have FP_INT_* constants yet.
 #ifndef FP_INT_UPWARD

>From e765d5dc043c73df03b074c9e42c585a4642650a Mon Sep 17 00:00:00 2001
From: changkhothuychung <nhat7203 at gmail.com>
Date: Fri, 12 Jul 2024 01:08:38 -0400
Subject: [PATCH 3/3] some fix

---
 libc/hdr/CMakeLists.txt         |  2 ++
 libc/hdr/math_function_macros.h | 13 +++++++++++++
 libc/hdr/math_macros.h          |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 6fa497fd79ce5..2588eb0cd50bc 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -29,6 +29,7 @@ add_proxy_header_library(
     math_macros.h
   FULL_BUILD_DEPENDS
     libc.include.llvm-libc-macros.math_macros
+    libc.include.math
 )
 
 add_proxy_header_library(
@@ -36,6 +37,7 @@ add_proxy_header_library(
   HDRS
     math_function_macros.h
   FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-macros.math_function_macros
     libc.include.math
 )
 
diff --git a/libc/hdr/math_function_macros.h b/libc/hdr/math_function_macros.h
index c2de468af61b0..48dec8260ef89 100644
--- a/libc/hdr/math_function_macros.h
+++ b/libc/hdr/math_function_macros.h
@@ -9,6 +9,19 @@
 #ifndef LLVM_LIBC_HDR_MATH_FUNCTION_MACROS_H
 #define LLVM_LIBC_HDR_MATH_FUNCTION_MACROS_H
 
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-macros/math-function-macros.h"
+
+#else // Overlay mode
+
+// GCC will include CXX headers when __cplusplus is defined. This behavior
+// can be suppressed by defining _GLIBCXX_INCLUDE_NEXT_C_HEADERS.
+#if defined(__GNUC__) && !defined(__clang__)
+#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+#endif
 #include <math.h>
 
+#endif // LLVM_LIBC_FULL_BUILD
+
 #endif // LLVM_LIBC_HDR_MATH_MACROS_H
diff --git a/libc/hdr/math_macros.h b/libc/hdr/math_macros.h
index 8dd6862863cd4..863451123f3f8 100644
--- a/libc/hdr/math_macros.h
+++ b/libc/hdr/math_macros.h
@@ -11,7 +11,6 @@
 
 #ifdef LIBC_FULL_BUILD
 
-#include "include/llvm-libc-macros/math-function-macros.h"
 #include "include/llvm-libc-macros/math-macros.h"
 
 #else // Overlay mode
@@ -21,6 +20,7 @@
 #if defined(__GNUC__) && !defined(__clang__)
 #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 #endif
+#include <math.h>
 
 // Some older math.h header does not have FP_INT_* constants yet.
 #ifndef FP_INT_UPWARD



More information about the libc-commits mailing list