[llvm-commits] [compiler-rt] r149687 - in /compiler-rt/trunk/lib/asan: asan_allocator.cc asan_poisoning.cc
Alexey Samsonov
samsonov at google.com
Fri Feb 3 00:50:16 PST 2012
Author: samsonov
Date: Fri Feb 3 02:50:16 2012
New Revision: 149687
URL: http://llvm.org/viewvc/llvm-project?rev=149687&view=rev
Log:
AddressSanitizer: simplify RoundUpToPowerOfTwo/clz; add a couple of CHECKs for real_X calls. Patch by timurrrr at google.com
Modified:
compiler-rt/trunk/lib/asan/asan_allocator.cc
compiler-rt/trunk/lib/asan/asan_poisoning.cc
Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=149687&r1=149686&r2=149687&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.cc Fri Feb 3 02:50:16 2012
@@ -78,28 +78,21 @@
#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 @@
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 @@
// ---------------------- Fake stack-------------------- {{{1
FakeStack::FakeStack() {
- CHECK(real_memset);
+ CHECK(real_memset != NULL);
real_memset(this, 0, sizeof(*this));
}
Modified: compiler-rt/trunk/lib/asan/asan_poisoning.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_poisoning.cc?rev=149687&r1=149686&r2=149687&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_poisoning.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_poisoning.cc Fri Feb 3 02:50:16 2012
@@ -24,6 +24,7 @@
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);
}
More information about the llvm-commits
mailing list