diff options
Diffstat (limited to 'unittests/ExecutionEngine')
-rw-r--r-- | unittests/ExecutionEngine/JIT/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITTest.cpp | 53 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/Makefile | 2 | ||||
-rw-r--r-- | unittests/ExecutionEngine/MCJIT/MCJITTestBase.h | 2 |
4 files changed, 54 insertions, 5 deletions
diff --git a/unittests/ExecutionEngine/JIT/CMakeLists.txt b/unittests/ExecutionEngine/JIT/CMakeLists.txt index 11cf784..3d33e4c 100644 --- a/unittests/ExecutionEngine/JIT/CMakeLists.txt +++ b/unittests/ExecutionEngine/JIT/CMakeLists.txt @@ -19,7 +19,9 @@ if( LLVM_USE_INTEL_JITEVENTS ) ) set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} + DebugInfo IntelJITEvents + Object ) endif( LLVM_USE_INTEL_JITEVENTS ) diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index 0a9ee82..30dadc9 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -161,7 +161,7 @@ public: uintptr_t ActualSizeResult; }; std::vector<StartExceptionTableCall> startExceptionTableCalls; - virtual uint8_t* startExceptionTable(const Function* F, + virtual uint8_t *startExceptionTable(const Function *F, uintptr_t &ActualSize) { uintptr_t InitialActualSize = ActualSize; uint8_t *Result = Base->startExceptionTable(F, ActualSize); @@ -203,14 +203,21 @@ bool LoadAssemblyInto(Module *M, const char *assembly) { class JITTest : public testing::Test { protected: + virtual RecordingJITMemoryManager *createMemoryManager() { + return new RecordingJITMemoryManager; + } + virtual void SetUp() { M = new Module("<main>", Context); - RJMM = new RecordingJITMemoryManager; + RJMM = createMemoryManager(); RJMM->setPoisonMemory(true); std::string Error; + TargetOptions Options; + Options.JITExceptionHandling = true; TheJIT.reset(EngineBuilder(M).setEngineKind(EngineKind::JIT) .setJITMemoryManager(RJMM) - .setErrorStr(&Error).create()); + .setErrorStr(&Error) + .setTargetOptions(Options).create()); ASSERT_TRUE(TheJIT.get() != NULL) << Error; } @@ -297,6 +304,46 @@ TEST(JIT, GlobalInFunction) { #endif // !defined(__arm__) && !defined(__powerpc__) +// Regression test for a bug. The JITEmitter wasn't checking to verify that +// it hadn't run out of space while generating the DWARF exception information +// for an emitted function. + +class ExceptionMemoryManagerMock : public RecordingJITMemoryManager { + public: + virtual uint8_t *startExceptionTable(const Function *F, + uintptr_t &ActualSize) { + // force an insufficient size the first time through. + bool ChangeActualSize = false; + if (ActualSize == 0) + ChangeActualSize = true;; + uint8_t *result = + RecordingJITMemoryManager::startExceptionTable(F, ActualSize); + if (ChangeActualSize) + ActualSize = 1; + return result; + } +}; + +class JITExceptionMemoryTest : public JITTest { + protected: + virtual RecordingJITMemoryManager *createMemoryManager() { + return new ExceptionMemoryManagerMock; + } +}; + +TEST_F(JITExceptionMemoryTest, ExceptionTableOverflow) { + Function *F = Function::Create(TypeBuilder<void(void), false>::get(Context), + Function::ExternalLinkage, + "func1", M); + BasicBlock *Block = BasicBlock::Create(Context, "block", F); + IRBuilder<> Builder(Block); + Builder.CreateRetVoid(); + TheJIT->getPointerToFunction(F); + ASSERT_TRUE(RJMM->startExceptionTableCalls.size() == 2); + ASSERT_TRUE(RJMM->deallocateExceptionTableCalls.size() == 1); + ASSERT_TRUE(RJMM->endExceptionTableCalls.size() == 1); +} + int PlusOne(int arg) { return arg + 1; } diff --git a/unittests/ExecutionEngine/JIT/Makefile b/unittests/ExecutionEngine/JIT/Makefile index 9e0bb9e..ef8b827 100644 --- a/unittests/ExecutionEngine/JIT/Makefile +++ b/unittests/ExecutionEngine/JIT/Makefile @@ -24,7 +24,7 @@ ifeq ($(USE_INTEL_JITEVENTS), 1) CPPFLAGS += -I$(INTEL_JITEVENTS_INCDIR) # Link against the LLVM Intel JIT Evens interface library - LINK_COMPONENTS += inteljitevents + LINK_COMPONENTS += debuginfo inteljitevents object endif ifeq ($(USE_OPROFILE), 1) diff --git a/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h b/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h index 4604aa5..fc774ab 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h +++ b/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h @@ -52,7 +52,7 @@ protected: , MArch("") , Builder(Context) , MM(new SectionMemoryManager) - , HostTriple(LLVM_HOSTTRIPLE) + , HostTriple(sys::getProcessTriple()) { InitializeNativeTarget(); InitializeNativeTargetAsmPrinter(); |