Skip to content

Commit 9550f8b

Browse files
author
Siva Chandra Reddy
committed
[libc][NFC] Make few fenv functions work with fexcept_t from other libcs.
1 parent c16fef1 commit 9550f8b

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

libc/src/fenv/fegetexceptflag.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
namespace __llvm_libc {
1616

1717
LLVM_LIBC_FUNCTION(int, fegetexceptflag, (fexcept_t * flagp, int excepts)) {
18-
// Since the return type of fetestexcept is int, we ensure that fexcept_t
19-
// matches in size.
20-
static_assert(sizeof(int) == sizeof(fexcept_t),
21-
"sizeof(fexcept_t) != sizeof(int)");
22-
*reinterpret_cast<int *>(flagp) = fputil::testExcept(FE_ALL_EXCEPT) & excepts;
18+
// TODO: Add a compile time check to see if the excepts actually fit in flagp.
19+
*flagp = static_cast<fexcept_t>(fputil::testExcept(FE_ALL_EXCEPT) & excepts);
2320
return 0;
2421
}
2522

libc/src/fenv/fesetexceptflag.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ namespace __llvm_libc {
1717
LLVM_LIBC_FUNCTION(int, fesetexceptflag,
1818
(const fexcept_t *flagp, int excepts)) {
1919
// Since the return type of fetestexcept is int, we ensure that fexcept_t
20-
// matches in size.
21-
static_assert(sizeof(int) == sizeof(fexcept_t),
22-
"sizeof(fexcept_t) != sizeof(int)");
20+
// can fit in int type.
21+
static_assert(sizeof(int) >= sizeof(fexcept_t),
22+
"fexcept_t value cannot fit in an int value.");
2323
int excepts_to_set = *reinterpret_cast<const int *>(flagp) & excepts;
2424
return fputil::setExcept(excepts_to_set);
2525
}

0 commit comments

Comments
 (0)