diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-04-28 17:58:07 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-04-28 17:58:07 +0000 |
commit | c9715624fa096bf412bf5d63214d9ea8fae485af (patch) | |
tree | 477bbbeae9095232d716b1bcd40357fe05bc77e3 /lib/Support | |
parent | b20d4f8d499c4c5315de69bd22c652665a7e3ab8 (diff) | |
download | external_llvm-c9715624fa096bf412bf5d63214d9ea8fae485af.zip external_llvm-c9715624fa096bf412bf5d63214d9ea8fae485af.tar.gz external_llvm-c9715624fa096bf412bf5d63214d9ea8fae485af.tar.bz2 |
Bug fix in BumpPtrAllocator: don't assume that all objects have the same alignment. "Bump" of the pointer for the next allocated object to be of the specified alignment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50362 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/Allocator.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/Support/Allocator.cpp b/lib/Support/Allocator.cpp index 5961afe..8ccd390 100644 --- a/lib/Support/Allocator.cpp +++ b/lib/Support/Allocator.cpp @@ -46,13 +46,16 @@ public: /// Allocate - Allocate and return at least the specified number of bytes. /// void *Allocate(unsigned AllocSize, unsigned Alignment, MemRegion **RegPtr) { - // Round size up to an even multiple of the alignment. - AllocSize = (AllocSize+Alignment-1) & ~(Alignment-1); - // If there is space in this region, return it. - if (unsigned(NextPtr+AllocSize-(char*)this) <= RegionSize) { - void *Result = NextPtr; - NextPtr += AllocSize; + char* Result = (char*) (((uintptr_t) (NextPtr+Alignment-1)) + & ~(Alignment-1)); + + // Speculate the new value of NextPtr. + char* NextPtrTmp = Result + AllocSize; + + // If we are still within the current region, return Result. + if (unsigned (NextPtrTmp - (char*) this) <= RegionSize) { + NextPtr = NextPtrTmp; return Result; } |