File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -2664,6 +2664,18 @@ FunctionPointer::Kind irgen::classifyFunctionPointerKind(SILFunction *fn) {
26642664
26652665 return fn->getLoweredFunctionType ();
26662666}
2667+ // Async functions that end up with weak_odr or linkonce_odr linkage may not be
2668+ // directly called because we need to preserve the connection between the
2669+ // function's implementation and the function's context size in the async
2670+ // function pointer data structure.
2671+ static bool mayDirectlyCallAsync (SILFunction *fn) {
2672+ if (fn->getLinkage () == SILLinkage::Shared ||
2673+ fn->getLinkage () == SILLinkage::PublicNonABI) {
2674+ return false ;
2675+ }
2676+
2677+ return true ;
2678+ }
26672679
26682680void IRGenSILFunction::visitFunctionRefBaseInst (FunctionRefBaseInst *i) {
26692681 auto fn = i->getInitiallyReferencedFunction ();
@@ -2690,7 +2702,8 @@ void IRGenSILFunction::visitFunctionRefBaseInst(FunctionRefBaseInst *i) {
26902702 if (fpKind.isAsyncFunctionPointer ()) {
26912703 value = IGM.getAddrOfAsyncFunctionPointer (fn);
26922704 value = llvm::ConstantExpr::getBitCast (value, fnPtr->getType ());
2693- secondaryValue = IGM.getAddrOfSILFunction (fn, NotForDefinition);
2705+ secondaryValue = mayDirectlyCallAsync (fn) ?
2706+ IGM.getAddrOfSILFunction (fn, NotForDefinition) : nullptr ;
26942707
26952708 // For ordinary sync functions and special async functions, produce
26962709 // only the direct address of the function. The runtime does not
You can’t perform that action at this time.
0 commit comments