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 @@ -2715,6 +2715,18 @@ FunctionPointer::Kind irgen::classifyFunctionPointerKind(SILFunction *fn) {
27152715
27162716 return fn->getLoweredFunctionType ();
27172717}
2718+ // Async functions that end up with weak_odr or linkonce_odr linkage may not be
2719+ // directly called because we need to preserve the connection between the
2720+ // function's implementation and the function's context size in the async
2721+ // function pointer data structure.
2722+ static bool mayDirectlyCallAsync (SILFunction *fn) {
2723+ if (fn->getLinkage () == SILLinkage::Shared ||
2724+ fn->getLinkage () == SILLinkage::PublicNonABI) {
2725+ return false ;
2726+ }
2727+
2728+ return true ;
2729+ }
27182730
27192731void IRGenSILFunction::visitFunctionRefBaseInst (FunctionRefBaseInst *i) {
27202732 auto fn = i->getInitiallyReferencedFunction ();
@@ -2741,7 +2753,8 @@ void IRGenSILFunction::visitFunctionRefBaseInst(FunctionRefBaseInst *i) {
27412753 if (fpKind.isAsyncFunctionPointer ()) {
27422754 value = IGM.getAddrOfAsyncFunctionPointer (fn);
27432755 value = llvm::ConstantExpr::getBitCast (value, fnPtr->getType ());
2744- secondaryValue = IGM.getAddrOfSILFunction (fn, NotForDefinition);
2756+ secondaryValue = mayDirectlyCallAsync (fn) ?
2757+ IGM.getAddrOfSILFunction (fn, NotForDefinition) : nullptr ;
27452758
27462759 // For ordinary sync functions and special async functions, produce
27472760 // only the direct address of the function. The runtime does not
You can’t perform that action at this time.
0 commit comments