From a7beb93b94a459991d0bfc717a8d5534caadcd89 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 5 Sep 2017 22:24:40 +0000 Subject: [PATCH] [ORC] Convert null remote symbols to null JITSymbols. The existing code created a JITSymbol with an invalid materializer instead, guaranteeing a 'missing symbol' error when someone tried to materialize the symbol. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312584 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/ExecutionEngine/Orc/RemoteObjectLayer.h | 3 ++ .../ExecutionEngine/Orc/RemoteObjectLayerTest.cpp | 33 +++++++++++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/include/llvm/ExecutionEngine/Orc/RemoteObjectLayer.h b/include/llvm/ExecutionEngine/Orc/RemoteObjectLayer.h index 9593be4b76c..17255954a99 100644 --- a/include/llvm/ExecutionEngine/Orc/RemoteObjectLayer.h +++ b/include/llvm/ExecutionEngine/Orc/RemoteObjectLayer.h @@ -214,6 +214,9 @@ protected: JITSymbol remoteToJITSymbol(Expected RemoteSymOrErr) { if (RemoteSymOrErr) { auto &RemoteSym = *RemoteSymOrErr; + if (RemoteSym == nullRemoteSymbol()) + return nullptr; + // else... RemoteSymbolMaterializer RSM(*this, RemoteSym.first); auto Sym = JITSymbol([RSM]() mutable { return RSM.materialize(); }, diff --git a/unittests/ExecutionEngine/Orc/RemoteObjectLayerTest.cpp b/unittests/ExecutionEngine/Orc/RemoteObjectLayerTest.cpp index da76890d73d..819c5f8eb34 100644 --- a/unittests/ExecutionEngine/Orc/RemoteObjectLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/RemoteObjectLayerTest.cpp @@ -334,7 +334,7 @@ TEST(RemoteObjectLayer, FindSymbol) { auto ReportError = [](Error Err) { auto ErrMsg = toString(std::move(Err)); - EXPECT_EQ(ErrMsg, "Could not find symbol 'barbaz'") + EXPECT_EQ(ErrMsg, "Could not find symbol 'badsymbol'") << "Expected error string to be \"Object handle 42 not found\""; }; @@ -352,7 +352,9 @@ TEST(RemoteObjectLayer, FindSymbol) { [](StringRef Name, bool ExportedSymbolsOnly) -> JITSymbol { if (Name == "foobar") return JITSymbol(0x12348765, JITSymbolFlags::Exported); - return make_error(Name); + if (Name == "badsymbol") + return make_error(Name); + return nullptr; }; return 42; }); @@ -374,19 +376,30 @@ TEST(RemoteObjectLayer, FindSymbol) { cantFail(Client.addObject(std::move(TestObject), std::make_shared())); + // Check that we can find and materialize a valid symbol. auto Sym1 = Client.findSymbol("foobar", true); - EXPECT_TRUE(!!Sym1) << "Symbol 'foobar' should be findable"; EXPECT_EQ(cantFail(Sym1.getAddress()), 0x12348765ULL) << "Symbol 'foobar' does not return the correct address"; - auto Sym2 = Client.findSymbol("barbaz", true); - EXPECT_FALSE(!!Sym2) << "Symbol 'barbaz' should not be findable"; - auto Err = Sym2.takeError(); - EXPECT_TRUE(!!Err) << "Sym2 should contain an error value"; - auto ErrMsg = toString(std::move(Err)); - EXPECT_EQ(ErrMsg, "Could not find symbol 'barbaz'") - << "Expected symbol-not-found error for Sym2"; + { + // Check that we can return a symbol containing an error. + auto Sym2 = Client.findSymbol("badsymbol", true); + EXPECT_FALSE(!!Sym2) << "Symbol 'badsymbol' should not be findable"; + auto Err = Sym2.takeError(); + EXPECT_TRUE(!!Err) << "Sym2 should contain an error value"; + auto ErrMsg = toString(std::move(Err)); + EXPECT_EQ(ErrMsg, "Could not find symbol 'badsymbol'") + << "Expected symbol-not-found error for Sym2"; + } + + { + // Check that we can return a 'null' symbol. + auto Sym3 = Client.findSymbol("baz", true); + EXPECT_FALSE(!!Sym3) << "Symbol 'baz' should convert to false"; + auto Err = Sym3.takeError(); + EXPECT_FALSE(!!Err) << "Symbol 'baz' should not contain an error"; + } cantFail(ClientEP.callB()); ServerThread.join(); -- 2.11.0