File tree 1 file changed +14
-1
lines changed
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) {
2664
2664
2665
2665
return fn->getLoweredFunctionType ();
2666
2666
}
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
+ }
2667
2679
2668
2680
void IRGenSILFunction::visitFunctionRefBaseInst (FunctionRefBaseInst *i) {
2669
2681
auto fn = i->getInitiallyReferencedFunction ();
@@ -2690,7 +2702,8 @@ void IRGenSILFunction::visitFunctionRefBaseInst(FunctionRefBaseInst *i) {
2690
2702
if (fpKind.isAsyncFunctionPointer ()) {
2691
2703
value = IGM.getAddrOfAsyncFunctionPointer (fn);
2692
2704
value = llvm::ConstantExpr::getBitCast (value, fnPtr->getType ());
2693
- secondaryValue = IGM.getAddrOfSILFunction (fn, NotForDefinition);
2705
+ secondaryValue = mayDirectlyCallAsync (fn) ?
2706
+ IGM.getAddrOfSILFunction (fn, NotForDefinition) : nullptr ;
2694
2707
2695
2708
// For ordinary sync functions and special async functions, produce
2696
2709
// only the direct address of the function. The runtime does not
You can’t perform that action at this time.
0 commit comments