AddressSanitizer: simplify RoundUpToPowerOfTwo/clz; add a couple of CHECKs for real_X calls. Patch by timurrrr@google.com

llvm-svn: 149687
This commit is contained in:
Alexey Samsonov 2012-02-03 08:50:16 +00:00
parent 23e3b90319
commit f9fef3d275
2 changed files with 14 additions and 19 deletions

View File

@ -78,28 +78,21 @@ static inline size_t Log2(size_t x) {
#endif
}
static inline size_t clz(size_t x) {
#if defined(_WIN64)
unsigned long ret; // NOLINT
_BitScanReverse64(&ret, x);
return ret;
#elif defined(_WIN32)
unsigned long ret; // NOLINT
_BitScanReverse(&ret, x);
return ret;
#else
return __builtin_clzl(x);
#endif
}
static inline size_t RoundUpToPowerOfTwo(size_t size) {
CHECK(size);
if (IsPowerOfTwo(size)) return size;
size_t up = __WORDSIZE - clz(size);
CHECK(size < (1ULL << up));
CHECK(size > (1ULL << (up - 1)));
return 1UL << up;
unsigned long up; // NOLINT
#if defined(_WIN64)
_BitScanReverse64(&up, size);
#elif defined(_WIN32)
_BitScanReverse(&up, size);
#else
up = __WORDSIZE - 1 - __builtin_clzl(size);
#endif
CHECK(size < (1ULL << (up + 1)));
CHECK(size > (1ULL << up));
return 1UL << (up + 1);
}
static inline size_t SizeClassToSize(uint8_t size_class) {
@ -747,6 +740,7 @@ static uint8_t *Reallocate(uint8_t *old_ptr, size_t new_size,
size_t memcpy_size = Min(new_size, old_size);
uint8_t *new_ptr = Allocate(0, new_size, stack);
if (new_ptr) {
CHECK(real_memcpy != NULL);
real_memcpy(new_ptr, old_ptr, memcpy_size);
Deallocate(old_ptr, stack);
}
@ -873,7 +867,7 @@ void asan_mz_force_unlock() {
// ---------------------- Fake stack-------------------- {{{1
FakeStack::FakeStack() {
CHECK(real_memset);
CHECK(real_memset != NULL);
real_memset(this, 0, sizeof(*this));
}

View File

@ -24,6 +24,7 @@ void PoisonShadow(uintptr_t addr, size_t size, uint8_t value) {
CHECK(AddrIsAlignedByGranularity(addr + size));
uintptr_t shadow_beg = MemToShadow(addr);
uintptr_t shadow_end = MemToShadow(addr + size);
CHECK(real_memset != NULL);
real_memset((void*)shadow_beg, value, shadow_end - shadow_beg);
}