Skip to content

[libc] Remove FE_ALL_EXCEPT check in hdr/fenv_macros.h. #114446

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 1 commit into from
Nov 1, 2024
Merged

Conversation

lntue
Copy link
Contributor

@lntue lntue commented Oct 31, 2024

FE_ALL_EXCEPT macro might not be a valid preprocessor constant expression in some environment.
Moreover, FE_ALL_EXCEPT might not be defined as int.

FE_ALL_EXCEPT macro might not be a valid preprocessor constant expression on some environment.
Moreover, FE_ALL_EXCEPT might not be defined as int.
@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2024

@llvm/pr-subscribers-libc

Author: None (lntue)

Changes

FE_ALL_EXCEPT macro might not be a valid preprocessor constant expression in some environment.
Moreover, FE_ALL_EXCEPT might not be defined as int.


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

2 Files Affected:

  • (modified) libc/hdr/fenv_macros.h (-7)
  • (modified) libc/test/UnitTest/FPMatcher.h (+13-9)
diff --git a/libc/hdr/fenv_macros.h b/libc/hdr/fenv_macros.h
index a2e4462ef02dca..3f0bd89a6ea354 100644
--- a/libc/hdr/fenv_macros.h
+++ b/libc/hdr/fenv_macros.h
@@ -19,7 +19,6 @@
 
 // In some environment, FE_ALL_EXCEPT is set to 0 and the remaining exceptions
 // FE_* are missing.
-#if (FE_ALL_EXCEPT == 0)
 #ifndef FE_DIVBYZERO
 #define FE_DIVBYZERO 0
 #endif // FE_DIVBYZERO
@@ -39,12 +38,6 @@
 #ifndef FE_UNDERFLOW
 #define FE_UNDERFLOW 0
 #endif // FE_UNDERFLOW
-#else
-// If this is not provided by the system, define it for use internally.
-#ifndef __FE_DENORM
-#define __FE_DENORM (1 << 6)
-#endif
-#endif
 
 // Rounding mode macros might be missing.
 #ifndef FE_DOWNWARD
diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h
index 7fcc6a32025b5d..55fe73cd2f1ac9 100644
--- a/libc/test/UnitTest/FPMatcher.h
+++ b/libc/test/UnitTest/FPMatcher.h
@@ -297,31 +297,35 @@ struct ModifyMXCSR {
 #define EXPECT_FP_EXCEPTION(expected)                                          \
   do {                                                                         \
     if (math_errhandling & MATH_ERREXCEPT) {                                   \
-      EXPECT_EQ(LIBC_NAMESPACE::fputil::test_except(FE_ALL_EXCEPT) &           \
-                    ((expected) ? (expected) : FE_ALL_EXCEPT),                 \
-                (expected));                                                   \
+      EXPECT_EQ(                                                               \
+          LIBC_NAMESPACE::fputil::test_except(                                 \
+              static_cast<int>(FE_ALL_EXCEPT)) &                               \
+              ((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)),     \
+          (expected));                                                         \
     }                                                                          \
   } while (0)
 
 #define ASSERT_FP_EXCEPTION(expected)                                          \
   do {                                                                         \
     if (math_errhandling & MATH_ERREXCEPT) {                                   \
-      ASSERT_EQ(LIBC_NAMESPACE::fputil::test_except(FE_ALL_EXCEPT) &           \
-                    ((expected) ? (expected) : FE_ALL_EXCEPT),                 \
-                (expected));                                                   \
+      ASSERT_EQ(                                                               \
+          LIBC_NAMESPACE::fputil::test_except(                                 \
+              static_cast<int>(FE_ALL_EXCEPT)) &                               \
+              ((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)),     \
+          (expected));                                                         \
     }                                                                          \
   } while (0)
 
 #define EXPECT_FP_EQ_WITH_EXCEPTION(expected_val, actual_val, expected_except) \
   do {                                                                         \
-    LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);                       \
+    LIBC_NAMESPACE::fputil::clear_except(static_cast<int>(FE_ALL_EXCEPT));     \
     EXPECT_FP_EQ(expected_val, actual_val);                                    \
     EXPECT_FP_EXCEPTION(expected_except);                                      \
   } while (0)
 
 #define EXPECT_FP_IS_NAN_WITH_EXCEPTION(actual_val, expected_except)           \
   do {                                                                         \
-    LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);                       \
+    LIBC_NAMESPACE::fputil::clear_except(static_cast<int>(FE_ALL_EXCEPT));     \
     EXPECT_FP_IS_NAN(actual_val);                                              \
     EXPECT_FP_EXCEPTION(expected_except);                                      \
   } while (0)
@@ -374,7 +378,7 @@ struct ModifyMXCSR {
     using namespace LIBC_NAMESPACE::fputil::testing;                           \
     ForceRoundingMode __r((rounding_mode));                                    \
     if (__r.success) {                                                         \
-      LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);                     \
+      LIBC_NAMESPACE::fputil::clear_except(static_cast<int>(FE_ALL_EXCEPT));   \
       EXPECT_FP_EQ((expected), (actual));                                      \
       EXPECT_FP_EXCEPTION(expected_except);                                    \
     }                                                                          \

EXPECT_EQ( \
LIBC_NAMESPACE::fputil::test_except( \
static_cast<int>(FE_ALL_EXCEPT)) & \
((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)), \
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not an expert but shouldn't all cast be to unsigned int rather then int?
This applies to all occurrences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fetestexcept is specified to take an int instead of unsigned int https://en.cppreference.com/w/c/numeric/fenv/fetestexcept

@lntue lntue merged commit 5cb7305 into llvm:main Nov 1, 2024
9 checks passed
@lntue lntue deleted the fenv branch November 1, 2024 02:24
smallp-o-p pushed a commit to smallp-o-p/llvm-project that referenced this pull request Nov 3, 2024
FE_ALL_EXCEPT macro might not be a valid preprocessor constant
expression in some environment.
Moreover, FE_ALL_EXCEPT might not be defined as int.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
FE_ALL_EXCEPT macro might not be a valid preprocessor constant
expression in some environment.
Moreover, FE_ALL_EXCEPT might not be defined as int.
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.

4 participants