[llvm-commits] [llvm] r167145 - /llvm/trunk/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp
Amara Emerson
amara.emerson at arm.com
Wed Oct 31 10:41:52 PDT 2012
Author: aemerson
Date: Wed Oct 31 12:41:51 2012
New Revision: 167145
URL: http://llvm.org/viewvc/llvm-project?rev=167145&view=rev
Log:
Port lli bug fix from r166920 to MCJIT unit test.
Modified:
llvm/trunk/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp
Modified: llvm/trunk/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp?rev=167145&r1=167144&r2=167145&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/MCJIT/SectionMemoryManager.cpp Wed Oct 31 12:41:51 2012
@@ -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 @@
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,
More information about the llvm-commits
mailing list