From a3badd6d2127c161f6fbad853fccd6e8064fcde7 Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Sun, 29 Apr 2018 16:34:54 -0700 Subject: [PATCH] Really fix CheckAddressBits compilation warning It looks like previous fix introduced another warning on gcc for i386. Somehow it barked on kAddressBits shift even that shift was dead code. Anyways, we now avoid possibility of undefined shift even stronger. And it actually removes compile warning on all compilers I tested. --- src/system-alloc.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/system-alloc.cc b/src/system-alloc.cc index 7e3f602..292e482 100755 --- a/src/system-alloc.cc +++ b/src/system-alloc.cc @@ -96,19 +96,15 @@ static const bool kDebugMode = true; using tcmalloc::kLog; using tcmalloc::Log; -// Anonymous namespace to avoid name conflicts on "CheckAddressBits". -namespace { - // Check that no bit is set at position ADDRESS_BITS or higher. -bool CheckAddressBits(uintptr_t ptr) { - if (kAddressBits == 8 * sizeof(void*)) { - return true; - } - return (ptr >> kAddressBits) == 0; +static bool CheckAddressBits(uintptr_t ptr) { + bool always_ok = (kAddressBits == 8 * sizeof(void*)); + // this is a bit insane but otherwise we get compiler warning about + // shifting right by word size even if this code is dead :( + int shift_bits = always_ok ? 0 : kAddressBits; + return always_ok || ((ptr >> shift_bits) == 0); } -} // Anonymous namespace to avoid name conflicts on "CheckAddressBits". - COMPILE_ASSERT(kAddressBits <= 8 * sizeof(void*), address_bits_larger_than_pointer_size);