Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.9] IRGen: Don't directly call async functions that have weak/linkonce_odr linkage #65350

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,18 @@ FunctionPointer::Kind irgen::classifyFunctionPointerKind(SILFunction *fn) {

return fn->getLoweredFunctionType();
}
// Async functions that end up with weak_odr or linkonce_odr linkage may not be
// directly called because we need to preserve the connection between the
// function's implementation and the function's context size in the async
// function pointer data structure.
static bool mayDirectlyCallAsync(SILFunction *fn) {
if (fn->getLinkage() == SILLinkage::Shared ||
fn->getLinkage() == SILLinkage::PublicNonABI) {
return false;
}

return true;
}

void IRGenSILFunction::visitFunctionRefBaseInst(FunctionRefBaseInst *i) {
auto fn = i->getInitiallyReferencedFunction();
Expand All @@ -2741,7 +2753,8 @@ void IRGenSILFunction::visitFunctionRefBaseInst(FunctionRefBaseInst *i) {
if (fpKind.isAsyncFunctionPointer()) {
value = IGM.getAddrOfAsyncFunctionPointer(fn);
value = llvm::ConstantExpr::getBitCast(value, fnPtr->getType());
secondaryValue = IGM.getAddrOfSILFunction(fn, NotForDefinition);
secondaryValue = mayDirectlyCallAsync(fn) ?
IGM.getAddrOfSILFunction(fn, NotForDefinition) : nullptr;

// For ordinary sync functions and special async functions, produce
// only the direct address of the function. The runtime does not
Expand Down