Skip to content

Commit e349fd0

Browse files
committed
[SIL] Fixed return index for call-as-async (BOOL, Error, Value) case.
When converting an ObjC method type which is being called as async to a Swift function type, some of the values passed to the ObjC method's completion handler are converted to return values of the Swift function. The flag and error parameters, however, if present, are ignored. When abstracting the result type for the Swift method, the formal type of the corresponding parameter in the ObjC method's completion handler is used. Digging out that parameter entails indexing into the parameters of the completion handler. Previously, the indexing logic relied on the error appearing before the flag if both appeared before the value of interest. Here, the indexing is tweaked to check both special indices for each possible index until the first that matches neither is found. rdar://81625544
1 parent cef64c9 commit e349fd0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,14 @@ AbstractionPattern AbstractionPattern::getFunctionResultType() const {
574574
// If there's a single argument, abstract it according to its formal type
575575
// in the ObjC signature.
576576
unsigned callbackResultIndex = 0;
577-
if (callbackErrorIndex && callbackResultIndex >= *callbackErrorIndex)
578-
++callbackResultIndex;
579-
if (callbackErrorFlagIndex
580-
&& callbackResultIndex >= *callbackErrorFlagIndex)
581-
++callbackResultIndex;
582-
577+
for (auto index : indices(callbackParamTy->getParamTypes())) {
578+
if (callbackErrorIndex && index == *callbackErrorIndex)
579+
continue;
580+
if (callbackErrorFlagIndex && index == *callbackErrorFlagIndex)
581+
continue;
582+
callbackResultIndex = index;
583+
break;
584+
}
583585
auto clangResultType = callbackParamTy
584586
->getParamType(callbackResultIndex)
585587
.getTypePtr();

validation-test/compiler_crashers_2_fixed/rdar81617749.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ func run(on object: PFXObject) async throws {
2525
// CHECK: performSingleBothy13
2626
print(try await object.performSingleBothy13()())
2727

28-
// Reenable with rdar://81625544
29-
// CHECK performSingleBothy21
30-
// print(try await object.performSingleBothy21()())
28+
// CHECK: performSingleBothy21
29+
print(try await object.performSingleBothy21()())
3130

3231
// CHECK: performSingleBothy23
3332
print(try await object.performSingleBothy23()())

0 commit comments

Comments
 (0)