[libc-commits] [PATCH] D105085: [libc] Clear all exceptions before setting in fesetexceptflag.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Jun 28 23:40:45 PDT 2021


sivachandra created this revision.
sivachandra added a reviewer: lntue.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added a project: libc-project.
sivachandra requested review of this revision.

Previously, exceptions from the flag were being added. This patch
changes it such that only the exceptions in the flag will be set.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105085

Files:
  libc/src/fenv/fesetexceptflag.cpp
  libc/test/src/fenv/exception_flags_test.cpp


Index: libc/test/src/fenv/exception_flags_test.cpp
===================================================================
--- libc/test/src/fenv/exception_flags_test.cpp
+++ libc/test/src/fenv/exception_flags_test.cpp
@@ -42,4 +42,15 @@
     // Cleanup
     __llvm_libc::fputil::clearExcept(e);
   }
+
+  // Next, we will raise one exception and save the flags.
+  __llvm_libc::fputil::raiseExcept(FE_INVALID);
+  fexcept_t eflags;
+  __llvm_libc::fegetexceptflag(&eflags, FE_ALL_EXCEPT);
+  // Clear all exceptions and raise two other exceptions.
+  __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT);
+  __llvm_libc::fputil::raiseExcept(FE_OVERFLOW | FE_INEXACT);
+  // When we set the flags and test, we should only see FE_INVALID.
+  __llvm_libc::fesetexceptflag(&eflags, FE_ALL_EXCEPT);
+  EXPECT_EQ(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT), FE_INVALID);
 }
Index: libc/src/fenv/fesetexceptflag.cpp
===================================================================
--- libc/src/fenv/fesetexceptflag.cpp
+++ libc/src/fenv/fesetexceptflag.cpp
@@ -21,6 +21,7 @@
   static_assert(sizeof(int) >= sizeof(fexcept_t),
                 "fexcept_t value cannot fit in an int value.");
   int excepts_to_set = static_cast<const int>(*flagp) & excepts;
+  fputil::clearExcept(FE_ALL_EXCEPT);
   return fputil::setExcept(excepts_to_set);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105085.355118.patch
Type: text/x-patch
Size: 1337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210629/6dd45441/attachment.bin>


More information about the libc-commits mailing list