summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-04-28 17:58:07 +0000
committerTed Kremenek <kremenek@apple.com>2008-04-28 17:58:07 +0000
commite51f22986b47356b1269f6e2d78993d87fcdf40d (patch)
tree4024f225aa67d83a8b0d3ea1c149266e637ba526 /llvm/lib/Support
parent14a05df97b5e55e40c1066732b32f2ee2c55600e (diff)
downloadbcm5719-llvm-e51f22986b47356b1269f6e2d78993d87fcdf40d.tar.gz
bcm5719-llvm-e51f22986b47356b1269f6e2d78993d87fcdf40d.zip
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.
llvm-svn: 50362
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/Allocator.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/llvm/lib/Support/Allocator.cpp b/llvm/lib/Support/Allocator.cpp
index 5961afe04c7..8ccd3908446 100644
--- a/llvm/lib/Support/Allocator.cpp
+++ b/llvm/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;
}
OpenPOWER on IntegriCloud