[llvm] r215841 - BumpPtrAllocator: remove 'no slabs allocated yet' check

Duncan P. N. Exon Smith dexonsmith at apple.com
Sun Aug 31 20:14:17 PDT 2014


> On 2014 Aug 17, at 14:31, Hans Wennborg <hans at hanshq.net> wrote:
> 
> Author: hans
> Date: Sun Aug 17 13:31:18 2014
> New Revision: 215841
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=215841&view=rev
> Log:
> BumpPtrAllocator: remove 'no slabs allocated yet' check
> 
> We already handle the no-slabs case when checking whether the current slab
> is large enough: if no slabs have been allocated, CurPtr and End are both 0.
> alignPtr(0), will still be 0, and so "if (Ptr + Size <= End)" fails.

I don't think this commit introduces the problem, but isn't the result
of `Ptr + Size` undefined when `Size` is too big?

Should this be changed to `if (Size <= End - Ptr)`?

> 
> Differential Revision: http://reviews.llvm.org/D4943
> 
> Modified:
>    llvm/trunk/include/llvm/Support/Allocator.h
>    llvm/trunk/unittests/Support/AllocatorTest.cpp
> 
> Modified: llvm/trunk/include/llvm/Support/Allocator.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Allocator.h?rev=215841&r1=215840&r2=215841&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/Allocator.h (original)
> +++ llvm/trunk/include/llvm/Support/Allocator.h Sun Aug 17 13:31:18 2014
> @@ -201,9 +201,6 @@ public:
> 
>   /// \brief Allocate space at the specified alignment.
>   void *Allocate(size_t Size, size_t Alignment) {
> -    if (!CurPtr) // Start a new slab if we haven't allocated one already.
> -      StartNewSlab();
> -
>     // Keep track of how many bytes we've allocated.
>     BytesAllocated += Size;
> 
> 
> Modified: llvm/trunk/unittests/Support/AllocatorTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/AllocatorTest.cpp?rev=215841&r1=215840&r2=215841&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Support/AllocatorTest.cpp (original)
> +++ llvm/trunk/unittests/Support/AllocatorTest.cpp Sun Aug 17 13:31:18 2014
> @@ -112,7 +112,7 @@ TEST(AllocatorTest, TestSmallSlabSize) {
>   BumpPtrAllocator Alloc;
> 
>   Alloc.Allocate(8000, 0);
> -  EXPECT_EQ(2U, Alloc.GetNumSlabs());
> +  EXPECT_EQ(1U, Alloc.GetNumSlabs());
> }
> 
> // Mock slab allocator that returns slabs aligned on 4096 bytes.  There is no
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list