[JITLink] Remove LTmp workaround now that LLVM requires C++17 (#213428)

C++17 guarantees the postfix-expression naming the called function is
sequenced before evaluation of its arguments, so
L->linkPhase1(std::move(L)) is well-formed without the LTmp indirection.
This should also be implemented by MSVC now. See here (P0145R3 and
P0400R0):

https://learn.microsoft.com/ar-sa/cpp/overview/visual-cpp-language-conformance?view=msvc-170
Disclaimer: As I have no LLVM Windows machine with MSVC at hand, I was
not able to test it myself.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Marc Auberer 2026-08-02 02:32:48 +02:00 committed by GitHub
parent 1ac9b999f8
commit 303e63dbd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 31 deletions

View file

@ -54,11 +54,7 @@ void JITLinkerBase::linkPhase1(std::unique_ptr<JITLinkerBase> Self) {
Ctx->getMemoryManager().allocate(
Ctx->getJITLinkDylib(), *G,
[S = std::move(Self)](AllocResult AR) mutable {
// FIXME: Once MSVC implements c++17 order of evaluation rules for calls
// this can be simplified to
// S->linkPhase2(std::move(S), std::move(AR));
auto *TmpSelf = S.get();
TmpSelf->linkPhase2(std::move(S), std::move(AR));
S->linkPhase2(std::move(S), std::move(AR));
});
}
@ -95,10 +91,7 @@ void JITLinkerBase::linkPhase2(std::unique_ptr<JITLinkerBase> Self,
dbgs() << "No external symbols for " << G->getName()
<< ". Proceeding immediately with link phase 3.\n";
});
// FIXME: Once MSVC implements c++17 order of evaluation rules for calls
// this can be simplified. See below.
auto &TmpSelf = *Self;
TmpSelf.linkPhase3(std::move(Self), AsyncLookupResult());
Self->linkPhase3(std::move(Self), AsyncLookupResult());
return;
}
@ -108,22 +101,11 @@ void JITLinkerBase::linkPhase2(std::unique_ptr<JITLinkerBase> Self,
<< " (may trigger materialization/linking of other graphs)...\n";
});
// We're about to hand off ownership of ourself to the continuation. Grab a
// pointer to the context so that we can call it to initiate the lookup.
//
// FIXME: Once MSVC implements c++17 order of evaluation rules for calls this
// can be simplified to:
//
// Ctx->lookup(std::move(UnresolvedExternals),
// [Self=std::move(Self)](Expected<AsyncLookupResult> Result) {
// Self->linkPhase3(std::move(Self), std::move(Result));
// });
Ctx->lookup(std::move(ExternalSymbols),
createLookupContinuation(
[S = std::move(Self)](
Expected<AsyncLookupResult> LookupResult) mutable {
auto &TmpSelf = *S;
TmpSelf.linkPhase3(std::move(S), std::move(LookupResult));
S->linkPhase3(std::move(S), std::move(LookupResult));
}));
}
@ -171,11 +153,7 @@ void JITLinkerBase::linkPhase3(std::unique_ptr<JITLinkerBase> Self,
}
Alloc->finalize([S = std::move(Self)](FinalizeResult FR) mutable {
// FIXME: Once MSVC implements c++17 order of evaluation rules for calls
// this can be simplified to
// S->linkPhase2(std::move(S), std::move(AR));
auto *TmpSelf = S.get();
TmpSelf->linkPhase4(std::move(S), std::move(FR));
S->linkPhase4(std::move(S), std::move(FR));
});
}

View file

@ -116,12 +116,10 @@ public:
// Ownership of the linker is passed into the linker's doLink function to
// allow it to be passed on to async continuations.
//
// FIXME: Remove LTmp once we have c++17.
// C++17 sequencing rules guarantee that function name expressions are
// sequenced before arguments, so L->linkPhase1(std::move(L), ...) will be
// well formed.
auto &LTmp = *L;
LTmp.linkPhase1(std::move(L));
// sequenced before arguments, so L->linkPhase1(std::move(L)) is well
// formed.
L->linkPhase1(std::move(L));
}
private: