OSDN Git Service

[Hashing] hash_1to3_bytes - avoid trunc(v + zext(x)) NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Sun, 14 Jul 2019 15:05:05 +0000 (15:05 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Sun, 14 Jul 2019 15:05:05 +0000 (15:05 +0000)
MSVC complains about the extension to uint64_t for an addition followed by truncation back to uint32_t - add an explicit uint32_t cast to avoid this.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366020 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/Hashing.h

index f639aa2..008188b 100644 (file)
@@ -191,7 +191,7 @@ inline uint64_t hash_1to3_bytes(const char *s, size_t len, uint64_t seed) {
   uint8_t b = s[len >> 1];
   uint8_t c = s[len - 1];
   uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8);
-  uint32_t z = len + (static_cast<uint32_t>(c) << 2);
+  uint32_t z = static_cast<uint32_t>(len) + (static_cast<uint32_t>(c) << 2);
   return shift_mix(y * k2 ^ z * k3 ^ seed) * k2;
 }