[llvm] r216036 - BumpPtrAllocator: don't accept 0 for the alignment parameter
Hans Wennborg
hans at hanshq.net
Tue Aug 19 16:35:34 PDT 2014
Author: hans
Date: Tue Aug 19 18:35:33 2014
New Revision: 216036
URL: http://llvm.org/viewvc/llvm-project?rev=216036&view=rev
Log:
BumpPtrAllocator: don't accept 0 for the alignment parameter
It seems unnecessary to have to use an extra branch to check for this special case.
http://reviews.llvm.org/D4945
Modified:
llvm/trunk/include/llvm/Support/Allocator.h
llvm/trunk/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
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=216036&r1=216035&r2=216036&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Allocator.h (original)
+++ llvm/trunk/include/llvm/Support/Allocator.h Tue Aug 19 18:35:33 2014
@@ -201,13 +201,11 @@ public:
/// \brief Allocate space at the specified alignment.
void *Allocate(size_t Size, size_t Alignment) {
+ assert(Alignment > 0 && "0-byte alignnment is not allowed. Use 1 instead.");
+
// Keep track of how many bytes we've allocated.
BytesAllocated += Size;
- // 0-byte alignment means 1-byte alignment.
- if (Alignment == 0)
- Alignment = 1;
-
// Allocate the aligned space, going forwards from CurPtr.
char *Ptr = alignPtr(CurPtr, Alignment);
Modified: llvm/trunk/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp?rev=216036&r1=216035&r2=216036&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp Tue Aug 19 18:35:33 2014
@@ -158,7 +158,7 @@ TEST(JITMemoryManagerTest, TestCodeAlloc
TEST(JITMemoryManagerTest, TestSmallGlobalInts) {
std::unique_ptr<JITMemoryManager> MemMgr(
JITMemoryManager::CreateDefaultMemManager());
- uint8_t *a = (uint8_t *)MemMgr->allocateGlobal(8, 0);
+ uint8_t *a = (uint8_t *)MemMgr->allocateGlobal(8, 1);
uint16_t *b = (uint16_t*)MemMgr->allocateGlobal(16, 2);
uint32_t *c = (uint32_t*)MemMgr->allocateGlobal(32, 4);
uint64_t *d = (uint64_t*)MemMgr->allocateGlobal(64, 8);
Modified: llvm/trunk/unittests/Support/AllocatorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/AllocatorTest.cpp?rev=216036&r1=216035&r2=216036&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/AllocatorTest.cpp (original)
+++ llvm/trunk/unittests/Support/AllocatorTest.cpp Tue Aug 19 18:35:33 2014
@@ -17,9 +17,9 @@ namespace {
TEST(AllocatorTest, Basics) {
BumpPtrAllocator Alloc;
- int *a = (int*)Alloc.Allocate(sizeof(int), 0);
- int *b = (int*)Alloc.Allocate(sizeof(int) * 10, 0);
- int *c = (int*)Alloc.Allocate(sizeof(int), 0);
+ int *a = (int*)Alloc.Allocate(sizeof(int), 1);
+ int *b = (int*)Alloc.Allocate(sizeof(int) * 10, 1);
+ int *c = (int*)Alloc.Allocate(sizeof(int), 1);
*a = 1;
b[0] = 2;
b[9] = 2;
@@ -49,11 +49,11 @@ TEST(AllocatorTest, Basics) {
// Allocate enough bytes to create three slabs.
TEST(AllocatorTest, ThreeSlabs) {
BumpPtrAllocator Alloc;
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(1U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(2U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(3U, Alloc.GetNumSlabs());
}
@@ -61,15 +61,15 @@ TEST(AllocatorTest, ThreeSlabs) {
// again.
TEST(AllocatorTest, TestReset) {
BumpPtrAllocator Alloc;
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(1U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(2U, Alloc.GetNumSlabs());
Alloc.Reset();
EXPECT_EQ(1U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(1U, Alloc.GetNumSlabs());
- Alloc.Allocate(3000, 0);
+ Alloc.Allocate(3000, 1);
EXPECT_EQ(2U, Alloc.GetNumSlabs());
}
@@ -99,11 +99,11 @@ TEST(AllocatorTest, TestOverflow) {
BumpPtrAllocator Alloc;
// Fill the slab right up until the end pointer.
- Alloc.Allocate(4096, 0);
+ Alloc.Allocate(4096, 1);
EXPECT_EQ(1U, Alloc.GetNumSlabs());
// If we don't allocate a new slab, then we will have overflowed.
- Alloc.Allocate(1, 0);
+ Alloc.Allocate(1, 1);
EXPECT_EQ(2U, Alloc.GetNumSlabs());
}
@@ -111,7 +111,7 @@ TEST(AllocatorTest, TestOverflow) {
TEST(AllocatorTest, TestSmallSlabSize) {
BumpPtrAllocator Alloc;
- Alloc.Allocate(8000, 0);
+ Alloc.Allocate(8000, 1);
EXPECT_EQ(1U, Alloc.GetNumSlabs());
}
@@ -155,7 +155,7 @@ TEST(AllocatorTest, TestBigAlignment) {
BumpPtrAllocatorImpl<MockSlabAllocator> Alloc;
// First allocate a tiny bit to ensure we have to re-align things.
- (void)Alloc.Allocate(1, 0);
+ (void)Alloc.Allocate(1, 1);
// Now the big chunk with a big alignment.
(void)Alloc.Allocate(3000, 2048);
More information about the llvm-commits
mailing list