BumpPtrAllocator: do the size check without moving any pointers
authorHans Wennborg <hans@hanshq.net>
Sun, 7 Sep 2014 04:24:31 +0000 (04:24 +0000)
committerHans Wennborg <hans@hanshq.net>
Sun, 7 Sep 2014 04:24:31 +0000 (04:24 +0000)
commit4f240010fdea1fcbe7dac3c8e9ebad082e4036c2
treeafa4a3d5b9241fbb819f9acf1d32b7b8a725b374
parente3fc1d8cde83b4a0a9d94035f1b1dc8d75339e5e
BumpPtrAllocator: do the size check without moving any pointers

Instead of aligning and moving the CurPtr forward, and then comparing
with End, simply calculate how much space is needed, and compare that
to how much is available.

Hopefully this avoids any doubts about comparing addresses possibly
derived from past the end of the slab array, overflowing, etc.

Also add a test where aligning CurPtr would move it past End.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217330 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/Allocator.h
include/llvm/Support/MathExtras.h
unittests/Support/AllocatorTest.cpp