File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -4978,7 +4978,15 @@ void irgen::emitAsyncReturn(
4978
4978
arguments.push_back (arg);
4979
4979
4980
4980
Builder.CreateIntrinsicCall (llvm::Intrinsic::coro_end_async, arguments);
4981
- Builder.CreateUnreachable ();
4981
+
4982
+ if (IGF.IGM .AsyncTailCallKind == llvm::CallInst::TCK_MustTail) {
4983
+ Builder.CreateUnreachable ();
4984
+ } else {
4985
+ // If target doesn't support musttail (e.g. WebAssembly), the function
4986
+ // passed to coro.end.async can return control back to the caller.
4987
+ // So use ret void instead of unreachable to allow it.
4988
+ Builder.CreateRetVoid ();
4989
+ }
4982
4990
}
4983
4991
4984
4992
void irgen::emitAsyncReturn (IRGenFunction &IGF, AsyncContextLayout &asyncLayout,
Original file line number Diff line number Diff line change
1
+ // Ensure that IRGen don't emit unreachable after coro.end.async for targets that don't support musttail call.
2
+ // RUN: %swift -disable-legacy-type-info -parse-stdlib -target wasm32-unknown-wasi %s -disable-llvm-optzns -disable-swift-specific-llvm-optzns -disable-objc-interop -module-name main -emit-ir -o - | %FileCheck %s
3
+ // REQUIRES: concurrency
4
+ // REQUIRES: CODEGENERATOR=WebAssembly
5
+
6
+ sil_stage canonical
7
+
8
+ import Builtin
9
+
10
+ sil @test_simple : $@async () -> () {
11
+ bb0:
12
+ %0 = tuple ()
13
+ return %0 : $()
14
+ // CHECK: call i1 (i8*, i1, ...) @llvm.coro.end.async
15
+ // CHECK-NOT: unreachable
16
+ // CHECK: ret void
17
+ }
You can’t perform that action at this time.
0 commit comments