[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 21:34:22 PDT 2023
lntue created this revision.
lntue added reviewers: michaelrj, sivachandra, brooksmoses.
Herald added projects: libc-project, All.
lntue requested review of this revision.
Fix undefined behavior of left shifting signed integer in exp2f.cpp.
Repository:
rG LLVM Github Monorepo
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.529150.patch
Type: text/x-patch
Size: 770 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230607/6d0a99e5/attachment.bin>
More information about the libc-commits
mailing list