diff options
author | Lang Hames <lhames@gmail.com> | 2014-10-22 23:18:42 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2014-10-22 23:18:42 +0000 |
commit | efe7e2267316adecf0bee20bd9e0da21924a59c7 (patch) | |
tree | 4ef983604dd16a2c2c2e42c96376289a57088dc6 /llvm/unittests | |
parent | 01aea5809f19901fc30fe40ff03b662c1bb90141 (diff) | |
download | bcm5719-llvm-efe7e2267316adecf0bee20bd9e0da21924a59c7.tar.gz bcm5719-llvm-efe7e2267316adecf0bee20bd9e0da21924a59c7.zip |
[MCJIT] Make repeat calls to MCJIT::getPointerToFunction for declarations safe.
MCJIT::getPointerForFunction adds the resulting address to the global mapping.
This should be done via updateGlobalMapping rather than addGlobalMapping, since
the latter asserts if a mapping already exists.
MCJIT::getPointerToFunction is actually deprecated - hopefully we can remove it
(or more likely re-task it) entirely soon. In the mean time it should at least
work as advertised.
<rdar://problem/18727946>
llvm-svn: 220444
Diffstat (limited to 'llvm/unittests')
-rw-r--r-- | llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp | 12 | ||||
-rw-r--r-- | llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp index 15e0efdb971..64d8c2fca04 100644 --- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp +++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp @@ -187,4 +187,16 @@ TEST_F(MCJITTest, multiple_functions) { #endif /*!defined(__arm__)*/ +TEST_F(MCJITTest, multiple_decl_lookups) { + SKIP_UNSUPPORTED_PLATFORM; + + Function *Foo = insertExternalReferenceToFunction<void(void)>(M.get(), "_exit"); + createJIT(std::move(M)); + void *A = TheJIT->getPointerToFunction(Foo); + void *B = TheJIT->getPointerToFunction(Foo); + + EXPECT_TRUE(A != 0) << "Failed lookup - test not correctly configured."; + EXPECT_EQ(A, B) << "Repeat calls to getPointerToFunction fail."; +} + } diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h index bc44418003c..eea88bbe3f4 100644 --- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h +++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestBase.h @@ -107,6 +107,15 @@ protected: return Result; } + // Inserts a declaration to a function defined elsewhere + template <typename FuncType> + Function *insertExternalReferenceToFunction(Module *M, StringRef Name) { + Function *Result = Function::Create( + TypeBuilder<FuncType, false>::get(Context), + GlobalValue::ExternalLinkage, Name, M); + return Result; + } + // Inserts an declaration to a function defined elsewhere Function *insertExternalReferenceToFunction(Module *M, StringRef Name, FunctionType *FuncTy) { |