diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -690,6 +690,123 @@ TestCombinedAllocator(); } +static bool use1 = false; + +template +class DoubleAllocator { + A1 a1; + A2 a2; + + public: + class DoubleAllocatorCache { + typename A1::AllocatorCache a1; + typename A2::AllocatorCache a2; + + public: + void Init(AllocatorGlobalStats *s) { + if (use1) + return a1.Init(s); + else + return a2.Init(s); + } + void *Allocate(DoubleAllocator *allocator, uptr class_id) { + if (use1) + return a1.Allocate(&allocator->a1, class_id); + else + return a2.Allocate(&allocator->a2, class_id); + } + + void Deallocate(DoubleAllocator *allocator, uptr class_id, void *p) { + if (use1) + return a1.Deallocate(&allocator->a1, class_id, p); + else + return a2.Deallocate(&allocator->a2, class_id, p); + } + + void Drain(DoubleAllocator *allocator) { + if (use1) + return a1.Drain(&allocator->a1); + else + return a2.Drain(&allocator->a2); + } + + void Destroy(DoubleAllocator *allocator, AllocatorGlobalStats *s) { + if (use1) + return a1.Destroy(&allocator->a1, s); + else + return a2.Destroy(&allocator->a2, s); + } + }; + + using MapUnmapCallback = Allocator32Compact::MapUnmapCallback; + using AddressSpaceView = Allocator32Compact::AddressSpaceView; + using AllocatorCache = DoubleAllocatorCache; + + void Init(s32 release_to_os_interval_ms) { + if (use1) + return a1.Init(release_to_os_interval_ms); + else + return a2.Init(release_to_os_interval_ms); + } + + static bool CanAllocate(uptr size, uptr alignment) { + if (use1) + return A1::CanAllocate(size, alignment); + else + return A2::CanAllocate(size, alignment); + } + + static uptr ClassID(uptr size) { + if (use1) + return A1::ClassID(size); + else + return A2::ClassID(size); + } + + bool PointerIsMine(const void *p) { + if (use1) + return a1.PointerIsMine(p); + else + return a2.PointerIsMine(p); + } + + void *GetMetaData(const void *p) { + if (use1) + return a1.GetMetaData(p); + else + return a2.GetMetaData(p); + } + + uptr GetSizeClass(const void *p) { + if (use1) + return a1.GetSizeClass(p); + else + return a2.GetSizeClass(p); + } + + void ForEachChunk(ForEachChunkCallback callback, void *arg) { + if (use1) + return a1.ForEachChunk(callback, arg); + else + return a2.ForEachChunk(callback, arg); + } + + void TestOnlyUnmap() { + if (use1) + return a1.TestOnlyUnmap(); + else + return a2.TestOnlyUnmap(); + } +}; + +TEST(SanitizerCommon, CombinedDoubleAllocator) { + TestCombinedAllocator< + DoubleAllocator>(); + use1 = true; + TestCombinedAllocator< + DoubleAllocator>(); +} + #if !SANITIZER_ANDROID TEST(SanitizerCommon, CombinedAllocator64Compact) { TestCombinedAllocator();