summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@google.com>2010-03-04 19:45:09 +0000
committerJeffrey Yasskin <jyasskin@google.com>2010-03-04 19:45:09 +0000
commitc3b7d1edfa10286d807fa5de5115860d48f76b17 (patch)
tree2e957d4b6f682be85f92d51efa87fc55fa7f548c /llvm/unittests/ExecutionEngine/JIT/JITTest.cpp
parent0b46650b6609120c908bcb72518e1554fc190aa4 (diff)
downloadbcm5719-llvm-c3b7d1edfa10286d807fa5de5115860d48f76b17.tar.gz
bcm5719-llvm-c3b7d1edfa10286d807fa5de5115860d48f76b17.zip
Fix PR6360. It's easy for a stub's address to escape to user code, so we can't
just count references to it from JIT output to decide when to destroy it. This patch waits to destroy the JIT's memory of a stub until the Function it refers to is destroyed. External function stubs and GVIndirectSyms aren't destroyed until the JIT itself is. llvm-svn: 97737
Diffstat (limited to 'llvm/unittests/ExecutionEngine/JIT/JITTest.cpp')
-rw-r--r--llvm/unittests/ExecutionEngine/JIT/JITTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp b/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp
index 168bb3cb98d..b85f724353c 100644
--- a/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp
+++ b/llvm/unittests/ExecutionEngine/JIT/JITTest.cpp
@@ -655,6 +655,29 @@ TEST_F(JITTest, NeedsExactSizeWithManyGlobals) {
EXPECT_EQ(42, *********test());
}
+TEST_F(JITTest, EscapedLazyStubStillCallable) {
+ TheJIT->DisableLazyCompilation(false);
+ LoadAssembly("define internal i32 @stubbed() { "
+ " ret i32 42 "
+ "} "
+ " "
+ "define i32()* @get_stub() { "
+ " ret i32()* @stubbed "
+ "} ");
+ typedef int32_t(*StubTy)();
+
+ // Call get_stub() to get the address of @stubbed without actually JITting it.
+ Function *get_stubIR = M->getFunction("get_stub");
+ StubTy (*get_stub)() = reinterpret_cast<StubTy(*)()>(
+ (intptr_t)TheJIT->getPointerToFunction(get_stubIR));
+ StubTy stubbed = get_stub();
+ // Now get_stubIR is the only reference to stubbed's stub.
+ get_stubIR->eraseFromParent();
+ // Now there are no references inside the JIT, but we've got a pointer outside
+ // it. The stub should be callable and return the right value.
+ EXPECT_EQ(42, stubbed());
+}
+
// Converts the LLVM assembly to bitcode and returns it in a std::string. An
// empty string indicates an error.
std::string AssembleToBitcode(LLVMContext &Context, const char *Assembly) {
OpenPOWER on IntegriCloud