[llvm] r235542 - [Allocator] Remove memory poisoning before deallocation

Reid Kleckner reid at kleckner.net
Wed Apr 22 13:56:42 PDT 2015


Author: rnk
Date: Wed Apr 22 15:56:42 2015
New Revision: 235542

URL: http://llvm.org/viewvc/llvm-project?rev=235542&view=rev
Log:
[Allocator] Remove memory poisoning before deallocation

I added the poisoning back in r76891 (2009) because of some bugs in
Unladen Swallow, and then Evan Cheng added the setRangeWritable() call
in r81308. Profiling a Release+Asserts build on Windows shows that this
memory protection call is actually very expensive. 4 seconds of a 70
second Clang compilation are spent in VirtualQuery. These days we have
more reliable tools like ASan to find these kinds of bugs, so we can go
ahead and retire these checks.

Modified:
    llvm/trunk/include/llvm/Support/Allocator.h

Modified: llvm/trunk/include/llvm/Support/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Allocator.h?rev=235542&r1=235541&r2=235542&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Allocator.h (original)
+++ llvm/trunk/include/llvm/Support/Allocator.h Wed Apr 22 15:56:42 2015
@@ -320,14 +320,6 @@ private:
     for (; I != E; ++I) {
       size_t AllocatedSlabSize =
           computeSlabSize(std::distance(Slabs.begin(), I));
-#ifndef NDEBUG
-      // Poison the memory so stale pointers crash sooner.  Note we must
-      // preserve the Size and NextPtr fields at the beginning.
-      if (AllocatedSlabSize != 0) {
-        sys::Memory::setRangeWritable(*I, AllocatedSlabSize);
-        memset(*I, 0xCD, AllocatedSlabSize);
-      }
-#endif
       Allocator.Deallocate(*I, AllocatedSlabSize);
     }
   }
@@ -337,12 +329,6 @@ private:
     for (auto &PtrAndSize : CustomSizedSlabs) {
       void *Ptr = PtrAndSize.first;
       size_t Size = PtrAndSize.second;
-#ifndef NDEBUG
-      // Poison the memory so stale pointers crash sooner.  Note we must
-      // preserve the Size and NextPtr fields at the beginning.
-      sys::Memory::setRangeWritable(Ptr, Size);
-      memset(Ptr, 0xCD, Size);
-#endif
       Allocator.Deallocate(Ptr, Size);
     }
   }





More information about the llvm-commits mailing list