diff options
author | Eli Bendersky <eliben@google.com> | 2013-01-11 16:33:30 +0000 |
---|---|---|
committer | Eli Bendersky <eliben@google.com> | 2013-01-11 16:33:30 +0000 |
commit | dced3cdb0408f0802db332453a1e9c69c5fea70c (patch) | |
tree | 0da6f197a3ba9f9cdaa6e7be284ecda33a1c2088 /unittests/ExecutionEngine/JIT/JITTest.cpp | |
parent | 8c1e72e6acd7d413321c7270fc1a8c89e537a593 (diff) |
Fix bug in exception table allocation (PR13678)
Patch by Michael Muller.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172214 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ExecutionEngine/JIT/JITTest.cpp')
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITTest.cpp | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index 0a9ee82f49..30dadc9f3e 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; } |