From 389ce43b7d74a899c23e512dbcef08ddd6d549fd Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Thu, 30 Jun 2016 18:11:51 -0700 Subject: [PATCH] Long is not long enough for a long long Summary: Thus `1UL << 63 == 0` which is not the intended behavior. Reviewed By: yfeldblum Differential Revision: D3478480 fbshipit-source-id: a31dba7f5a503be2b34a4cb66bc7039076f158a0 --- folly/detail/FingerprintPolynomial.h | 8 ++++---- folly/detail/SlowFingerprint.h | 2 +- folly/test/BitsTest.cpp | 2 +- folly/test/GroupVarintTest.cpp | 2 +- folly/test/RandomBenchmark.cpp | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/folly/detail/FingerprintPolynomial.h b/folly/detail/FingerprintPolynomial.h index 588ae757..fd927dcb 100644 --- a/folly/detail/FingerprintPolynomial.h +++ b/folly/detail/FingerprintPolynomial.h @@ -57,7 +57,7 @@ class FingerprintPolynomial { // Multiply by X. The actual degree must be < DEG. void mulX() { - CHECK_EQ(0, val_[0] & (1UL<<63)); + CHECK_EQ(0, val_[0] & (1ULL<<63)); uint64_t b = 0; for (int i = size()-1; i >= 0; i--) { uint64_t nb = val_[i] >> 63; @@ -91,8 +91,8 @@ class FingerprintPolynomial { // the binary representation of A, left shift by 1, // XOR p if a_(k-1) == 1 void mulXmod(const FingerprintPolynomial& p) { - bool needXOR = (val_[0] & (1UL<<63)); - val_[0] &= ~(1UL<<63); + bool needXOR = (val_[0] & (1ULL<<63)); + val_[0] &= ~(1ULL<<63); mulX(); if (needXOR) { add(p); @@ -112,7 +112,7 @@ class FingerprintPolynomial { DCHECK_LE(k, DEG); int word_offset = (DEG - k) / 64; int bit_offset = 63 - (DEG - k) % 64; - val_[word_offset] ^= (1UL << bit_offset); + val_[word_offset] ^= (1ULL << bit_offset); } // Set the highest 8 bits to val. diff --git a/folly/detail/SlowFingerprint.h b/folly/detail/SlowFingerprint.h index 1bbbda61..9e0b276a 100644 --- a/folly/detail/SlowFingerprint.h +++ b/folly/detail/SlowFingerprint.h @@ -76,7 +76,7 @@ class SlowFingerprint { void updateLSB(uint64_t val, int bits) { val <<= (64-bits); for (; bits != 0; --bits) { - updateBit(val & (1UL << 63)); + updateBit(val & (1ULL << 63)); val <<= 1; } } diff --git a/folly/test/BitsTest.cpp b/folly/test/BitsTest.cpp index b5cf43be..d277f9d8 100644 --- a/folly/test/BitsTest.cpp +++ b/folly/test/BitsTest.cpp @@ -107,7 +107,7 @@ TEST(Bits, FindLastSet) { EXPECT_EQ(1024, nextPowTwoFunc(513u)); \ EXPECT_EQ(1024, nextPowTwoFunc(777u)); \ EXPECT_EQ(1ul << 31, nextPowTwoFunc((1ul << 31) - 1)); \ - EXPECT_EQ(1ul << 32, nextPowTwoFunc((1ul << 32) - 1)); \ + EXPECT_EQ(1ull << 32, nextPowTwoFunc((1ull << 32) - 1)); \ EXPECT_EQ(1ull << 63, nextPowTwoFunc((1ull << 62) + 1)); \ } diff --git a/folly/test/GroupVarintTest.cpp b/folly/test/GroupVarintTest.cpp index 102c2f35..fa3bc117 100644 --- a/folly/test/GroupVarintTest.cpp +++ b/folly/test/GroupVarintTest.cpp @@ -60,7 +60,7 @@ void testGroupVarint32(uint32_t a, uint32_t b, uint32_t c, uint32_t d, ...) { // ssse3 decoding requires that the source buffer have length >= 17, // so that it can read 128 bits from &start[1] via _mm_loadu_si128. - foundBytes.resize(std::max(size + 4, 17UL)); + foundBytes.resize(std::max(size + 4, 17UL)); char* start = &(foundBytes.front()); char* p = GroupVarint32::encode(start, a, b, c, d); EXPECT_EQ((void*)(start + size), (void*)p); diff --git a/folly/test/RandomBenchmark.cpp b/folly/test/RandomBenchmark.cpp index cc17e5ee..14a0edb3 100644 --- a/folly/test/RandomBenchmark.cpp +++ b/folly/test/RandomBenchmark.cpp @@ -63,7 +63,7 @@ BENCHMARK(RandomDouble) { doNotOptimizeAway(Random::randDouble01()); } BENCHMARK(Random32) { doNotOptimizeAway(Random::rand32()); } BENCHMARK(Random32Num) { doNotOptimizeAway(Random::rand32(100)); } BENCHMARK(Random64) { doNotOptimizeAway(Random::rand64()); } -BENCHMARK(Random64Num) { doNotOptimizeAway(Random::rand64(100ul << 32)); } +BENCHMARK(Random64Num) { doNotOptimizeAway(Random::rand64(100ull << 32)); } BENCHMARK(Random64OneIn) { doNotOptimizeAway(Random::oneIn(100)); } int main(int argc, char** argv) { -- 2.34.1