diff options
Diffstat (limited to 'lib/Support/Allocator.cpp')
-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 5961afe04c..8ccd390844 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; } |