xref: /llvm-project/llvm/test/Transforms/Coroutines/coro-async-end-bug.ll (revision 2d69827c5c754f0eca98e497ecf0e52ed54b4fd3)
1; RUN: opt < %s -passes='default<O2>' -S | FileCheck --check-prefixes=CHECK %s
2target datalayout = "p:64:64:64"
3
4%swift.async_func_pointer = type <{ i32, i32 }>
5%swift.context = type { ptr, ptr }
6%swift.opaque = type opaque
7%swift.refcounted = type { ptr, i64 }
8%swift.type = type { i64 }
9%swift.error = type opaque
10
11@repoTu = linkonce_odr hidden global %swift.async_func_pointer <{ i32 trunc (i64 sub (i64 ptrtoint (ptr @repo to i64), i64 ptrtoint (ptr @repoTu to i64)) to i32), i32 16 }>, align 8
12
13declare token @llvm.coro.id.async(i32, i32, i32, ptr) #0
14
15declare ptr @llvm.coro.begin(token, ptr writeonly) #0
16
17declare i1 @llvm.coro.end.async(ptr, i1, ...) #0
18
19define swifttailcc void @repo(ptr swiftasync %0, ptr noalias nocapture %1, ptr noalias nocapture %2, ptr %3, ptr %4, ptr %Self, ptr %Self.AsyncSequence, ptr %Self.Element.Comparable) #1 {
20entry:
21  %5 = alloca ptr, align 8
22  %6 = call token @llvm.coro.id.async(i32 16, i32 16, i32 0, ptr @repoTu)
23  %7 = call ptr @llvm.coro.begin(token %6, ptr null)
24  store ptr %0, ptr %5, align 8
25  %8 = call swiftcc i1 %3(ptr noalias nocapture %1, ptr noalias nocapture %2, ptr swiftself %4) #2
26  %9 = load ptr, ptr %5, align 8
27  %10 = getelementptr inbounds <{ ptr, ptr }>, ptr %9, i32 0, i32 1
28  %11 = load ptr, ptr %10, align 8
29  %12 = load ptr, ptr %5, align 8
30  %13 = call i1 (ptr, i1, ...) @llvm.coro.end.async(ptr %7, i1 false, ptr @repo.0, ptr %11, ptr %12, i1 %8, ptr null)
31  unreachable
32}
33
34; CHECK: define swifttailcc void @repo
35; CHECK-NOT:llvm.coro.end.async
36; CHECK: musttail call swifttailcc void
37; CHECK-NOT:llvm.coro.end.async
38; CHECK-NOT: unreachable
39; CHECK: ret
40
41define internal swifttailcc void @repo.0(ptr %0, ptr %1, i1 %2, ptr %3) #0 {
42entry:
43  musttail call swifttailcc void %0(ptr swiftasync %1, i1 %2, ptr swiftself %3)
44  ret void
45}
46
47attributes #0 = { nounwind }
48attributes #1 = { nounwind }
49