@@ -6133,14 +6133,22 @@ void IRGenSILFunction::visitWitnessMethodInst(swift::WitnessMethodInst *i) {
61336133 CanType baseTy = i->getLookupType ();
61346134 ProtocolConformanceRef conformance = i->getConformance ();
61356135 SILDeclRef member = i->getMember ();
6136+ auto fnType = IGM.getSILTypes ().getConstantFunctionType (
6137+ IGM.getMaximalTypeExpansionContext (), member);
61366138
61376139 assert (member.requiresNewWitnessTableEntry ());
61386140
61396141 if (IGM.isResilient (conformance.getRequirement (),
61406142 ResilienceExpansion::Maximal)) {
6141- auto *fnPtr = IGM.getAddrOfDispatchThunk (member, NotForDefinition);
6142- auto fnType = IGM.getSILTypes ().getConstantFunctionType (
6143- IGM.getMaximalTypeExpansionContext (), member);
6143+ llvm::Constant *fnPtr = IGM.getAddrOfDispatchThunk (member, NotForDefinition);
6144+
6145+ if (fnType->isAsync ()) {
6146+ auto *fnPtrType = fnPtr->getType ();
6147+ fnPtr = IGM.getAddrOfAsyncFunctionPointer (
6148+ LinkEntity::forDispatchThunk (member));
6149+ fnPtr = llvm::ConstantExpr::getBitCast (fnPtr, fnPtrType);
6150+ }
6151+
61446152 auto sig = IGM.getSignature (fnType);
61456153 auto fn = FunctionPointer::forDirect (fnType, fnPtr, sig);
61466154
@@ -6340,7 +6348,15 @@ void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
63406348 auto *classDecl = cast<ClassDecl>(method.getDecl ()->getDeclContext ());
63416349 if (IGM.hasResilientMetadata (classDecl,
63426350 ResilienceExpansion::Maximal)) {
6343- auto *fnPtr = IGM.getAddrOfDispatchThunk (method, NotForDefinition);
6351+ llvm::Constant *fnPtr = IGM.getAddrOfDispatchThunk (method, NotForDefinition);
6352+
6353+ if (methodType->isAsync ()) {
6354+ auto *fnPtrType = fnPtr->getType ();
6355+ fnPtr = IGM.getAddrOfAsyncFunctionPointer (
6356+ LinkEntity::forDispatchThunk (method));
6357+ fnPtr = llvm::ConstantExpr::getBitCast (fnPtr, fnPtrType);
6358+ }
6359+
63446360 auto sig = IGM.getSignature (methodType);
63456361 FunctionPointer fn (methodType, fnPtr, sig);
63466362
0 commit comments