Skip to content

[libc][math] undef iscanonical before defining it using LLVM_LIBC_FUNCTION macro #110865

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 4 commits into from
Oct 2, 2024

Conversation

Sh0g0-1758
Copy link
Member

@Sh0g0-1758 Sh0g0-1758 commented Oct 2, 2024

It appears that #110565 fails because the macro definition of iscanonical is included somewhere. This PR ensures that the macro expands correctly and also removes the static_cast because implicit conversion from bool to int is defined in C++.

@llvmbot llvmbot added the libc label Oct 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 2, 2024

@llvm/pr-subscribers-libc

Author: Shourya Goel (Sh0g0-1758)

Changes

It appears that #110565 fails because the macro LLVM_LIBC_FUNCTION is not being recognized or expanded properly. This PR expands the macro and also removes the static_assert since conversion from bool to int is well defined in C/C++.


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

5 Files Affected:

  • (modified) libc/src/math/generic/iscanonical.cpp (+2-2)
  • (modified) libc/src/math/generic/iscanonicalf.cpp (+2-2)
  • (modified) libc/src/math/generic/iscanonicalf128.cpp (+2-2)
  • (modified) libc/src/math/generic/iscanonicalf16.cpp (+2-2)
  • (modified) libc/src/math/generic/iscanonicall.cpp (+2-2)
diff --git a/libc/src/math/generic/iscanonical.cpp b/libc/src/math/generic/iscanonical.cpp
index d67a6b87b3e506..69a95c719a85c9 100644
--- a/libc/src/math/generic/iscanonical.cpp
+++ b/libc/src/math/generic/iscanonical.cpp
@@ -13,9 +13,9 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, iscanonical, (double x)) {
+int iscanonical(double x) {
   double temp;
-  return static_cast<int>(fputil::canonicalize(temp, x) == 0);
+  return fputil::canonicalize(temp, x) == 0;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf.cpp b/libc/src/math/generic/iscanonicalf.cpp
index daa0708794d2f4..b27c0fd1fabf44 100644
--- a/libc/src/math/generic/iscanonicalf.cpp
+++ b/libc/src/math/generic/iscanonicalf.cpp
@@ -13,9 +13,9 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, iscanonicalf, (float x)) {
+int iscanonicalf(float x) {
   float temp;
-  return static_cast<int>(fputil::canonicalize(temp, x) == 0);
+  return fputil::canonicalize(temp, x) == 0;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf128.cpp b/libc/src/math/generic/iscanonicalf128.cpp
index 9be50050f8234c..ccd9b34411b2c4 100644
--- a/libc/src/math/generic/iscanonicalf128.cpp
+++ b/libc/src/math/generic/iscanonicalf128.cpp
@@ -13,9 +13,9 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, iscanonicalf128, (float128 x)) {
+int iscanonicalf128(float128 x) {
   float128 temp;
-  return static_cast<int>(fputil::canonicalize(temp, x) == 0);
+  return fputil::canonicalize(temp, x) == 0;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf16.cpp b/libc/src/math/generic/iscanonicalf16.cpp
index 4f7bb1a0050f51..236b6276295137 100644
--- a/libc/src/math/generic/iscanonicalf16.cpp
+++ b/libc/src/math/generic/iscanonicalf16.cpp
@@ -13,9 +13,9 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, iscanonicalf16, (float16 x)) {
+int iscanonicalf16(float16 x) {
   float16 temp;
-  return static_cast<int>(fputil::canonicalize(temp, x) == 0);
+  return fputil::canonicalize(temp, x) == 0;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicall.cpp b/libc/src/math/generic/iscanonicall.cpp
index 756c1f8fb4abfa..9aa28ecccf6a86 100644
--- a/libc/src/math/generic/iscanonicall.cpp
+++ b/libc/src/math/generic/iscanonicall.cpp
@@ -13,9 +13,9 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, iscanonicall, (long double x)) {
+int iscanonicall(long double x) {
   long double temp;
-  return static_cast<int>(fputil::canonicalize(temp, x) == 0);
+  return fputil::canonicalize(temp, x) == 0;
 }
 
 } // namespace LIBC_NAMESPACE_DECL

@Sh0g0-1758 Sh0g0-1758 changed the title [libc][math] exapnd macro definition for iscanonical variants [libc][math] undef iscanonical before defining it using LLVM_LIBC_FUNCTION macro Oct 2, 2024
@Sh0g0-1758 Sh0g0-1758 changed the title [libc][math] undef iscanonical before defining it using LLVM_LIBC_FUNCTION macro [libc][math] undef iscanonical before defining it using LLVM_LIBC_FUNCTION macro Oct 2, 2024
@nickdesaulniers nickdesaulniers requested a review from lntue October 2, 2024 16:00
@overmighty
Copy link
Member

removes the static_assert since conversion from bool to int is well defined in C/C++.

Nit: removes the static_cast because implicit conversion from bool to int is defined in C++.

@lntue lntue merged commit 2b8e81c into llvm:main Oct 2, 2024
5 of 6 checks passed
@nickdesaulniers
Copy link
Member

the macro definition of iscanonical is included somewhere

ah interesting find. Would be good to know more & get to the bottom of that.

Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Oct 3, 2024
…FUNCTION` macro (llvm#110865)

It appears that llvm#110565 fails because the macro definition of
iscanonical is included somewhere. This PR ensures that the macro
expands correctly and also removes the static_cast because implicit
conversion from bool to int is defined in C++.
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.

5 participants