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 @@ -4982,7 +4982,15 @@ void irgen::emitAsyncReturn(
4982
4982
arguments.push_back (arg);
4983
4983
4984
4984
Builder.CreateIntrinsicCall (llvm::Intrinsic::coro_end_async, arguments);
4985
- Builder.CreateUnreachable ();
4985
+
4986
+ if (IGF.IGM .AsyncTailCallKind == llvm::CallInst::TCK_MustTail) {
4987
+ Builder.CreateUnreachable ();
4988
+ } else {
4989
+ // If target doesn't support musttail (e.g. WebAssembly), the function
4990
+ // passed to coro.end.async can return control back to the caller.
4991
+ // So use ret void instead of unreachable to allow it.
4992
+ Builder.CreateRetVoid ();
4993
+ }
4986
4994
}
4987
4995
4988
4996
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