Commit fd346480 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix narrowing conversion in folly::popcount

Summary: [Folly] Fix narrowing conversion in `folly::popcount`.

Reviewed By: ot, nbronson

Differential Revision: D8555467

fbshipit-source-id: fdef83fc05e3e595087e7b8a3aba98400e5a954a
parent 101ad63e
......@@ -123,7 +123,7 @@ inline FOLLY_INTRINSIC_CONSTEXPR unsigned int findLastSet(T const v) {
// clang-format off
using size = index_constant<constexpr_max(sizeof(T), sizeof(U0))>;
return v ? 1u + ((8u * size{} - 1u) ^ static_cast<unsigned int>(
sizeof(T) <= sizeof(U0) ? __builtin_clz(bits_to_unsigned<U1>(v)) :
sizeof(T) <= sizeof(U0) ? __builtin_clz(bits_to_unsigned<U0>(v)) :
sizeof(T) <= sizeof(U1) ? __builtin_clzl(bits_to_unsigned<U1>(v)) :
sizeof(T) <= sizeof(U2) ? __builtin_clzll(bits_to_unsigned<U2>(v)) :
0)) : 0u;
......@@ -145,7 +145,7 @@ inline FOLLY_INTRINSIC_CONSTEXPR unsigned int popcount(T const v) {
// clang-format off
return static_cast<unsigned int>(
sizeof(T) <= sizeof(U0) ? __builtin_popcount(bits_to_unsigned<U1>(v)) :
sizeof(T) <= sizeof(U0) ? __builtin_popcount(bits_to_unsigned<U0>(v)) :
sizeof(T) <= sizeof(U1) ? __builtin_popcountl(bits_to_unsigned<U1>(v)) :
sizeof(T) <= sizeof(U2) ? __builtin_popcountll(bits_to_unsigned<U2>(v)) :
0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment