Fix llvm::BumpPtrAllocatorImpl::Reset()

Kal b17c0de at gmail.com
Mon May 11 10:37:56 PDT 2015


BumpPtrAllocator's Reset doesn't act as documented if Slaps.size() == 0 
but CustomSizedSlabs.size() != 0.

-------------- next part --------------
Index: Allocator.h
===================================================================
--- Allocator.h	(revision 236999)
+++ Allocator.h	(working copy)
@@ -187,17 +187,16 @@
   /// \brief Deallocate all but the current slab and reset the current pointer
   /// to the beginning of it, freeing all memory allocated so far.
   void Reset() {
-    if (Slabs.empty())
-      return;
+    if (!Slabs.empty()) {
+      // Reset the state.
+      BytesAllocated = 0;
+      CurPtr = (char *)Slabs.front();
+      End = CurPtr + SlabSize;
 
-    // Reset the state.
-    BytesAllocated = 0;
-    CurPtr = (char *)Slabs.front();
-    End = CurPtr + SlabSize;
-
-    // Deallocate all but the first slab, and all custome sized slabs.
-    DeallocateSlabs(std::next(Slabs.begin()), Slabs.end());
-    Slabs.erase(std::next(Slabs.begin()), Slabs.end());
+      // Deallocate all but the first slab, and all custome sized slabs.
+      DeallocateSlabs(std::next(Slabs.begin()), Slabs.end());
+      Slabs.erase(std::next(Slabs.begin()), Slabs.end());
+    }
     DeallocateCustomSizedSlabs();
     CustomSizedSlabs.clear();
   }


More information about the llvm-commits mailing list