1 ; Need to move users of allocas that were moved into the coroutine frame after
3 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
5 define nonnull i8* @f(i32 %n) {
7 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null);
9 store i32 %n, i32* %n.addr ; this needs to go after coro.begin
10 %0 = tail call i32 @llvm.coro.size.i32()
11 %call = tail call i8* @malloc(i32 %0)
12 %1 = tail call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %call)
13 %2 = bitcast i32* %n.addr to i8*
14 call void @ctor(i8* %2)
18 %3 = load i32, i32* %n.addr
19 %dec = add nsw i32 %3, -1
20 store i32 %dec, i32* %n.addr
21 call void @print(i32 %3)
22 %4 = call i8 @llvm.coro.suspend(token none, i1 false)
23 %conv = sext i8 %4 to i32
24 switch i32 %conv, label %coro_Suspend [
25 i32 0, label %for.cond
26 i32 1, label %coro_Cleanup
30 %5 = call i8* @llvm.coro.free(token %id, i8* nonnull %1)
31 call void @free(i8* %5)
32 br label %coro_Suspend
35 call i1 @llvm.coro.end(i8* null, i1 false)
42 %hdl = call i8* @f(i32 4)
43 call void @llvm.coro.resume(i8* %hdl)
44 call void @llvm.coro.resume(i8* %hdl)
45 call void @llvm.coro.destroy(i8* %hdl)
47 ; CHECK: call void @ctor
48 ; CHECK-NEXT: call void @print(i32 4)
49 ; CHECK-NEXT: call void @print(i32 3)
50 ; CHECK-NEXT: call void @print(i32 2)
54 declare i8* @malloc(i32)
55 declare void @free(i8*)
56 declare void @print(i32)
57 declare void @ctor(i8* nocapture readonly)
59 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
60 declare i32 @llvm.coro.size.i32()
61 declare i8* @llvm.coro.begin(token, i8*)
62 declare i8 @llvm.coro.suspend(token, i1)
63 declare i8* @llvm.coro.free(token, i8*)
64 declare i1 @llvm.coro.end(i8*, i1)
66 declare void @llvm.coro.resume(i8*)
67 declare void @llvm.coro.destroy(i8*)