OSDN Git Service

[ORC] Convert null remote symbols to null JITSymbols.
authorLang Hames <lhames@gmail.com>
Tue, 5 Sep 2017 22:24:40 +0000 (22:24 +0000)
committerLang Hames <lhames@gmail.com>
Tue, 5 Sep 2017 22:24:40 +0000 (22:24 +0000)
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

include/llvm/ExecutionEngine/Orc/RemoteObjectLayer.h
unittests/ExecutionEngine/Orc/RemoteObjectLayerTest.cpp

index 9593be4..1725595 100644 (file)
@@ -214,6 +214,9 @@ protected:
   JITSymbol remoteToJITSymbol(Expected<RemoteSymbol> 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(); },
index da76890..819c5f8 100644 (file)
@@ -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<JITSymbolNotFound>(Name);
+          if (Name == "badsymbol")
+            return make_error<JITSymbolNotFound>(Name);
+          return nullptr;
         };
       return 42;
     });
@@ -374,19 +376,30 @@ TEST(RemoteObjectLayer, FindSymbol) {
   cantFail(Client.addObject(std::move(TestObject),
                             std::make_shared<NullResolver>()));
 
+  // 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<remote::utils::TerminateSession>());
   ServerThread.join();