-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Create a separate proxy header for math-function-macros.h #98430
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
Conversation
@llvm/pr-subscribers-libc Author: Nhat Nguyen (changkhothuychung) ChangesFix #98393 Full diff: https://github.com/llvm/llvm-project/pull/98430.diff 3 Files Affected:
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
|
libc/hdr/math_macros.h
Outdated
@@ -21,7 +21,6 @@ | |||
#if defined(__GNUC__) && !defined(__clang__) | |||
#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS | |||
#endif | |||
#include <math.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<math.h>
should be included in the overlay mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain me why it is needed in overlay mode ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at other proxy headers in libc/hdr/
folder, the structure is that if it is in full build mode (detected with #ifdef LIBC_FULL_BUILD
, then we include our own headers in libc/include/llvm-libc-*
. OTOH, if it is in overlay mode, we will just use the corresponding system header. And in this case, the corresponding system header is <math.h>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main purpose of proxy headers in libc/hdr
is to provide a clear separation between our own public headers and the system headers, make sure that they won't be mixed and mismatched in different build modes.
When building the current PR's head in full build mode, some of the tests that rely on math function macros failed to build. You should update those tests to use To reproduce:
Some of the failures:
|
I dont see Which function are you referring to? |
https://github.com/llvm/llvm-project/blob/main/libc/src/__support/FPUtil/FPBits.h#L660-L672 |
@lntue some of the tests derive the type directly, thus I can't use the functions is_nan() and is_inf() from FPBits, do u have any recommendations to handle this? For example this test - https://github.com/llvm/llvm-project/blob/main/libc/test/src/math/atan2f_test.cpp#L80-L81 |
For something like that, you can feed the floating point variables back to
|
thanks, and how about this case ? https://github.com/llvm/llvm-project/blob/main/libc/test/src/math/atan2f_test.cpp#L85-L87 Should I create a FPBits from result and perform is_nan and is_inf check for it? |
Yes, that would be the most straightforward way to do it. And for |
@lntue do you have any idea why there are some erros with undeclared identifier? I see the file FPBits.h is included. |
The failure in |
@lntue CI looks good, can you help me confirm the full build mode? my laptop (mac m1) has issues with building libc on full build mode. |
@@ -34,7 +36,7 @@ TEST_F(LlvmLibcExplogfTest, ExpInFloatRange) { | |||
return static_cast<float>(result.mh * r); | |||
}; | |||
auto f_check = [](float x) -> bool { | |||
return !((isnan(x) || isinf(x) || x < -70 || x > 70 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will also need to be fully qualified. Maybe you can have using FPBits = LIBC_NAMESPACE::fputil::FPBits<float>
at the beginning of the file, and the all subsequence usage can just be FPBits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the issue!
Fix #98393