[libc][NFC] Make explicit uint16_t casts in fenv
authorAlex Brachet <abrachet@google.com>
Thu, 16 Jun 2022 16:18:44 +0000 (16:18 +0000)
committerAlex Brachet <abrachet@google.com>
Thu, 16 Jun 2022 16:18:44 +0000 (16:18 +0000)
libc/src/__support/FPUtil/x86_64/FEnvImpl.h
libc/src/fenv/fesetexceptflag.cpp

index 6bac3e9e6a0f180ddabfa09232a0409a3fd22e56..c8e8fcb5448ee2b8bc9e7a7426d73123378dfcf1 100644 (file)
@@ -203,7 +203,8 @@ static inline int get_except() {
 static inline int clear_except(int excepts) {
   internal::X87StateDescriptor state;
   internal::get_x87_state_descriptor(state);
-  state.status_word &= ~internal::get_status_value_for_except(excepts);
+  state.status_word &=
+      static_cast<uint16_t>(~internal::get_status_value_for_except(excepts));
   internal::write_x87_state_descriptor(state);
 
   uint32_t mxcsr = internal::get_mxcsr();
@@ -215,8 +216,8 @@ static inline int clear_except(int excepts) {
 static inline int test_except(int excepts) {
   uint16_t status_value = internal::get_status_value_for_except(excepts);
   // Check both x87 status word and MXCSR.
-  return internal::exception_status_to_macro(status_value &
-                                             internal::get_mxcsr());
+  return internal::exception_status_to_macro(
+      static_cast<uint16_t>(status_value & internal::get_mxcsr()));
 }
 
 // Sets the exception flags but does not trigger the exception handler.
index 7ee9b1c63a3092a9bcc3b594f683c7d4345fbc31..3e134aba7fcf744d57095d6d9a6abcb750915081 100644 (file)
@@ -20,7 +20,7 @@ LLVM_LIBC_FUNCTION(int, fesetexceptflag,
   // 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 = static_cast<const int>(*flagp) & excepts;
+  int excepts_to_set = static_cast<int>(*flagp) & excepts;
   fputil::clear_except(FE_ALL_EXCEPT);
   return fputil::set_except(excepts_to_set);
 }