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.
This commit is contained in:
Aliaksey Kandratsenka 2018-04-29 16:34:54 -07:00
parent 7c718fe176
commit a3badd6d21

View File

@ -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);