]> granicus.if.org Git - llvm/commitdiff
[ORC] Add unit tests for the reexports utility that were left out of r336741,
authorLang Hames <lhames@gmail.com>
Wed, 11 Jul 2018 04:39:11 +0000 (04:39 +0000)
committerLang Hames <lhames@gmail.com>
Wed, 11 Jul 2018 04:39:11 +0000 (04:39 +0000)
and fix a bug that these exposed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336760 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/Orc/Core.cpp
unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

index 38f2213a85f126207ebadf99a1cf05d1cb6f3317..7272cd6014d4af3246c45e4a9d71ce793e056d96 100644 (file)
@@ -462,7 +462,7 @@ void ReExportsMaterializationUnit::materialize(
               // FIXME: We're creating a SymbolFlagsMap and a std::map of
               // std::sets just to add one dependency here. This needs a
               // re-think.
-              Resolved.insert(KV.first);
+              Resolved.insert(KV.second.Aliasee);
             }
             QueryInfo->R.resolve(ResolutionMap);
 
index 0b36e3c49aa3966b4787148465aab17d185c1228..09e6a23bea7a3c1d5c455a30122a45bef59b40cb 100644 (file)
@@ -300,6 +300,48 @@ TEST_F(CoreAPIsStandardTest, TestChainedAliases) {
       << "\"Baz\"'s address should match \"Foo\"'s";
 }
 
+TEST_F(CoreAPIsStandardTest, TestBasicReExports) {
+  // Test that the basic use case of re-exporting a single symbol from another
+  // VSO works.
+  cantFail(V.define(absoluteSymbols({{Foo, FooSym}})));
+
+  auto &V2 = ES.createVSO("V2");
+
+  cantFail(V2.define(reexports(V, {{Bar, {Foo, BarSym.getFlags()}}})));
+
+  auto Result = cantFail(lookup({&V2}, Bar));
+  EXPECT_EQ(Result.getAddress(), FooSym.getAddress())
+      << "Re-export Bar for symbol Foo should match FooSym's address";
+}
+
+TEST_F(CoreAPIsStandardTest, TestThatReExportsDontUnnecessarilyMaterialize) {
+  // Test that re-exports do not materialize symbols that have not been queried
+  // for.
+  cantFail(V.define(absoluteSymbols({{Foo, FooSym}})));
+
+  bool BarMaterialized = false;
+  auto BarMU = llvm::make_unique<SimpleMaterializationUnit>(
+      SymbolFlagsMap({{Bar, BarSym.getFlags()}}),
+      [&](MaterializationResponsibility R) {
+        BarMaterialized = true;
+        R.resolve({{Bar, BarSym}});
+        R.finalize();
+      });
+
+  cantFail(V.define(BarMU));
+
+  auto &V2 = ES.createVSO("V2");
+
+  cantFail(V2.define(reexports(
+      V, {{Baz, {Foo, BazSym.getFlags()}}, {Qux, {Bar, QuxSym.getFlags()}}})));
+
+  auto Result = cantFail(lookup({&V2}, Baz));
+  EXPECT_EQ(Result.getAddress(), FooSym.getAddress())
+      << "Re-export Baz for symbol Foo should match FooSym's address";
+
+  EXPECT_FALSE(BarMaterialized) << "Bar should not have been materialized";
+}
+
 TEST_F(CoreAPIsStandardTest, TestTrivialCircularDependency) {
   Optional<MaterializationResponsibility> FooR;
   auto FooMU = llvm::make_unique<SimpleMaterializationUnit>(