Fix clang build for MicroLock
authorMax Warsewa <mwa@fb.com>
Fri, 4 Mar 2016 22:32:48 +0000 (14:32 -0800)
committerFacebook Github Bot 3 <facebook-github-bot-3-bot@fb.com>
Fri, 4 Mar 2016 22:35:25 +0000 (14:35 -0800)
Summary: clang would complain about losing integer precision. Use unsigned for offset calculation.

Reviewed By: luciang

Differential Revision: D3011253

fb-gh-sync-id: 10cb603708a22bf0e57f41b2486ffca4f5bf7a14
shipit-source-id: 10cb603708a22bf0e57f41b2486ffca4f5bf7a14

folly/MicroLock.h

index 18efaa9b80d7a308ff1379388536e1b196d3e1c8..3ff158b8728570c968f3df9f022ec7842996feca 100644 (file)
@@ -110,11 +110,11 @@ inline detail::Futex<>* MicroLockCore::word() const {
 
 inline unsigned MicroLockCore::baseShift(unsigned slot) const {
   assert(slot < CHAR_BIT / 2);
-  uintptr_t offset_bytes = (uintptr_t)&lock_ - (uintptr_t)word();
-  assert(offset_bytes < sizeof(uint32_t));
+
+  unsigned offset_bytes = (unsigned)((uintptr_t)&lock_ - (uintptr_t)word());
 
   return kIsLittleEndian
-             ? (unsigned)offset_bytes * CHAR_BIT + slot * 2
+             ? offset_bytes * CHAR_BIT + slot * 2
              : CHAR_BIT * (sizeof(uint32_t) - offset_bytes - 1) + slot * 2;
 }