1 // Verify that we synthesized the coroutine for a lambda inside of a function template. 2 // RUN: %clang_cc1 -std=c++1z -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s 3 4 namespace std::experimental { 5 template <typename R, typename... T> struct coroutine_traits { 6 using promise_type = typename R::promise_type; 7 }; 8 9 template <class Promise = void> struct coroutine_handle; 10 template <> struct coroutine_handle<void> { 11 static coroutine_handle from_address(void *) noexcept; 12 coroutine_handle() = default; 13 template <class PromiseType> 14 coroutine_handle(coroutine_handle<PromiseType>) noexcept; 15 }; 16 template <class Promise> struct coroutine_handle : coroutine_handle<void> { 17 coroutine_handle() = default; 18 static coroutine_handle from_address(void *) noexcept; 19 }; 20 } 21 22 struct suspend_always { 23 bool await_ready() noexcept; 24 void await_suspend(std::experimental::coroutine_handle<>) noexcept; 25 void await_resume() noexcept; 26 }; 27 28 struct Task { 29 struct promise_type { 30 Task get_return_object(); return_voidTask::promise_type31 void return_void() {} 32 suspend_always initial_suspend() noexcept; 33 suspend_always final_suspend() noexcept; 34 void unhandled_exception() noexcept; 35 }; 36 }; 37 SyncAwait(_AwrT && A)38template <typename _AwrT> auto SyncAwait(_AwrT &&A) { 39 if (!A.await_ready()) { 40 auto AwaitAsync = [&]() -> Task { 41 try { (void)(co_await A); } catch (...) {} 42 }; 43 Task t = AwaitAsync(); 44 } 45 return A.await_resume(); 46 } 47 f()48void f() { 49 suspend_always test; 50 SyncAwait(test); 51 } 52 53 // Verify that we synthesized the coroutine for a lambda inside SyncAwait 54 // CHECK-LABEL: define linkonce_odr void @_ZZ9SyncAwaitIR14suspend_alwaysEDaOT_ENKUlvE_clEv( 55 // CHECK: alloca %"struct.Task::promise_type" 56 // CHECK: call token @llvm.coro.id( 57 // CHECK: call i8 @llvm.coro.suspend( 58 // CHECK: call i1 @llvm.coro.end( 59