From: Max Warsewa Date: Fri, 4 Mar 2016 22:32:48 +0000 (-0800) Subject: Fix clang build for MicroLock X-Git-Tag: deprecate-dynamic-initializer~6 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2f595596190c768c6c074c93c878ef8b9144fe55;p=folly.git Fix clang build for MicroLock 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 --- diff --git a/folly/MicroLock.h b/folly/MicroLock.h index 18efaa9b..3ff158b8 100644 --- a/folly/MicroLock.h +++ b/folly/MicroLock.h @@ -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; }