From 40a55fff0517b5e3093d00a4ec634bb4c29e4abb Mon Sep 17 00:00:00 2001 From: Alex Brachet Date: Thu, 16 Jun 2022 16:18:44 +0000 Subject: [PATCH] [libc][NFC] Make explicit uint16_t casts in fenv --- libc/src/__support/FPUtil/x86_64/FEnvImpl.h | 7 ++++--- libc/src/fenv/fesetexceptflag.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h index 6bac3e9e6a0f..c8e8fcb5448e 100644 --- a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h +++ b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h @@ -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(~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(status_value & internal::get_mxcsr())); } // Sets the exception flags but does not trigger the exception handler. diff --git a/libc/src/fenv/fesetexceptflag.cpp b/libc/src/fenv/fesetexceptflag.cpp index 7ee9b1c63a30..3e134aba7fcf 100644 --- a/libc/src/fenv/fesetexceptflag.cpp +++ b/libc/src/fenv/fesetexceptflag.cpp @@ -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(*flagp) & excepts; + int excepts_to_set = static_cast(*flagp) & excepts; fputil::clear_except(FE_ALL_EXCEPT); return fputil::set_except(excepts_to_set); }