llvm.org GIT mirror llvm / 79fafc7
[ORC] Remove symbols from dependency lists when failing materialization. When failing materialization of a symbol X, remove X from the dependants list of any of X's dependencies. This ensures that when X's dependencies are emitted (or fail themselves) they do not try to access the no-longer-existing MaterializationInfo for X. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359252 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 1 year, 7 months ago
3 changed file(s) with 68 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
389389 }
390390
391391 void MaterializationResponsibility::resolve(const SymbolMap &Symbols) {
392 LLVM_DEBUG(dbgs() << "In " << JD.getName() << " resolving " << Symbols
393 << "\n");
392 LLVM_DEBUG(
393 { dbgs() << "In " << JD.getName() << " resolving " << Symbols << "\n"; });
394394 #ifndef NDEBUG
395395 for (auto &KV : Symbols) {
396396 auto I = SymbolFlags.find(KV.first);
411411 }
412412
413413 void MaterializationResponsibility::emit() {
414
415 LLVM_DEBUG({
416 dbgs() << "In " << JD.getName() << " emitting " << SymbolFlags << "\n";
417 });
418
414419 #ifndef NDEBUG
415420 for (auto &KV : SymbolFlags)
416421 assert(!KV.second.isMaterializing() &&
439444 }
440445
441446 void MaterializationResponsibility::failMaterialization() {
447
448 LLVM_DEBUG({
449 dbgs() << "In " << JD.getName() << " failing materialization for "
450 << SymbolFlags << "\n";
451 });
442452
443453 SymbolNameSet FailedSymbols;
444454 for (auto &KV : SymbolFlags)
10231033 // there is nobody to notify.
10241034 if (MII == MaterializingInfos.end())
10251035 continue;
1036
1037 // Remove this symbol from the dependants list of any dependencies.
1038 for (auto &KV : MII->second.UnemittedDependencies) {
1039 auto *DependencyJD = KV.first;
1040 auto &Dependencies = KV.second;
1041 for (auto &DependencyName : Dependencies) {
1042 auto DependencyMII =
1043 DependencyJD->MaterializingInfos.find(DependencyName);
1044 assert(DependencyMII != DependencyJD->MaterializingInfos.end() &&
1045 "Unemitted dependency must have a MaterializingInfo entry");
1046 assert(DependencyMII->second.Dependants.count(this) &&
1047 "Dependency's dependants list does not contain this JITDylib");
1048 assert(DependencyMII->second.Dependants[this].count(Name) &&
1049 "Dependency's dependants list does not contain dependant");
1050 DependencyMII->second.Dependants[this].erase(Name);
1051 }
1052 }
10261053
10271054 // Copy all the queries to the FailedQueries list, then abandon them.
10281055 // This has to be a copy, and the copy has to come before the abandon
2929 ThreadSafeModuleTest.cpp
3030 )
3131
32 target_link_libraries(OrcJITTests PRIVATE ${ORC_JIT_TEST_LIBS})
32 target_link_libraries(OrcJITTests PRIVATE
33 LLVMTestingSupport
34 ${ORC_JIT_TEST_LIBS})
99 #include "llvm/Config/llvm-config.h"
1010 #include "llvm/ExecutionEngine/Orc/Core.h"
1111 #include "llvm/ExecutionEngine/Orc/OrcError.h"
12 #include "llvm/Testing/Support/Error.h"
1213
1314 #include
1415 #include
729730 }
730731 }
731732
733 TEST_F(CoreAPIsStandardTest, FailEmissionEarly) {
734
735 cantFail(JD.define(absoluteSymbols({{Baz, BazSym}})));
736
737 auto MU = llvm::make_unique(
738 SymbolFlagsMap({{Foo, FooSym.getFlags()}, {Bar, BarSym.getFlags()}}),
739 [&](MaterializationResponsibility R) {
740 R.resolve(SymbolMap({{Foo, FooSym}, {Bar, BarSym}}));
741
742 ES.lookup(
743 JITDylibSearchList({{&JD, false}}), SymbolNameSet({Baz}),
744 [&R](Expected Result) {
745 // Called when "baz" is resolved. We don't actually depend
746 // on or care about baz, but use it to trigger failure of
747 // this materialization before Baz has been finalized in
748 // order to test that error propagation is correct in this
749 // scenario.
750 cantFail(std::move(Result));
751 R.failMaterialization();
752 },
753 [](Error Err) { cantFail(std::move(Err)); },
754 [&](const SymbolDependenceMap &Deps) {
755 R.addDependenciesForAll(Deps);
756 });
757 });
758
759 cantFail(JD.define(MU));
760
761 SymbolNameSet Names({Foo, Bar});
762 auto Result = ES.lookup(JITDylibSearchList({{&JD, false}}), Names);
763
764 EXPECT_THAT_EXPECTED(std::move(Result), Failed())
765 << "Unexpected success while trying to test error propagation";
766 }
767
732768 TEST_F(CoreAPIsStandardTest, TestLookupWithUnthreadedMaterialization) {
733769 auto MU = llvm::make_unique(
734770 SymbolFlagsMap({{Foo, JITSymbolFlags::Exported}}),