1 // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc18.0.0 -fcoroutines-ts -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s
2 
3 void *myAlloc(long long);
4 
5 // CHECK-LABEL: f(
f(int n)6 void f(int n) {
7   // CHECK: %n.addr = alloca i32
8   // CHECK: %n_copy = alloca i32
9   // CHECK: %promise = alloca i32
10   int n_copy;
11   int promise;
12 
13   // CHECK: %[[PROM_ADDR:.+]] = bitcast i32* %promise to i8*
14   // CHECK-NEXT: %[[COROID:.+]] = call token @llvm.coro.id(i32 32, i8* %[[PROM_ADDR]], i8* null, i8* null)
15   __builtin_coro_id(32, &promise, 0, 0);
16 
17   // CHECK-NEXT: call i1 @llvm.coro.alloc(token %[[COROID]])
18   __builtin_coro_alloc();
19 
20   // CHECK-NEXT: call i8* @llvm.coro.noop()
21   __builtin_coro_noop();
22 
23   // CHECK-NEXT: %[[SIZE:.+]] = call i64 @llvm.coro.size.i64()
24   // CHECK-NEXT: %[[MEM:.+]] = call i8* @myAlloc(i64 %[[SIZE]])
25   // CHECK-NEXT: %[[FRAME:.+]] = call i8* @llvm.coro.begin(token %[[COROID]], i8* %[[MEM]])
26   __builtin_coro_begin(myAlloc(__builtin_coro_size()));
27 
28   // CHECK-NEXT: call void @llvm.coro.resume(i8* %[[FRAME]])
29   __builtin_coro_resume(__builtin_coro_frame());
30 
31   // CHECK-NEXT: call void @llvm.coro.destroy(i8* %[[FRAME]])
32   __builtin_coro_destroy(__builtin_coro_frame());
33 
34   // CHECK-NEXT: call i1 @llvm.coro.done(i8* %[[FRAME]])
35   __builtin_coro_done(__builtin_coro_frame());
36 
37   // CHECK-NEXT: call i8* @llvm.coro.promise(i8* %[[FRAME]], i32 48, i1 false)
38   __builtin_coro_promise(__builtin_coro_frame(), 48, 0);
39 
40   // CHECK-NEXT: call i8* @llvm.coro.free(token %[[COROID]], i8* %[[FRAME]])
41   __builtin_coro_free(__builtin_coro_frame());
42 
43   // CHECK-NEXT: call i1 @llvm.coro.end(i8* %[[FRAME]], i1 false)
44   __builtin_coro_end(__builtin_coro_frame(), 0);
45 
46   // CHECK-NEXT: call i8 @llvm.coro.suspend(token none, i1 true)
47   __builtin_coro_suspend(1);
48 
49   // CHECK-NEXT: %[[N_ADDR:.+]] = bitcast i32* %n.addr to i8*
50   // CHECK-NEXT: %[[N_COPY_ADDR:.+]] = bitcast i32* %n_copy to i8*
51   // CHECK-NEXT: call i1 @llvm.coro.param(i8* %[[N_ADDR]], i8* %[[N_COPY_ADDR]])
52   __builtin_coro_param(&n, &n_copy);
53 }
54