[libc-commits] [libc] 804dc3d - [libc] Clear all exceptions before setting in fesetexceptflag.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Wed Jun 30 10:29:56 PDT 2021
Author: Siva Chandra Reddy
Date: 2021-06-30T17:29:48Z
New Revision: 804dc3dcf27d10d4cd0af06fdf2999ea81ba751f
URL: https://github.com/llvm/llvm-project/commit/804dc3dcf27d10d4cd0af06fdf2999ea81ba751f
DIFF: https://github.com/llvm/llvm-project/commit/804dc3dcf27d10d4cd0af06fdf2999ea81ba751f.diff
LOG: [libc] Clear all exceptions before setting in fesetexceptflag.
Previously, exceptions from the flag were being added. This patch
changes it such that only the exceptions in the flag will be set.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D105085
Added:
Modified:
libc/src/fenv/fesetexceptflag.cpp
libc/test/src/fenv/exception_flags_test.cpp
Removed:
################################################################################
diff --git a/libc/src/fenv/fesetexceptflag.cpp b/libc/src/fenv/fesetexceptflag.cpp
index 1968ebea5a60b..9ee6205d3a6cc 100644
--- a/libc/src/fenv/fesetexceptflag.cpp
+++ b/libc/src/fenv/fesetexceptflag.cpp
@@ -21,6 +21,7 @@ LLVM_LIBC_FUNCTION(int, fesetexceptflag,
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);
}
diff --git a/libc/test/src/fenv/exception_flags_test.cpp b/libc/test/src/fenv/exception_flags_test.cpp
index e492a21c1b1e2..bb3ddaa7148ac 100644
--- a/libc/test/src/fenv/exception_flags_test.cpp
+++ b/libc/test/src/fenv/exception_flags_test.cpp
@@ -42,4 +42,15 @@ TEST(LlvmLibcFenvTest, GetExceptFlagAndSetExceptFlag) {
// 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);
}
More information about the libc-commits
mailing list