Expected<AsyncLookupResult> LR) {
// If the lookup failed, bail out.
if (!LR)
- return Ctx->notifyFailed(LR.takeError());
+ return deallocateAndBailOut(LR.takeError());
// Assign addresses to external atoms.
applyLookupResult(*LR);
// Copy atom content to working memory and fix up.
if (auto Err = copyAndFixUpAllAtoms(Layout, *Alloc))
- return Ctx->notifyFailed(std::move(Err));
+ return deallocateAndBailOut(std::move(Err));
LLVM_DEBUG({
dbgs() << "Atom graph \"" << G->getName() << "\" after copy-and-fixup:\n";
});
if (auto Err = runPasses(Passes.PostFixupPasses, *G))
- return Ctx->notifyFailed(std::move(Err));
+ return deallocateAndBailOut(std::move(Err));
// FIXME: Use move capture once we have c++14.
auto *UnownedSelf = Self.release();
void JITLinkerBase::linkPhase3(std::unique_ptr<JITLinkerBase> Self, Error Err) {
if (Err)
- return Ctx->notifyFailed(std::move(Err));
+ return deallocateAndBailOut(std::move(Err));
Ctx->notifyFinalized(std::move(Alloc));
}
"All atoms should have been resolved by this point");
}
+void JITLinkerBase::deallocateAndBailOut(Error Err) {
+ assert(Err && "Should not be bailing out on success value");
+ assert(Alloc && "can not call deallocateAndBailOut before allocation");
+ Ctx->notifyFailed(joinErrors(std::move(Err), Alloc->deallocate()));
+}
+
void JITLinkerBase::dumpGraph(raw_ostream &OS) {
assert(G && "Graph is not set yet");
G->dump(dbgs(), [this](Edge::Kind K) { return getEdgeKindName(K); });