Skip to content

Commit 0398252

Browse files
authored
Merge pull request swiftlang#39680 from kateinoigakukun/katei/fix-ill-unreachable-coro-end
[IRGen] Put 'ret void' instead of unreachable for non swiftasync cc
2 parents 600fd17 + 671ce74 commit 0398252

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4982,7 +4982,15 @@ void irgen::emitAsyncReturn(
49824982
arguments.push_back(arg);
49834983

49844984
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+
}
49864994
}
49874995

49884996
void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

0 commit comments

Comments
 (0)