[libc-commits] [libc] 578a4cf - [libc][NFC] Clear all exceptions in exception_flags_test before raising another.

Siva Chandra via libc-commits libc-commits at lists.llvm.org
Wed Jun 30 13:49:03 PDT 2021


Author: Siva Chandra
Date: 2021-06-30T13:48:07-07:00
New Revision: 578a4cfe19121df5e5e02bf03482233e3bc56a0d

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

LOG: [libc][NFC] Clear all exceptions in exception_flags_test before raising another.

This is because, raising some exceptions can raise other ones. For
example, raising FE_OVERFLOW can raise FE_INEXACT. So, we need to clear all
exceptions if we want a clean slate.

Added: 
    

Modified: 
    libc/test/src/fenv/exception_flags_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/fenv/exception_flags_test.cpp b/libc/test/src/fenv/exception_flags_test.cpp
index bb3ddaa7148a..855ba7c9248d 100644
--- a/libc/test/src/fenv/exception_flags_test.cpp
+++ b/libc/test/src/fenv/exception_flags_test.cpp
@@ -18,6 +18,7 @@ TEST(LlvmLibcFenvTest, GetExceptFlagAndSetExceptFlag) {
   // We will disable all exceptions to prevent invocation of the exception
   // handler.
   __llvm_libc::fputil::disableExcept(FE_ALL_EXCEPT);
+  __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT);
 
   int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW,
                    FE_UNDERFLOW};
@@ -39,8 +40,9 @@ TEST(LlvmLibcFenvTest, GetExceptFlagAndSetExceptFlag) {
     ASSERT_EQ(__llvm_libc::fesetexceptflag(&eflags, FE_ALL_EXCEPT), 0);
     ASSERT_NE(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT) & e, 0);
 
-    // Cleanup
-    __llvm_libc::fputil::clearExcept(e);
+    // Cleanup. We clear all excepts as raising excepts like FE_OVERFLOW
+    // can also raise FE_INEXACT.
+    __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT);
   }
 
   // Next, we will raise one exception and save the flags.


        


More information about the libc-commits mailing list