[libc-commits] [libc] cb2e2d5 - [libc] Small adjustments to fenv tests

Michael Jones via libc-commits libc-commits at lists.llvm.org
Mon Feb 1 10:40:39 PST 2021


Author: Michael Jones
Date: 2021-02-01T18:40:32Z
New Revision: cb2e2d506814dc3c06449a87aec180b29f4351d7

URL: https://github.com/llvm/llvm-project/commit/cb2e2d506814dc3c06449a87aec180b29f4351d7
DIFF: https://github.com/llvm/llvm-project/commit/cb2e2d506814dc3c06449a87aec180b29f4351d7.diff

LOG: [libc] Small adjustments to fenv tests

Some libcs define non-standard FE_* macros and include them in
FE_ALL_EXCEPT. This change adjusts the fenv tests so that the
non-standard FE_* macros do not interfere when compiled with
fenv.h from another libc.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D95650

Added: 
    

Modified: 
    libc/test/src/fenv/enabled_exceptions_test.cpp
    libc/test/src/fenv/exception_status_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/fenv/enabled_exceptions_test.cpp b/libc/test/src/fenv/enabled_exceptions_test.cpp
index 81cd4947cc76..e9c2ae86b8c0 100644
--- a/libc/test/src/fenv/enabled_exceptions_test.cpp
+++ b/libc/test/src/fenv/enabled_exceptions_test.cpp
@@ -27,6 +27,12 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndCrash) {
   int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW,
                    FE_UNDERFLOW};
 
+  // We '|' the individual exception flags instead of using FE_ALL_EXCEPT
+  // as it can include non-standard extensions. Note that we should be able
+  // to compile this file with headers from other libcs as well.
+  constexpr int allExcepts =
+      FE_DIVBYZERO | FE_INVALID | FE_INEXACT | FE_OVERFLOW | FE_UNDERFLOW;
+
   for (int e : excepts) {
     ASSERT_DEATH(
         [=] {
@@ -36,7 +42,7 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndCrash) {
           // Raising all exceptions except |e| should not call the
           // SIGFPE handler. They should set the exception flag though,
           // so we verify that.
-          int others = FE_ALL_EXCEPT & ~e;
+          int others = allExcepts & ~e;
           ASSERT_EQ(__llvm_libc::feraiseexcept(others), 0);
           ASSERT_EQ(__llvm_libc::fetestexcept(others), others);
 

diff  --git a/libc/test/src/fenv/exception_status_test.cpp b/libc/test/src/fenv/exception_status_test.cpp
index 466ef7cd6220..12a65bd116f9 100644
--- a/libc/test/src/fenv/exception_status_test.cpp
+++ b/libc/test/src/fenv/exception_status_test.cpp
@@ -24,6 +24,10 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
 
   int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW,
                    FE_UNDERFLOW};
+
+  constexpr int allExcepts =
+      FE_DIVBYZERO | FE_INVALID | FE_INEXACT | FE_OVERFLOW | FE_UNDERFLOW;
+
   for (int e : excepts) {
     int r = __llvm_libc::feraiseexcept(e);
     ASSERT_EQ(r, 0);
@@ -108,8 +112,8 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
     }
   }
 
-  int r = __llvm_libc::feraiseexcept(FE_ALL_EXCEPT);
+  int r = __llvm_libc::feraiseexcept(allExcepts);
   ASSERT_EQ(r, 0);
-  int s = __llvm_libc::fetestexcept(FE_ALL_EXCEPT);
-  ASSERT_EQ(s, FE_ALL_EXCEPT);
+  int s = __llvm_libc::fetestexcept(allExcepts);
+  ASSERT_EQ(s, allExcepts);
 }


        


More information about the libc-commits mailing list