@@ -81,10 +81,12 @@ class LargeSILTypeMapper {
8181 irgen::IRGenModule &IGM);
8282 SmallVector<SILResultInfo, 2 > getNewResults (GenericEnvironment *GenericEnv,
8383 CanSILFunctionType fnType,
84- irgen::IRGenModule &Mod);
84+ irgen::IRGenModule &Mod,
85+ bool mustTransform = false );
8586 CanSILFunctionType getNewSILFunctionType (GenericEnvironment *env,
8687 CanSILFunctionType fnType,
87- irgen::IRGenModule &IGM);
88+ irgen::IRGenModule &IGM,
89+ bool mustTransform = false );
8890 SILType getNewOptionalFunctionType (GenericEnvironment *GenericEnv,
8991 SILType storageType,
9092 irgen::IRGenModule &Mod);
@@ -241,8 +243,9 @@ bool LargeSILTypeMapper::newResultsDiffer(GenericEnvironment *GenericEnv,
241243
242244static bool modNonFuncTypeResultType (GenericEnvironment *genEnv,
243245 CanSILFunctionType loweredTy,
244- irgen::IRGenModule &Mod) {
245- if (!modifiableFunction (loweredTy)) {
246+ irgen::IRGenModule &Mod,
247+ bool mustTransform = false ) {
248+ if (!modifiableFunction (loweredTy) && !mustTransform) {
246249 return false ;
247250 }
248251 if (loweredTy->getNumResults () != 1 ) {
@@ -259,7 +262,8 @@ static bool modNonFuncTypeResultType(GenericEnvironment *genEnv,
259262SmallVector<SILResultInfo, 2 >
260263LargeSILTypeMapper::getNewResults (GenericEnvironment *GenericEnv,
261264 CanSILFunctionType fnType,
262- irgen::IRGenModule &Mod) {
265+ irgen::IRGenModule &Mod,
266+ bool mustTransform) {
263267 // Get new SIL Function results - same as old results UNLESS:
264268 // 1) Function type results might have a different signature
265269 // 2) Large loadables are replaced by @out version
@@ -268,7 +272,7 @@ LargeSILTypeMapper::getNewResults(GenericEnvironment *GenericEnv,
268272 for (auto result : origResults) {
269273 SILType currResultTy = result.getSILStorageInterfaceType ();
270274 SILType newSILType = getNewSILType (GenericEnv, currResultTy, Mod);
271- if (modNonFuncTypeResultType (GenericEnv, fnType, Mod)) {
275+ if (modNonFuncTypeResultType (GenericEnv, fnType, Mod, mustTransform )) {
272276 // Case (2) Above
273277 SILResultInfo newSILResultInfo (newSILType.getASTType (),
274278 ResultConvention::Indirect);
@@ -288,8 +292,9 @@ LargeSILTypeMapper::getNewResults(GenericEnvironment *GenericEnv,
288292CanSILFunctionType
289293LargeSILTypeMapper::getNewSILFunctionType (GenericEnvironment *env,
290294 CanSILFunctionType fnType,
291- irgen::IRGenModule &IGM) {
292- if (!modifiableFunction (fnType)) {
295+ irgen::IRGenModule &IGM,
296+ bool mustTransform) {
297+ if (!modifiableFunction (fnType) && !mustTransform) {
293298 return fnType;
294299 }
295300
@@ -301,7 +306,7 @@ LargeSILTypeMapper::getNewSILFunctionType(GenericEnvironment *env,
301306
302307 auto newParams = getNewParameters (env, fnType, IGM);
303308 auto newYields = getNewYields (env, fnType, IGM);
304- auto newResults = getNewResults (env, fnType, IGM);
309+ auto newResults = getNewResults (env, fnType, IGM, mustTransform );
305310 auto newFnType = SILFunctionType::get (
306311 fnType->getInvocationGenericSignature (),
307312 fnType->getExtInfo (),
@@ -2623,7 +2628,20 @@ void LoadableByAddress::recreateSingleApply(
26232628 // Change the type of the Closure
26242629 auto partialApplyConvention = castedApply->getCalleeConvention ();
26252630 auto resultIsolation = castedApply->getResultIsolation ();
2626-
2631+ // We do need to update the closure's funtion type to match with the other
2632+ // uses inside of the binary. Pointer auth cares about the SIL function
2633+ // type.
2634+ if (callee->getType ().castTo <SILFunctionType>()->getExtInfo ().getRepresentation () ==
2635+ SILFunctionTypeRepresentation::ObjCMethod) {
2636+ CanSILFunctionType newFnType =
2637+ MapperCache.getNewSILFunctionType (
2638+ genEnv,
2639+ callee->getType ().castTo <SILFunctionType>(), *currIRMod,
2640+ /* mustTransform*/ true );
2641+ SILType newType = SILType::getPrimitiveObjectType (newFnType);
2642+ callee = applyBuilder.createConvertFunction (castedApply->getLoc (),
2643+ callee, newType, false );
2644+ }
26272645 auto newApply = applyBuilder.createPartialApply (
26282646 castedApply->getLoc (), callee, applySite.getSubstitutionMap (), callArgs,
26292647 partialApplyConvention, resultIsolation, castedApply->isOnStack ());
0 commit comments