[LLVMdev] Fwd: Bug in Support/Allocator.h

Kal b17c0de at gmail.com
Mon May 11 08:38:47 PDT 2015


Here is a real patch.


-------- Weitergeleitete Nachricht --------
Betreff: 	Bug in Support/Allocator.h
Datum: 	Mon, 11 May 2015 17:25:45 +0200
Von: 	Kal <b17c0de at gmail.com>
An: 	LLVM Developers Mailing List (llvmdev at cs.uiuc.edu) 
<llvmdev at cs.uiuc.edu>



Hi,
llvm::BumpPtrAllocatorImpl::Reset() looks like it has a bug.

There is this check at the top:
     if (Slabs.empty())
       return;

But what if you don't have any normal Slabs allocated but only
CustomSizedSlabs.

I think this should be:

     if (Slabs.empty() && CustomSizedSlabs.empty())
       return;



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150511/0805fe5b/attachment.html>
-------------- 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-dev mailing list