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

Robin Caloudis via libc-commits libc-commits at lists.llvm.org
Fri Apr 5 13:06:59 PDT 2024


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

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

>From b6980db5db29fe8750e068487d25e3b5a38e15cb Mon Sep 17 00:00:00 2001
From: Robin Caloudis <robin.caloudis at gmx.de>
Date: Fri, 5 Apr 2024 21:56:52 +0200
Subject: [PATCH] Add compile time check

Take care of a TODO. This
check makes sure that the fexcept_t
value fits in an int value.
---
 libc/src/fenv/fegetexceptflag.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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



More information about the libc-commits mailing list