1 ; Tests that coro-split can handle the case when a code after coro.suspend uses
2 ; a value produces between coro.save and coro.suspend (%Result.i19)
3 ; and checks whether stray coro.saves are properly removed
4 ; RUN: opt < %s -coro-split -S | FileCheck %s
6 %"struct.std::coroutine_handle" = type { i8* }
7 %"struct.std::coroutine_handle.0" = type { %"struct.std::coroutine_handle" }
8 %"struct.lean_future<int>::Awaiter" = type { i32, %"struct.std::coroutine_handle.0" }
10 declare i8* @malloc(i64)
11 declare void @print(i32)
13 define void @a() "coroutine.presplit"="1" {
15 %ref.tmp7 = alloca %"struct.lean_future<int>::Awaiter", align 8
16 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
17 %alloc = call i8* @malloc(i64 16) #3
18 %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
20 %save = call token @llvm.coro.save(i8* null)
21 %Result.i19 = getelementptr inbounds %"struct.lean_future<int>::Awaiter", %"struct.lean_future<int>::Awaiter"* %ref.tmp7, i64 0, i32 0
22 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
23 switch i8 %suspend, label %exit [
24 i8 0, label %await.ready
28 %StrayCoroSave = call token @llvm.coro.save(i8* null)
29 %val = load i32, i32* %Result.i19
30 call void @print(i32 %val)
33 call i1 @llvm.coro.end(i8* null, i1 false)
37 ; CHECK-LABEL: @a.resume(
38 ; CHECK: getelementptr inbounds %a.Frame
39 ; CHECK-NEXT: getelementptr inbounds %"struct.lean_future<int>::Awaiter"
40 ; CHECK-NOT: call token @llvm.coro.save(i8* null)
41 ; CHECK-NEXT: %val = load i32, i32* %Result
42 ; CHECK-NEXT: call void @print(i32 %val)
43 ; CHECK-NEXT: ret void
45 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
46 declare i1 @llvm.coro.alloc(token) #3
47 declare noalias nonnull i8* @"\01??2@YAPEAX_K@Z"(i64) local_unnamed_addr
48 declare i64 @llvm.coro.size.i64() #5
49 declare i8* @llvm.coro.begin(token, i8* writeonly) #3
50 declare void @"\01?puts@@YAXZZ"(...)
51 declare token @llvm.coro.save(i8*) #3
52 declare i8* @llvm.coro.frame() #5
53 declare i8 @llvm.coro.suspend(token, i1) #3
54 declare void @"\01??3@YAXPEAX@Z"(i8*) local_unnamed_addr #10
55 declare i8* @llvm.coro.free(token, i8* nocapture readonly) #2
56 declare i1 @llvm.coro.end(i8*, i1) #3