[asan/msan] one more test for 32-bit allocator + minor code simplification
authorKostya Serebryany <kcc@google.com>
Thu, 6 Dec 2012 14:39:41 +0000 (14:39 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 6 Dec 2012 14:39:41 +0000 (14:39 +0000)
llvm-svn: 169507

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

index c5356fa..caf5380 100644 (file)
@@ -149,7 +149,7 @@ class SizeClassAllocator64 {
   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 @@ class SizeClassAllocator32 {
   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) {
index d3180ec..e0b7207 100644 (file)
@@ -326,9 +326,10 @@ void TestSizeClassAllocatorLocalCache() {
   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 @@ void TestSizeClassAllocatorLocalCache() {
   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 @@ TEST(SanitizerCommon, SizeClassAllocator64LocalCache) {
   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);