X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FAllocator.h;h=ff08622eee548a76c96da4dab6a4725409bd0111;hp=05dccec94de4e6ae14ba5cfa136a46801f6fa642;hb=4f240010fdea1fcbe7dac3c8e9ebad082e4036c2;hpb=e3fc1d8cde83b4a0a9d94035f1b1dc8d75339e5e diff --git a/include/llvm/Support/Allocator.h b/include/llvm/Support/Allocator.h index 05dccec94de..ff08622eee5 100644 --- a/include/llvm/Support/Allocator.h +++ b/include/llvm/Support/Allocator.h @@ -209,12 +209,12 @@ public: // Keep track of how many bytes we've allocated. BytesAllocated += Size; - // Allocate the aligned space, going forwards from CurPtr. - uintptr_t AlignedAddr = alignAddr(CurPtr, Alignment); + size_t Adjustment = alignmentAdjustment(CurPtr, Alignment); + assert(Adjustment + Size >= Size && "Adjustment + Size must not overflow"); - // Check if we can hold it. - if (AlignedAddr + Size <= (uintptr_t)End) { - char *AlignedPtr = (char*)AlignedAddr; + // Check if we have enough space. + if (Adjustment + Size <= size_t(End - CurPtr)) { + char *AlignedPtr = CurPtr + Adjustment; CurPtr = AlignedPtr + Size; // Update the allocation point of this memory block in MemorySanitizer. // Without this, MemorySanitizer messages for values originated from here @@ -238,7 +238,7 @@ public: // Otherwise, start a new slab and try again. StartNewSlab(); - AlignedAddr = alignAddr(CurPtr, Alignment); + uintptr_t AlignedAddr = alignAddr(CurPtr, Alignment); assert(AlignedAddr + Size <= (uintptr_t)End && "Unable to allocate memory!"); char *AlignedPtr = (char*)AlignedAddr;