[libc-commits] [libc] [libc][fenv] Add compile time check (PR #87826)

via libc-commits libc-commits at lists.llvm.org
Fri Apr 5 13:07:29 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Robin Caloudis (robincaloudis)

<details>
<summary>Changes</summary>

Take care of a TODO. This
check makes sure that the fexcept_t
value fits in an int value.

---
Full diff: https://github.com/llvm/llvm-project/pull/87826.diff


1 Files Affected:

- (modified) libc/src/fenv/fegetexceptflag.cpp (+2-1) 


``````````diff
diff --git a/libc/src/fenv/fegetexceptflag.cpp b/libc/src/fenv/fegetexceptflag.cpp
index 71b87ce7315d1a..c6160da7afbde2 100644
--- a/libc/src/fenv/fegetexceptflag.cpp
+++ b/libc/src/fenv/fegetexceptflag.cpp
@@ -15,7 +15,8 @@
 namespace LIBC_NAMESPACE {
 
 LLVM_LIBC_FUNCTION(int, fegetexceptflag, (fexcept_t * flagp, int excepts)) {
-  // TODO: Add a compile time check to see if the excepts actually fit in flagp.
+  static_assert(sizeof(int) >= sizeof(fexcept_t),
+                "fexcept_t value cannot fit in an int value.");
   *flagp = static_cast<fexcept_t>(fputil::test_except(FE_ALL_EXCEPT) & excepts);
   return 0;
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/87826


More information about the libc-commits mailing list