using namespace llvm;
-class MCJITMultipleModuleTest : public testing::Test, public MCJITTestBase {
-public:
- virtual ~MCJITMultipleModuleTest();
-};
-
-// Provide out-of-line definition to prevent weak vtable.
-MCJITMultipleModuleTest::~MCJITMultipleModuleTest() {}
-
namespace {
+class MCJITMultipleModuleTest : public testing::Test, public MCJITTestBase {};
+
// FIXME: ExecutionEngine has no support empty modules
/*
TEST_F(MCJITMultipleModuleTest, multiple_empty_modules) {
TEST_F(MCJITMultipleModuleTest, two_module_case) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B;
+ std::unique_ptr<Module> A, B;
Function *FA, *FB;
createTwoModuleCase(A, FA, B, FB);
- createJIT(A.take());
- TheJIT->addModule(B.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
checkAdd(ptr);
TEST_F(MCJITMultipleModuleTest, two_module_reverse_case) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B;
+ std::unique_ptr<Module> A, B;
Function *FA, *FB;
createTwoModuleCase(A, FA, B, FB);
- createJIT(A.take());
- TheJIT->addModule(B.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
uint64_t ptr = TheJIT->getFunctionAddress(FB->getName().str());
TheJIT->finalizeObject();
TEST_F(MCJITMultipleModuleTest, two_module_extern_reverse_case) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B;
+ std::unique_ptr<Module> A, B;
Function *FA, *FB;
createTwoModuleExternCase(A, FA, B, FB);
- createJIT(A.take());
- TheJIT->addModule(B.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
uint64_t ptr = TheJIT->getFunctionAddress(FB->getName().str());
TheJIT->finalizeObject();
TEST_F(MCJITMultipleModuleTest, two_module_extern_case) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B;
+ std::unique_ptr<Module> A, B;
Function *FA, *FB;
createTwoModuleExternCase(A, FA, B, FB);
- createJIT(A.take());
- TheJIT->addModule(B.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
checkAdd(ptr);
TEST_F(MCJITMultipleModuleTest, two_module_consecutive_call_case) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B;
+ std::unique_ptr<Module> A, B;
Function *FA1, *FA2, *FB;
createTwoModuleExternCase(A, FA1, B, FB);
FA2 = insertSimpleCallFunction<int32_t(int32_t, int32_t)>(A.get(), FA1);
- createJIT(A.take());
- TheJIT->addModule(B.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
uint64_t ptr = TheJIT->getFunctionAddress(FB->getName().str());
TheJIT->finalizeObject();
TEST_F(MCJITMultipleModuleTest, two_module_global_variables_case) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B;
+ std::unique_ptr<Module> A, B;
Function *FA, *FB;
GlobalVariable *GVA, *GVB;
A.reset(createEmptyModule("A"));
FB = startFunction<int32_t(void)>(B.get(), "FB");
endFunctionWithRet(FB, Builder.CreateLoad(GVB));
- createJIT(A.take());
- TheJIT->addModule(B.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
uint64_t FBPtr = TheJIT->getFunctionAddress(FB->getName().str());
TheJIT->finalizeObject();
TEST_F(MCJITMultipleModuleTest, three_module_case) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B, C;
+ std::unique_ptr<Module> A, B, C;
Function *FA, *FB, *FC;
createThreeModuleCase(A, FA, B, FB, C, FC);
- createJIT(A.take());
- TheJIT->addModule(B.take());
- TheJIT->addModule(C.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
+ TheJIT->addModule(std::move(C));
uint64_t ptr = TheJIT->getFunctionAddress(FC->getName().str());
checkAdd(ptr);
TEST_F(MCJITMultipleModuleTest, three_module_case_reverse_order) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B, C;
+ std::unique_ptr<Module> A, B, C;
Function *FA, *FB, *FC;
createThreeModuleCase(A, FA, B, FB, C, FC);
- createJIT(A.take());
- TheJIT->addModule(B.take());
- TheJIT->addModule(C.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
+ TheJIT->addModule(std::move(C));
uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
checkAdd(ptr);
TEST_F(MCJITMultipleModuleTest, three_module_chain_case) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B, C;
+ std::unique_ptr<Module> A, B, C;
Function *FA, *FB, *FC;
createThreeModuleChainedCallsCase(A, FA, B, FB, C, FC);
- createJIT(A.take());
- TheJIT->addModule(B.take());
- TheJIT->addModule(C.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
+ TheJIT->addModule(std::move(C));
uint64_t ptr = TheJIT->getFunctionAddress(FC->getName().str());
checkAdd(ptr);
TEST_F(MCJITMultipleModuleTest, three_modules_chain_case_reverse_order) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B, C;
+ std::unique_ptr<Module> A, B, C;
Function *FA, *FB, *FC;
createThreeModuleChainedCallsCase(A, FA, B, FB, C, FC);
- createJIT(A.take());
- TheJIT->addModule(B.take());
- TheJIT->addModule(C.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
+ TheJIT->addModule(std::move(C));
uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
checkAdd(ptr);
TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B;
+ std::unique_ptr<Module> A, B;
Function *FA, *FB1, *FB2;
createCrossModuleRecursiveCase(A, FA, B, FB1, FB2);
- createJIT(A.take());
- TheJIT->addModule(B.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
checkAccumulate(ptr);
TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case_reverse_order) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B;
+ std::unique_ptr<Module> A, B;
Function *FA, *FB1, *FB2;
createCrossModuleRecursiveCase(A, FA, B, FB1, FB2);
- createJIT(A.take());
- TheJIT->addModule(B.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
uint64_t ptr = TheJIT->getFunctionAddress(FB1->getName().str());
checkAccumulate(ptr);
TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case3) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<Module> A, B;
+ std::unique_ptr<Module> A, B;
Function *FA, *FB1, *FB2;
createCrossModuleRecursiveCase(A, FA, B, FB1, FB2);
- createJIT(A.take());
- TheJIT->addModule(B.take());
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
uint64_t ptr = TheJIT->getFunctionAddress(FB1->getName().str());
checkAccumulate(ptr);
ptr = TheJIT->getFunctionAddress(FB2->getName().str());
checkAccumulate(ptr);
}
+
+// Test that FindFunctionNamed finds the definition of
+// a function in the correct module. We check two functions
+// in two different modules, to make sure that for at least
+// one of them MCJIT had to ignore the extern declaration.
+TEST_F(MCJITMultipleModuleTest, FindFunctionNamed_test) {
+ SKIP_UNSUPPORTED_PLATFORM;
+
+ std::unique_ptr<Module> A, B;
+ Function *FA, *FB1, *FB2;
+ createCrossModuleRecursiveCase(A, FA, B, FB1, FB2);
+
+ createJIT(std::move(A));
+ TheJIT->addModule(std::move(B));
+
+ EXPECT_EQ(FA, TheJIT->FindFunctionNamed(FA->getName().data()));
+ EXPECT_EQ(FB1, TheJIT->FindFunctionNamed(FB1->getName().data()));
+}
+
}