Skip to content

Commit 3e077e7

Browse files
committed
IRGen: Use the 'right' async context index in the dynamic replacement prolog
The right index is the index derived for calling a function (Signature::forAsyncEntry) rather then for receiving the results (Signature::forAsyncAwait(); the resume fn signature). rdar://86863272
1 parent a1e2ebb commit 3e077e7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,7 @@ void IRGenModule::createReplaceableProlog(IRGenFunction &IGF, SILFunction *f) {
28482848
unsigned argIdx = 0;
28492849
for (auto arg : forwardedArgs) {
28502850
// Replace the context argument.
2851-
if (argIdx == asyncContextIndex)
2851+
if (argIdx == asyncFnPtr.getSignature().getAsyncContextIndex())
28522852
arguments.push_back(Builder.CreateBitOrPointerCast(
28532853
calleeContextBuffer.getAddress(), IGM.SwiftContextPtrTy));
28542854
else

test/IRGen/async_dynamic_replacement.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ internal func _replacement_number() async -> Int {
2323
public func calls_number() async -> Int {
2424
await number()
2525
}
26+
27+
// CHECK-LABEL: define swifttailcc void @"$s25async_dynamic_replacement32indirectReturnDynamicReplaceableSi_S6ityYaKF"(<{ %TSi, %TSi, %TSi, %TSi, %TSi, %TSi, %TSi }>* {{.*}}%0, %swift.context* swiftasync %1)
28+
// CHECK: forward_to_replaced:
29+
// CHECK: musttail call swifttailcc void {{.*}}(<{ %TSi, %TSi, %TSi, %TSi, %TSi, %TSi, %TSi }>* noalias nocapture %0, %swift.context* swiftasync {{.*}})
30+
public dynamic func indirectReturnDynamicReplaceable() async throws -> (Int, Int, Int, Int, Int, Int, Int) {
31+
return (0, 0, 0, 0, 0, 0, 0)
32+
}

0 commit comments

Comments
 (0)