16ed67ccbSChuanqi Xu // RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple x86_64-unknown-linux-gnu -std=c++20 -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping %s -o - | FileCheck %s
2565e37c7SXun Li
3ec117158SChuanqi Xu namespace std {
4565e37c7SXun Li template <typename... T>
5565e37c7SXun Li struct coroutine_traits;
6565e37c7SXun Li
7565e37c7SXun Li template <class Promise = void>
8565e37c7SXun Li struct coroutine_handle {
9565e37c7SXun Li coroutine_handle() = default;
from_addressstd::coroutine_handle10565e37c7SXun Li static coroutine_handle from_address(void *) noexcept { return {}; }
11565e37c7SXun Li };
12565e37c7SXun Li template <>
13565e37c7SXun Li struct coroutine_handle<void> {
from_addressstd::coroutine_handle14565e37c7SXun Li static coroutine_handle from_address(void *) { return {}; }
15565e37c7SXun Li coroutine_handle() = default;
16565e37c7SXun Li template <class PromiseType>
coroutine_handlestd::coroutine_handle17565e37c7SXun Li coroutine_handle(coroutine_handle<PromiseType>) noexcept {}
18565e37c7SXun Li };
19ec117158SChuanqi Xu } // namespace std
20565e37c7SXun Li
21565e37c7SXun Li struct suspend_always {
22565e37c7SXun Li bool await_ready() noexcept;
23ec117158SChuanqi Xu void await_suspend(std::coroutine_handle<>) noexcept;
24565e37c7SXun Li void await_resume() noexcept;
25565e37c7SXun Li };
26565e37c7SXun Li
27565e37c7SXun Li template <>
28ec117158SChuanqi Xu struct std::coroutine_traits<int, int> {
29565e37c7SXun Li struct promise_type {
30565e37c7SXun Li int get_return_object();
31565e37c7SXun Li suspend_always initial_suspend();
32565e37c7SXun Li suspend_always final_suspend() noexcept;
3380bebbc7SNathan Sidwell void unhandled_exception() noexcept;
34565e37c7SXun Li void return_value(int);
35*050593fcSAndrey Ali Khan Bolshakov suspend_always yield_value(int);
36565e37c7SXun Li };
37565e37c7SXun Li };
38565e37c7SXun Li
39565e37c7SXun Li // CHECK-LABEL: _Z2f1i:
f1(int x)409f2967bcSAlan Phipps int f1(int x) { // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE+8]]:2 = #0
41565e37c7SXun Li if (x > 42) { // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = #0
429f2967bcSAlan Phipps // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> [[@LINE-1]]:13 = #1, (#0 - #1)
439f2967bcSAlan Phipps ++x; // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:14 -> [[@LINE-2]]:15 = #1
449f2967bcSAlan Phipps } else { // CHECK-NEXT: File 0, [[@LINE-3]]:15 -> [[@LINE]]:4 = #1
45565e37c7SXun Li co_return x + 42; // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE-1]]:10 = (#0 - #1)
46565e37c7SXun Li } // CHECK-NEXT: File 0, [[@LINE-2]]:10 -> [[@LINE]]:4 = (#0 - #1)
47565e37c7SXun Li co_return x; // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE]]:3 = #1
489783e209SZequan Wu } // CHECK-NEXT: File 0, [[@LINE-1]]:3 -> [[@LINE-1]]:14 = #1
49*050593fcSAndrey Ali Khan Bolshakov
50*050593fcSAndrey Ali Khan Bolshakov // CHECK-LABEL: _Z2f2i:
51*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: File 0, [[@LINE+1]]:15 -> [[@LINE+15]]:2 = #0
f2(int x)52*050593fcSAndrey Ali Khan Bolshakov int f2(int x) {
53*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: File 0, [[@LINE+5]]:13 -> [[@LINE+5]]:18 = #0
54*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: Branch,File 0, [[@LINE+4]]:13 -> [[@LINE+4]]:18 = #1, (#0 - #1)
55*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: Gap,File 0, [[@LINE+3]]:20 -> [[@LINE+3]]:21 = #1
56*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: File 0, [[@LINE+2]]:21 -> [[@LINE+2]]:37 = #1
57*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: File 0, [[@LINE+1]]:40 -> [[@LINE+1]]:56 = (#0 - #1)
58*050593fcSAndrey Ali Khan Bolshakov co_await (x > 0 ? suspend_always{} : suspend_always{});
59*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: File 0, [[@LINE+5]]:12 -> [[@LINE+5]]:17 = #0
60*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: Branch,File 0, [[@LINE+4]]:12 -> [[@LINE+4]]:17 = #2, (#0 - #2)
61*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: Gap,File 0, [[@LINE+3]]:19 -> [[@LINE+3]]:20 = #2
62*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: File 0, [[@LINE+2]]:20 -> [[@LINE+2]]:21 = #2
63*050593fcSAndrey Ali Khan Bolshakov // CHECK-NEXT: File 0, [[@LINE+1]]:24 -> [[@LINE+1]]:25 = (#0 - #2)
64*050593fcSAndrey Ali Khan Bolshakov co_yield x > 0 ? 1 : 2;
65*050593fcSAndrey Ali Khan Bolshakov co_return 0;
66*050593fcSAndrey Ali Khan Bolshakov }
67