diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2009-10-23 22:37:43 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2009-10-23 22:37:43 +0000 |
commit | d0fc8f809af1c06f56d0bccec35cda724252f96f (patch) | |
tree | ea8bfc3fd935f3e48f98718bbdd555ca3582136f /llvm/unittests/ExecutionEngine/JIT/JITTest.cpp | |
parent | 091f04256a60c07b7abaccacbf557c930ed75460 (diff) | |
download | bcm5719-llvm-d0fc8f809af1c06f56d0bccec35cda724252f96f.tar.gz bcm5719-llvm-d0fc8f809af1c06f56d0bccec35cda724252f96f.zip |
Fix http://llvm.org/PR4822: allow module deletion after a function has been
compiled.
When functions are compiled, they accumulate references in the JITResolver's
stub maps. This patch removes those references when the functions are
destroyed. It's illegal to destroy a Function when any thread may still try to
call its machine code.
This patch also updates r83987 to use ValueMap instead of explicit CallbackVHs
and fixes a couple "do stuff inside assert()" bugs from r84522.
llvm-svn: 84975
Diffstat (limited to 'llvm/unittests/ExecutionEngine/JIT/JITTest.cpp')
-rw-r--r-- | llvm/unittests/ExecutionEngine/JIT/JITTest.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp b/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp index 8f9b65ab0ba..e47a4370aea 100644 --- a/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -9,6 +9,7 @@ #include "gtest/gtest.h" #include "llvm/ADT/OwningPtr.h" +#include "llvm/Assembly/Parser.h" #include "llvm/BasicBlock.h" #include "llvm/Constant.h" #include "llvm/Constants.h" @@ -22,6 +23,7 @@ #include "llvm/Module.h" #include "llvm/ModuleProvider.h" #include "llvm/Support/IRBuilder.h" +#include "llvm/Support/SourceMgr.h" #include "llvm/Support/TypeBuilder.h" #include "llvm/Target/TargetSelect.h" #include "llvm/Type.h" @@ -49,14 +51,25 @@ class JITTest : public testing::Test { protected: virtual void SetUp() { M = new Module("<main>", Context); + MP = new ExistingModuleProvider(M); std::string Error; - TheJIT.reset(EngineBuilder(M).setEngineKind(EngineKind::JIT) + TheJIT.reset(EngineBuilder(MP).setEngineKind(EngineKind::JIT) .setErrorStr(&Error).create()); ASSERT_TRUE(TheJIT.get() != NULL) << Error; } + void LoadAssembly(const char *assembly) { + SMDiagnostic Error; + bool success = NULL != ParseAssemblyString(assembly, M, Error, Context); + std::string errMsg; + raw_string_ostream os(errMsg); + Error.Print("", os); + ASSERT_TRUE(success) << os.str(); + } + LLVMContext Context; - Module *M; // Owned by ExecutionEngine. + Module *M; // Owned by MP. + ModuleProvider *MP; // Owned by ExecutionEngine. OwningPtr<ExecutionEngine> TheJIT; }; @@ -264,6 +277,20 @@ TEST_F(JITTest, NonLazyLeaksNoStubs) { } #endif +TEST_F(JITTest, ModuleDeletion) { + LoadAssembly("define void @main() { " + " call i32 @computeVal() " + " ret void " + "} " + " " + "define internal i32 @computeVal() { " + " ret i32 0 " + "} "); + Function *func = M->getFunction("main"); + TheJIT->getPointerToFunction(func); + TheJIT->deleteModuleProvider(MP); +} + // This code is copied from JITEventListenerTest, but it only runs once for all // the tests in this directory. Everything seems fine, but that's strange // behavior. |