1 // fixme: the following line is added to cleanup bots, will be removed in weeks.
2 // RUN: rm -f %S/coroutine.ll
3 // RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping %s -o - | FileCheck %s
4 
5 namespace std::experimental {
6 template <typename... T>
7 struct coroutine_traits;
8 
9 template <class Promise = void>
10 struct coroutine_handle {
11   coroutine_handle() = default;
12   static coroutine_handle from_address(void *) noexcept { return {}; }
13 };
14 template <>
15 struct coroutine_handle<void> {
16   static coroutine_handle from_address(void *) { return {}; }
17   coroutine_handle() = default;
18   template <class PromiseType>
19   coroutine_handle(coroutine_handle<PromiseType>) noexcept {}
20 };
21 } // namespace std::experimental
22 
23 struct suspend_always {
24   bool await_ready() noexcept;
25   void await_suspend(std::experimental::coroutine_handle<>) noexcept;
26   void await_resume() noexcept;
27 };
28 
29 template <>
30 struct std::experimental::coroutine_traits<int, int> {
31   struct promise_type {
32     int get_return_object();
33     suspend_always initial_suspend();
34     suspend_always final_suspend() noexcept;
35     void return_value(int);
36   };
37 };
38 
39 // CHECK-LABEL: _Z2f1i:
40 int f1(int x) {       // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE+7]]:2 = #0
41   if (x > 42) {       // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = #0
42     ++x;              // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:14 -> [[@LINE-1]]:15 = #1
43   } else {            // CHECK-NEXT: File 0, [[@LINE-2]]:15 -> [[@LINE]]:4 = #1
44     co_return x + 42; // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE-1]]:10 = (#0 - #1)
45   }                   // CHECK-NEXT: File 0, [[@LINE-2]]:10 -> [[@LINE]]:4 = (#0 - #1)
46   co_return x;        // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE]]:3 = #1
47 } // CHECK-NEXT: File 0, [[@LINE-1]]:3 -> [[@LINE]]:2 = #1
48