Skip to content

Commit b142815

Browse files
committed
IRGen: Don't directly call async functions that have weak/linkonce_odr linkage
The async function pointer context size and the async function implementiation are logically tied. Using a different async context pointer context size and async function implementation (from different translation units) is problematic. rdar://106029807
1 parent c0d7a82 commit b142815

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff 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

27192731
void 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

0 commit comments

Comments
 (0)