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