[libc-commits] [libc] f76254d - [libc] Fix implicit conversion error in DyadicFloat::as_mantissa_type(). (#133383)
via libc-commits
libc-commits at lists.llvm.org
Fri Mar 28 05:31:20 PDT 2025
Author: Jesse D
Date: 2025-03-28T08:31:17-04:00
New Revision: f76254d9b2a68e0021d93e682744e4240a2368b9
URL: https://github.com/llvm/llvm-project/commit/f76254d9b2a68e0021d93e682744e4240a2368b9
DIFF: https://github.com/llvm/llvm-project/commit/f76254d9b2a68e0021d93e682744e4240a2368b9.diff
LOG: [libc] Fix implicit conversion error in DyadicFloat::as_mantissa_type(). (#133383)
This is the same fix that was recently applied to
as_mantissa_type_rounded(), but for as_mantissa_type().
Added:
Modified:
libc/src/__support/FPUtil/dyadic_float.h
Removed:
################################################################################
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 65d55e16d95ec..2d181134bc2ae 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -434,7 +434,12 @@ template <size_t Bits> struct DyadicFloat {
if (exponent > 0) {
new_mant <<= exponent;
} else {
- new_mant >>= (-exponent);
+ // Cast the exponent to size_t before negating it, rather than after,
+ // to avoid undefined behavior negating INT_MIN as an integer (although
+ // exponents coming in to this function _shouldn't_ be that large). The
+ // result should always end up as a positive size_t.
+ size_t shift = -static_cast<size_t>(exponent);
+ new_mant >>= shift;
}
if (sign.is_neg()) {
More information about the libc-commits
mailing list