@@ -81,10 +81,12 @@ class LargeSILTypeMapper {
81
81
irgen::IRGenModule &IGM);
82
82
SmallVector<SILResultInfo, 2 > getNewResults (GenericEnvironment *GenericEnv,
83
83
CanSILFunctionType fnType,
84
- irgen::IRGenModule &Mod);
84
+ irgen::IRGenModule &Mod,
85
+ bool mustTransform = false );
85
86
CanSILFunctionType getNewSILFunctionType (GenericEnvironment *env,
86
87
CanSILFunctionType fnType,
87
- irgen::IRGenModule &IGM);
88
+ irgen::IRGenModule &IGM,
89
+ bool mustTransform = false );
88
90
SILType getNewOptionalFunctionType (GenericEnvironment *GenericEnv,
89
91
SILType storageType,
90
92
irgen::IRGenModule &Mod);
@@ -241,8 +243,9 @@ bool LargeSILTypeMapper::newResultsDiffer(GenericEnvironment *GenericEnv,
241
243
242
244
static bool modNonFuncTypeResultType (GenericEnvironment *genEnv,
243
245
CanSILFunctionType loweredTy,
244
- irgen::IRGenModule &Mod) {
245
- if (!modifiableFunction (loweredTy)) {
246
+ irgen::IRGenModule &Mod,
247
+ bool mustTransform = false ) {
248
+ if (!modifiableFunction (loweredTy) && !mustTransform) {
246
249
return false ;
247
250
}
248
251
if (loweredTy->getNumResults () != 1 ) {
@@ -259,7 +262,8 @@ static bool modNonFuncTypeResultType(GenericEnvironment *genEnv,
259
262
SmallVector<SILResultInfo, 2 >
260
263
LargeSILTypeMapper::getNewResults (GenericEnvironment *GenericEnv,
261
264
CanSILFunctionType fnType,
262
- irgen::IRGenModule &Mod) {
265
+ irgen::IRGenModule &Mod,
266
+ bool mustTransform) {
263
267
// Get new SIL Function results - same as old results UNLESS:
264
268
// 1) Function type results might have a different signature
265
269
// 2) Large loadables are replaced by @out version
@@ -268,7 +272,7 @@ LargeSILTypeMapper::getNewResults(GenericEnvironment *GenericEnv,
268
272
for (auto result : origResults) {
269
273
SILType currResultTy = result.getSILStorageInterfaceType ();
270
274
SILType newSILType = getNewSILType (GenericEnv, currResultTy, Mod);
271
- if (modNonFuncTypeResultType (GenericEnv, fnType, Mod)) {
275
+ if (modNonFuncTypeResultType (GenericEnv, fnType, Mod, mustTransform )) {
272
276
// Case (2) Above
273
277
SILResultInfo newSILResultInfo (newSILType.getASTType (),
274
278
ResultConvention::Indirect);
@@ -288,8 +292,9 @@ LargeSILTypeMapper::getNewResults(GenericEnvironment *GenericEnv,
288
292
CanSILFunctionType
289
293
LargeSILTypeMapper::getNewSILFunctionType (GenericEnvironment *env,
290
294
CanSILFunctionType fnType,
291
- irgen::IRGenModule &IGM) {
292
- if (!modifiableFunction (fnType)) {
295
+ irgen::IRGenModule &IGM,
296
+ bool mustTransform) {
297
+ if (!modifiableFunction (fnType) && !mustTransform) {
293
298
return fnType;
294
299
}
295
300
@@ -301,7 +306,7 @@ LargeSILTypeMapper::getNewSILFunctionType(GenericEnvironment *env,
301
306
302
307
auto newParams = getNewParameters (env, fnType, IGM);
303
308
auto newYields = getNewYields (env, fnType, IGM);
304
- auto newResults = getNewResults (env, fnType, IGM);
309
+ auto newResults = getNewResults (env, fnType, IGM, mustTransform );
305
310
auto newFnType = SILFunctionType::get (
306
311
fnType->getInvocationGenericSignature (),
307
312
fnType->getExtInfo (),
@@ -2623,7 +2628,20 @@ void LoadableByAddress::recreateSingleApply(
2623
2628
// Change the type of the Closure
2624
2629
auto partialApplyConvention = castedApply->getCalleeConvention ();
2625
2630
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
+ }
2627
2645
auto newApply = applyBuilder.createPartialApply (
2628
2646
castedApply->getLoc (), callee, applySite.getSubstitutionMap (), callArgs,
2629
2647
partialApplyConvention, resultIsolation, castedApply->isOnStack ());
0 commit comments