[libc-commits] [PATCH] D152336: [libc] Fix undefined behavior of left shifting signed integer in exp2f.cpp.
Tue Ly via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Jun 6 22:15:48 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0a751ae3da3: [libc] Fix undefined behavior of left shifting signed integer in exp2f.cpp. (authored by lntue).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152336/new/
https://reviews.llvm.org/D152336
Files:
libc/src/math/generic/exp2f.cpp
Index: libc/src/math/generic/exp2f.cpp
===================================================================
--- libc/src/math/generic/exp2f.cpp
+++ libc/src/math/generic/exp2f.cpp
@@ -107,8 +107,9 @@
int k = static_cast<int>(kf);
// hi = floor(kf * 2^(-4))
// exp_hi = shift hi to the exponent field of double precision.
- int64_t exp_hi = static_cast<int64_t>(k >> ExpBase::MID_BITS)
- << fputil::FloatProperties<double>::MANTISSA_WIDTH;
+ int64_t exp_hi =
+ static_cast<int64_t>(static_cast<uint64_t>(k >> ExpBase::MID_BITS)
+ << fputil::FloatProperties<double>::MANTISSA_WIDTH);
// mh = 2^hi * 2^mid
// mh_bits = bit field of mh
int64_t mh_bits = ExpBase::EXP_2_MID[k & ExpBase::MID_MASK] + exp_hi;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152336.529158.patch
Type: text/x-patch
Size: 770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230607/81630e71/attachment-0001.bin>
More information about the libc-commits
mailing list