[llvm-commits] [compiler-rt] r169507 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_allocator.h tests/sanitizer_allocator_test.cc

Kostya Serebryany kcc at google.com
Thu Dec 6 06:39:41 PST 2012


Author: kcc
Date: Thu Dec  6 08:39:41 2012
New Revision: 169507

URL: http://llvm.org/viewvc/llvm-project?rev=169507&view=rev
Log:
[asan/msan] one more test for 32-bit allocator + minor code simplification

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=169507&r1=169506&r2=169507&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Thu Dec  6 08:39:41 2012
@@ -149,7 +149,7 @@
   void *Allocate(uptr size, uptr alignment) {
     if (size < alignment) size = alignment;
     CHECK(CanAllocate(size, alignment));
-    return AllocateBySizeClass(SizeClassMap::ClassID(size));
+    return AllocateBySizeClass(ClassID(size));
   }
 
   void Deallocate(void *p) {
@@ -347,7 +347,7 @@
   void *Allocate(uptr size, uptr alignment) {
     if (size < alignment) size = alignment;
     CHECK(CanAllocate(size, alignment));
-    return AllocateBySizeClass(SizeClassMap::ClassID(size));
+    return AllocateBySizeClass(ClassID(size));
   }
 
   void Deallocate(void *p) {

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc?rev=169507&r1=169506&r2=169507&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc Thu Dec  6 08:39:41 2012
@@ -326,9 +326,10 @@
   static THREADLOCAL AllocatorCache static_allocator_cache;
   static_allocator_cache.Init();
   AllocatorCache cache;
-  typename AllocatorCache::Allocator a;
+  typedef typename AllocatorCache::Allocator Allocator;
+  Allocator *a = new Allocator();
 
-  a.Init();
+  a->Init();
   cache.Init();
 
   const uptr kNumAllocs = 10000;
@@ -337,19 +338,20 @@
   for (int i = 0; i < kNumIter; i++) {
     void *allocated[kNumAllocs];
     for (uptr i = 0; i < kNumAllocs; i++) {
-      allocated[i] = cache.Allocate(&a, 0);
+      allocated[i] = cache.Allocate(a, 0);
     }
     for (uptr i = 0; i < kNumAllocs; i++) {
-      cache.Deallocate(&a, 0, allocated[i]);
+      cache.Deallocate(a, 0, allocated[i]);
     }
-    cache.Drain(&a);
-    uptr total_allocated = a.TotalMemoryUsed();
+    cache.Drain(a);
+    uptr total_allocated = a->TotalMemoryUsed();
     if (saved_total)
       CHECK_EQ(saved_total, total_allocated);
     saved_total = total_allocated;
   }
 
-  a.TestOnlyUnmap();
+  a->TestOnlyUnmap();
+  delete a;
 }
 
 #if SANITIZER_WORDSIZE == 64
@@ -357,8 +359,18 @@
   TestSizeClassAllocatorLocalCache<
       SizeClassAllocatorLocalCache<Allocator64> >();
 }
+
+TEST(SanitizerCommon, SizeClassAllocator64CompactLocalCache) {
+  TestSizeClassAllocatorLocalCache<
+      SizeClassAllocatorLocalCache<Allocator64Compact> >();
+}
 #endif
 
+TEST(SanitizerCommon, SizeClassAllocator32CompactLocalCache) {
+  TestSizeClassAllocatorLocalCache<
+      SizeClassAllocatorLocalCache<Allocator32Compact> >();
+}
+
 TEST(Allocator, Basic) {
   char *p = (char*)InternalAlloc(10);
   EXPECT_NE(p, (char*)0);





More information about the llvm-commits mailing list