xref: /llvm-project/clang/test/CodeGenCoroutines/coro-dwarf.cpp (revision 3ceacd8b9567a25308f7aaa73d266ee3b4c6ab5f)
1 // RUN: %clang_cc1 -disable-llvm-optzns -std=c++20 \
2 // RUN:            -triple=x86_64 -dwarf-version=4 -debug-info-kind=limited \
3 // RUN:            -emit-llvm -o - %s | \
4 // RUN:            FileCheck %s --implicit-check-not=DILocalVariable
5 
6 namespace std {
7 template <typename... T> struct coroutine_traits;
8 
9 template <class Promise = void> struct coroutine_handle {
10   coroutine_handle() = default;
11   static coroutine_handle from_address(void *) noexcept;
12 };
13 template <> struct coroutine_handle<void> {
14   static coroutine_handle from_address(void *) noexcept;
15   coroutine_handle() = default;
16   template <class PromiseType>
17   coroutine_handle(coroutine_handle<PromiseType>) noexcept;
18 };
19 } // namespace std
20 
21 struct suspend_always {
22   bool await_ready() noexcept;
23   void await_suspend(std::coroutine_handle<>) noexcept;
24   void await_resume() noexcept;
25 };
26 
27 template <typename... Args> struct std::coroutine_traits<void, Args...> {
28   struct promise_type {
29     void get_return_object() noexcept;
30     suspend_always initial_suspend() noexcept;
31     suspend_always final_suspend() noexcept;
32     void return_void() noexcept;
33     promise_type();
34     ~promise_type() noexcept;
35     void unhandled_exception() noexcept;
36   };
37 };
38 
39 // TODO: Not supported yet
40 struct CopyOnly {
41   int val;
42   CopyOnly(const CopyOnly &) noexcept;
43   CopyOnly(CopyOnly &&) = delete;
44   ~CopyOnly();
45 };
46 
47 struct MoveOnly {
48   int val;
49   MoveOnly(const MoveOnly &) = delete;
50   MoveOnly(MoveOnly &&) noexcept;
51   ~MoveOnly();
52 };
53 
54 struct MoveAndCopy {
55   int val;
56   MoveAndCopy(const MoveAndCopy &) noexcept;
57   MoveAndCopy(MoveAndCopy &&) noexcept;
58   ~MoveAndCopy();
59 };
60 
61 void consume(int, int, int) noexcept;
62 
f_coro(int val,MoveOnly moParam,MoveAndCopy mcParam)63 void f_coro(int val, MoveOnly moParam, MoveAndCopy mcParam) {
64   consume(val, moParam.val, mcParam.val);
65   co_return;
66 }
67 
68 // CHECK: ![[SP:[0-9]+]] = distinct !DISubprogram(name: "f_coro", linkageName: "_Z6f_coroi8MoveOnly11MoveAndCopy"
69 // CHECK: !{{[0-9]+}} = !DILocalVariable(name: "val", arg: 1, scope: ![[SP]], file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
70 // CHECK: !{{[0-9]+}} = !DILocalVariable(name: "moParam", arg: 2, scope: ![[SP]], file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
71 // CHECK: !{{[0-9]+}} = !DILocalVariable(name: "mcParam", arg: 3, scope: ![[SP]], file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
72 // CHECK: !{{[0-9]+}} = !DILocalVariable(name: "__promise",
73 
74 // CHECK: ![[INIT:[0-9]+]] = distinct !DISubprogram(linkageName: "_Z6f_coroi8MoveOnly11MoveAndCopy.__await_suspend_wrapper__init"
75 // CHECK: !{{[0-9]+}} = !DILocalVariable(arg: 1, scope: ![[INIT]]
76 // CHECK: !{{[0-9]+}} = !DILocalVariable(arg: 2, scope: ![[INIT]]
77 
78 // CHECK: ![[FINAL:[0-9]+]] = distinct !DISubprogram(linkageName: "_Z6f_coroi8MoveOnly11MoveAndCopy.__await_suspend_wrapper__final"
79 // CHECK: !{{[0-9]+}} = !DILocalVariable(arg: 1, scope: ![[FINAL]]
80 // CHECK: !{{[0-9]+}} = !DILocalVariable(arg: 2, scope: ![[FINAL]]
81