Files
swift-mirror/test/IRGen/async/unreachable.swift
Arnold Schwaighofer 8c5fc073fd [IRGen] Use coro.end.async to return from an async function
The `coro.end.async` intrinsic allow specifying a function that is to be
tail-called as the last thing before returning.

LLVM lowering will inline the `must-tail-call` function argument to
`coro.end.async`. This `must-tail-call` function can contain a
`musttail` call.

```
define @my_must_tail_call_func(void (*)(i64) %fnptr, i64 %args) {
  musttail call void %fnptr(i64 %args)
  ret void
}

define @async_func() {
  ...
  coro.end.async(..., @my_must_tail_call_func, %return_continuation, i64 %args)
  unreachable
}
```
2021-03-10 10:15:27 -08:00

15 lines
419 B
Swift

// RUN: %target-swift-frontend -primary-file %s -g -emit-ir -enable-experimental-concurrency -disable-llvm-optzns -disable-swift-specific-llvm-optzns | %FileCheck %s
// REQUIRES: concurrency
// CHECK: call i1 (i8*, i1, ...) @llvm.coro.end.async
func foo() async -> Never {
await bar()
fatalError()
}
// CHECK: call i1 (i8*, i1, ...) @llvm.coro.end.async
func bar() async -> Never {
await foo()
fatalError()
}