@@ -80,10 +80,12 @@ class LargeSILTypeMapper {
8080 irgen::IRGenModule &IGM);
8181 SmallVector<SILResultInfo, 2 > getNewResults (GenericEnvironment *GenericEnv,
8282 CanSILFunctionType fnType,
83- irgen::IRGenModule &Mod);
83+ irgen::IRGenModule &Mod,
84+ bool mustTransform = false );
8485 CanSILFunctionType getNewSILFunctionType (GenericEnvironment *env,
8586 CanSILFunctionType fnType,
86- irgen::IRGenModule &IGM);
87+ irgen::IRGenModule &IGM,
88+ bool mustTransform = false );
8789 SILType getNewOptionalFunctionType (GenericEnvironment *GenericEnv,
8890 SILType storageType,
8991 irgen::IRGenModule &Mod);
@@ -240,8 +242,9 @@ bool LargeSILTypeMapper::newResultsDiffer(GenericEnvironment *GenericEnv,
240242
241243static bool modNonFuncTypeResultType (GenericEnvironment *genEnv,
242244 CanSILFunctionType loweredTy,
243- irgen::IRGenModule &Mod) {
244- if (!modifiableFunction (loweredTy)) {
245+ irgen::IRGenModule &Mod,
246+ bool mustTransform = false ) {
247+ if (!modifiableFunction (loweredTy) && !mustTransform) {
245248 return false ;
246249 }
247250 if (loweredTy->getNumResults () != 1 ) {
@@ -258,7 +261,8 @@ static bool modNonFuncTypeResultType(GenericEnvironment *genEnv,
258261SmallVector<SILResultInfo, 2 >
259262LargeSILTypeMapper::getNewResults (GenericEnvironment *GenericEnv,
260263 CanSILFunctionType fnType,
261- irgen::IRGenModule &Mod) {
264+ irgen::IRGenModule &Mod,
265+ bool mustTransform) {
262266 // Get new SIL Function results - same as old results UNLESS:
263267 // 1) Function type results might have a different signature
264268 // 2) Large loadables are replaced by @out version
@@ -267,7 +271,7 @@ LargeSILTypeMapper::getNewResults(GenericEnvironment *GenericEnv,
267271 for (auto result : origResults) {
268272 SILType currResultTy = result.getSILStorageInterfaceType ();
269273 SILType newSILType = getNewSILType (GenericEnv, currResultTy, Mod);
270- if (modNonFuncTypeResultType (GenericEnv, fnType, Mod)) {
274+ if (modNonFuncTypeResultType (GenericEnv, fnType, Mod, mustTransform )) {
271275 // Case (2) Above
272276 SILResultInfo newSILResultInfo (newSILType.getASTType (),
273277 ResultConvention::Indirect);
@@ -287,8 +291,9 @@ LargeSILTypeMapper::getNewResults(GenericEnvironment *GenericEnv,
287291CanSILFunctionType
288292LargeSILTypeMapper::getNewSILFunctionType (GenericEnvironment *env,
289293 CanSILFunctionType fnType,
290- irgen::IRGenModule &IGM) {
291- if (!modifiableFunction (fnType)) {
294+ irgen::IRGenModule &IGM,
295+ bool mustTransform) {
296+ if (!modifiableFunction (fnType) && !mustTransform) {
292297 return fnType;
293298 }
294299
@@ -300,7 +305,7 @@ LargeSILTypeMapper::getNewSILFunctionType(GenericEnvironment *env,
300305
301306 auto newParams = getNewParameters (env, fnType, IGM);
302307 auto newYields = getNewYields (env, fnType, IGM);
303- auto newResults = getNewResults (env, fnType, IGM);
308+ auto newResults = getNewResults (env, fnType, IGM, mustTransform );
304309 auto newFnType = SILFunctionType::get (
305310 fnType->getInvocationGenericSignature (),
306311 fnType->getExtInfo (),
@@ -2621,7 +2626,20 @@ void LoadableByAddress::recreateSingleApply(
26212626 // Change the type of the Closure
26222627 auto partialApplyConvention = castedApply->getCalleeConvention ();
26232628 auto resultIsolation = castedApply->getResultIsolation ();
2624-
2629+ // We do need to update the closure's funtion type to match with the other
2630+ // uses inside of the binary. Pointer auth cares about the SIL function
2631+ // type.
2632+ if (callee->getType ().castTo <SILFunctionType>()->getExtInfo ().getRepresentation () ==
2633+ SILFunctionTypeRepresentation::ObjCMethod) {
2634+ CanSILFunctionType newFnType =
2635+ MapperCache.getNewSILFunctionType (
2636+ genEnv,
2637+ callee->getType ().castTo <SILFunctionType>(), *currIRMod,
2638+ /* mustTransform*/ true );
2639+ SILType newType = SILType::getPrimitiveObjectType (newFnType);
2640+ callee = applyBuilder.createConvertFunction (castedApply->getLoc (),
2641+ callee, newType, false );
2642+ }
26252643 auto newApply = applyBuilder.createPartialApply (
26262644 castedApply->getLoc (), callee, applySite.getSubstitutionMap (), callArgs,
26272645 partialApplyConvention, resultIsolation, castedApply->isOnStack ());
0 commit comments