From 9550f8ba9a3a697f28a7920c8aeb5cba1e8003a6 Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Thu, 4 Mar 2021 11:16:26 -0800 Subject: [PATCH] [libc][NFC] Make few fenv functions work with fexcept_t from other libcs. --- libc/src/fenv/fegetexceptflag.cpp | 7 ++----- libc/src/fenv/fesetexceptflag.cpp | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libc/src/fenv/fegetexceptflag.cpp b/libc/src/fenv/fegetexceptflag.cpp index 06ca56e..24620b0 100644 --- a/libc/src/fenv/fegetexceptflag.cpp +++ b/libc/src/fenv/fegetexceptflag.cpp @@ -15,11 +15,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fegetexceptflag, (fexcept_t * flagp, int excepts)) { - // Since the return type of fetestexcept is int, we ensure that fexcept_t - // matches in size. - static_assert(sizeof(int) == sizeof(fexcept_t), - "sizeof(fexcept_t) != sizeof(int)"); - *reinterpret_cast(flagp) = fputil::testExcept(FE_ALL_EXCEPT) & excepts; + // TODO: Add a compile time check to see if the excepts actually fit in flagp. + *flagp = static_cast(fputil::testExcept(FE_ALL_EXCEPT) & excepts); return 0; } diff --git a/libc/src/fenv/fesetexceptflag.cpp b/libc/src/fenv/fesetexceptflag.cpp index 3c88d63..8d44a04 100644 --- a/libc/src/fenv/fesetexceptflag.cpp +++ b/libc/src/fenv/fesetexceptflag.cpp @@ -17,9 +17,9 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fesetexceptflag, (const fexcept_t *flagp, int excepts)) { // Since the return type of fetestexcept is int, we ensure that fexcept_t - // matches in size. - static_assert(sizeof(int) == sizeof(fexcept_t), - "sizeof(fexcept_t) != sizeof(int)"); + // can fit in int type. + static_assert(sizeof(int) >= sizeof(fexcept_t), + "fexcept_t value cannot fit in an int value."); int excepts_to_set = *reinterpret_cast(flagp) & excepts; return fputil::setExcept(excepts_to_set); } -- 2.7.4