[libc-commits] [libc] 9550f8b - [libc][NFC] Make few fenv functions work with fexcept_t from other libcs.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Thu Mar 4 11:25:39 PST 2021


Author: Siva Chandra Reddy
Date: 2021-03-04T11:25:28-08:00
New Revision: 9550f8ba9a3a697f28a7920c8aeb5cba1e8003a6

URL: https://github.com/llvm/llvm-project/commit/9550f8ba9a3a697f28a7920c8aeb5cba1e8003a6
DIFF: https://github.com/llvm/llvm-project/commit/9550f8ba9a3a697f28a7920c8aeb5cba1e8003a6.diff

LOG: [libc][NFC] Make few fenv functions work with fexcept_t from other libcs.

Added: 
    

Modified: 
    libc/src/fenv/fegetexceptflag.cpp
    libc/src/fenv/fesetexceptflag.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/fenv/fegetexceptflag.cpp b/libc/src/fenv/fegetexceptflag.cpp
index 06ca56e55ed4..24620b0f0164 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<int *>(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<fexcept_t>(fputil::testExcept(FE_ALL_EXCEPT) & excepts);
   return 0;
 }
 

diff  --git a/libc/src/fenv/fesetexceptflag.cpp b/libc/src/fenv/fesetexceptflag.cpp
index 3c88d63dffbe..8d44a0447f70 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<const int *>(flagp) & excepts;
   return fputil::setExcept(excepts_to_set);
 }


        


More information about the libc-commits mailing list