aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/ExecutionEngine
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@google.com>2009-10-23 22:37:43 +0000
committerJeffrey Yasskin <jyasskin@google.com>2009-10-23 22:37:43 +0000
commit23e5fcfec4640955fec41dc8348f467adf1a3e56 (patch)
treeff1de1e3e7b059ed882c0e5c6a3e1c7a8632ddde /unittests/ExecutionEngine
parent7b929dad59785f62a66f7c58615082f98441e95e (diff)
downloadexternal_llvm-23e5fcfec4640955fec41dc8348f467adf1a3e56.zip
external_llvm-23e5fcfec4640955fec41dc8348f467adf1a3e56.tar.gz
external_llvm-23e5fcfec4640955fec41dc8348f467adf1a3e56.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84975 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ExecutionEngine')
-rw-r--r--unittests/ExecutionEngine/JIT/JITTest.cpp31
-rw-r--r--unittests/ExecutionEngine/JIT/Makefile2
2 files changed, 30 insertions, 3 deletions
diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp
index 8f9b65a..e47a437 100644
--- a/unittests/ExecutionEngine/JIT/JITTest.cpp
+++ b/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.
diff --git a/unittests/ExecutionEngine/JIT/Makefile b/unittests/ExecutionEngine/JIT/Makefile
index 0069c76..048924a 100644
--- a/unittests/ExecutionEngine/JIT/Makefile
+++ b/unittests/ExecutionEngine/JIT/Makefile
@@ -9,7 +9,7 @@
LEVEL = ../../..
TESTNAME = JIT
-LINK_COMPONENTS := core support jit native
+LINK_COMPONENTS := asmparser core support jit native
include $(LEVEL)/Makefile.config
include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest