Skip to content

Commit f00cf74

Browse files
[IRGen] Put 'ret void' instead of unreachable for non swiftasync cc
If target doesn't support musttail (e.g. WebAssembly), the function passed to coro.end.async can return control back to the caller. So the frontend should emit 'ret void' instead of unreachable after the coro.end.async intrinsic call to allow such situation.
1 parent 862cbcc commit f00cf74

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/IRGen/GenCall.cpp

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

49084908
Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_end_async, arguments);
4909-
Builder.CreateUnreachable();
4909+
4910+
if (IGF.IGM.AsyncTailCallKind == llvm::CallInst::TCK_MustTail) {
4911+
Builder.CreateUnreachable();
4912+
} else {
4913+
// If target doesn't support musttail (e.g. WebAssembly), the function
4914+
// passed to coro.end.async can return control back to the caller.
4915+
// So use ret void instead of unreachable to allow it.
4916+
Builder.CreateRetVoid();
4917+
}
49104918
}
49114919

49124920
void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout,

0 commit comments

Comments
 (0)