[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
This commit is contained in:
Siva Chandra Reddy 2021-06-29 06:37:56 +00:00
parent 0c2f40f916
commit 804dc3dcf2
2 changed files with 12 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);
}