Skip to content

Commit d06c9f3

Browse files
committed
IRGen: Add the swiftasync attribute to the resume function call for await_async_continuation
Without this we are going to crash (timing dependent) in withUnsafeContinuation and bridged async objective c calls. rdar://78031499
1 parent 99edcd6 commit d06c9f3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4915,8 +4915,11 @@ IRGenFunction::getFunctionPointerForResumeIntrinsic(llvm::Value *resume) {
49154915
auto *fnTy = llvm::FunctionType::get(
49164916
IGM.VoidTy, {IGM.Int8PtrTy},
49174917
false /*vaargs*/);
4918+
auto attrs = IGM.constructInitialAttributes();
4919+
attrs = attrs.addParamAttribute(IGM.getLLVMContext(), 0,
4920+
llvm::Attribute::SwiftAsync);
49184921
auto signature =
4919-
Signature(fnTy, IGM.constructInitialAttributes(), IGM.SwiftAsyncCC);
4922+
Signature(fnTy, attrs, IGM.SwiftAsyncCC);
49204923
auto fnPtr = FunctionPointer(
49214924
FunctionPointer::Kind::Function,
49224925
Builder.CreateBitOrPointerCast(resume, fnTy->getPointerTo()),

test/IRGen/async/get_async_continuation.sil

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bb0:
7373
// CHECK: unreachable
7474

7575
// CHECK: await.async.resume:
76-
// CHECK: call { i8* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async{{.*}}({{.*}} @__swift_async_resume_project_context
76+
// CHECK: call { i8* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async{{.*}}({{.*}} @__swift_async_resume_project_context{{.*}}@__swift_suspend_dispatch_1
7777
// CHECK: [[result_addr_addr:%.*]] = getelementptr inbounds %swift.continuation_context, %swift.continuation_context* [[cont_context]], i32 0, i32 3
7878
// CHECK: [[result_addr:%.*]] = load %swift.opaque*, %swift.opaque** [[result_addr_addr]]
7979
// CHECK: [[typed_result_addr:%.*]] = bitcast %swift.opaque* [[result_addr]] to i32*
@@ -83,6 +83,12 @@ bb0:
8383
// CHECK: [[result_bb]]:
8484
// CHECK: phi i32 [ [[result_value]], %await.async.resume ]
8585

86+
87+
// CHECK: define internal swifttailcc void @__swift_suspend_dispatch_1(i8* %0, i8* %1)
88+
// CHECK-NOT: define
89+
// CHECK: musttail call swifttailcc void %{{.*}}(i8* swiftasync %1)
90+
// CHECK-NEXT: ret void
91+
8692
sil @async_continuation : $@async () -> () {
8793
entry:
8894
%c = get_async_continuation Builtin.Int32

0 commit comments

Comments
 (0)