diff --git a/lib/ExecutionEngine/Orc/Core.cpp b/lib/ExecutionEngine/Orc/Core.cpp index ecfa116a646..15c9578e691 100644 --- a/lib/ExecutionEngine/Orc/Core.cpp +++ b/lib/ExecutionEngine/Orc/Core.cpp @@ -1031,6 +1031,7 @@ Error JITDylib::resolve(const SymbolMap &Resolved) { auto &MI = MaterializingInfos[Name]; for (auto &Q : MI.takeQueriesMeeting(SymbolState::Resolved)) { Q->notifySymbolMetRequiredState(Name, ResolvedSym); + Q->removeQueryDependence(*this, Name); if (Q->isComplete()) CompletedQueries.insert(std::move(Q)); } diff --git a/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp index 729dad9c29a..60612f6c6a7 100644 --- a/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp +++ b/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp @@ -935,7 +935,7 @@ TEST_F(CoreAPIsStandardTest, FailResolution) { } } -TEST_F(CoreAPIsStandardTest, FailEmissionEarly) { +TEST_F(CoreAPIsStandardTest, FailEmissionAfterResolution) { cantFail(JD.define(absoluteSymbols({{Baz, BazSym}}))); @@ -970,6 +970,30 @@ TEST_F(CoreAPIsStandardTest, FailEmissionEarly) { << "Unexpected success while trying to test error propagation"; } +TEST_F(CoreAPIsStandardTest, FailAfterPartialResolution) { + + cantFail(JD.define(absoluteSymbols({{Foo, FooSym}}))); + + // Fail materialization of bar. + auto BarMU = std::make_unique( + SymbolFlagsMap({{Bar, BarSym.getFlags()}}), + [&](MaterializationResponsibility R) { R.failMaterialization(); }); + + cantFail(JD.define(std::move(BarMU))); + + bool QueryHandlerRun = false; + ES.lookup( + JITDylibSearchList({{&JD, false}}), SymbolNameSet({Foo, Bar}), + SymbolState::Resolved, + [&](Expected Result) { + EXPECT_THAT_EXPECTED(std::move(Result), Failed()) + << "Expected query to fail"; + QueryHandlerRun = true; + }, + NoDependenciesToRegister); + EXPECT_TRUE(QueryHandlerRun) << "Query handler never ran"; +} + TEST_F(CoreAPIsStandardTest, TestLookupWithUnthreadedMaterialization) { auto MU = std::make_unique( SymbolFlagsMap({{Foo, JITSymbolFlags::Exported}}),