Skip to content

[IRGen] Put 'ret void' instead of unreachable for non swiftasync cc #39680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4929,7 +4929,15 @@ void irgen::emitAsyncReturn(
arguments.push_back(arg);

Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_end_async, arguments);
Builder.CreateUnreachable();

if (IGF.IGM.AsyncTailCallKind == llvm::CallInst::TCK_MustTail) {
Builder.CreateUnreachable();
} else {
// If target doesn't support musttail (e.g. WebAssembly), the function
// passed to coro.end.async can return control back to the caller.
// So use ret void instead of unreachable to allow it.
Builder.CreateRetVoid();
}
}

void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout,
Expand Down
17 changes: 17 additions & 0 deletions test/IRGen/async/non_musttail_target.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Ensure that IRGen don't emit unreachable after coro.end.async for targets that don't support musttail call.
// 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
// REQUIRES: concurrency
// REQUIRES: CODEGENERATOR=WebAssembly

sil_stage canonical

import Builtin

sil @test_simple : $@async () -> () {
bb0:
%0 = tuple ()
return %0 : $()
// CHECK: call i1 (i8*, i1, ...) @llvm.coro.end.async
// CHECK-NOT: unreachable
// CHECK: ret void
}