summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorAmara Emerson <amara.emerson@arm.com>2012-10-31 17:41:51 +0000
committerAmara Emerson <amara.emerson@arm.com>2012-10-31 17:41:51 +0000
commita25ad19a23c20a235e8c8dc7d863324a64ef045e (patch)
tree85d5a0fc17df6f9fd803f8d2a89eabf4a8ff1846 /unittests
parent9f74bc9e7718cb10146d0ab42741de0d33123e61 (diff)
downloadllvm-a25ad19a23c20a235e8c8dc7d863324a64ef045e.tar.gz
llvm-a25ad19a23c20a235e8c8dc7d863324a64ef045e.tar.bz2
llvm-a25ad19a23c20a235e8c8dc7d863324a64ef045e.tar.xz
Port lli bug fix from r166920 to MCJIT unit test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167145 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp b/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp
index 7f3cf2455e..d6baf3c9bb 100644
--- a/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp
+++ b/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp
@@ -14,6 +14,7 @@
#include "llvm/Config/config.h"
#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/MathExtras.h"
#include "SectionMemoryManager.h"
@@ -34,9 +35,16 @@ uint8_t *SectionMemoryManager::allocateDataSection(uintptr_t Size,
unsigned SectionID) {
if (!Alignment)
Alignment = 16;
- uint8_t *Addr = (uint8_t*)calloc((Size + Alignment - 1)/Alignment, Alignment);
- AllocatedDataMem.push_back(sys::MemoryBlock(Addr, Size));
- return Addr;
+ // Ensure that enough memory is requested to allow aligning.
+ size_t NumElementsAligned = 1 + (Size + Alignment - 1)/Alignment;
+ uint8_t *Addr = (uint8_t*)calloc(NumElementsAligned, Alignment);
+
+ // Honour the alignment requirement.
+ uint8_t *AlignedAddr = (uint8_t*)RoundUpToAlignment((uint64_t)Addr, Alignment);
+
+ // Store the original address from calloc so we can free it later.
+ AllocatedDataMem.push_back(sys::MemoryBlock(Addr, NumElementsAligned*Alignment));
+ return AlignedAddr;
}
uint8_t *SectionMemoryManager::allocateCodeSection(uintptr_t Size,