1 // RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -triple=x86_64-pc-windows-msvc18.0.0 -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
2 // -triple=x86_64-unknown-linux-gnu
3 
4 #include "Inputs/coroutine.h"
5 
6 namespace coro = std::experimental::coroutines_v1;
7 
8 struct coro_t {
9   void* p;
10   ~coro_t();
11   struct promise_type {
12     coro_t get_return_object();
13     coro::suspend_never initial_suspend();
14     coro::suspend_never final_suspend() noexcept;
15     void return_void();
16     promise_type();
17     ~promise_type();
18     void unhandled_exception();
19   };
20 };
21 
22 struct Cleanup { ~Cleanup(); };
23 void may_throw();
24 
f()25 coro_t f() {
26   Cleanup cleanup;
27   may_throw();
28   co_return;
29 }
30 
31 // CHECK-LABEL: define dso_local void @"?f@@YA?AUcoro_t@@XZ"(
32 // CHECK:  %gro.active = alloca i1
33 // CHECK:  store i1 false, i1* %gro.active
34 
35 // CHECK:  invoke %"struct.coro_t::promise_type"* @"??0promise_type@coro_t@@QEAA@XZ"(
36 // CHECK:  invoke void @"?get_return_object@promise_type@coro_t@@QEAA?AU2@XZ"(
37 // CHECK:  store i1 true, i1* %gro.active
38 
39 // CHECK:  %[[IS_ACTIVE:.+]] = load i1, i1* %gro.active
40 // CHECK:  br i1 %[[IS_ACTIVE]], label %[[CLEANUP1:.+]], label
41 
42 // CHECK: [[CLEANUP1]]:
43 // CHECK:  %[[NRVO:.+]] = load i1, i1* %nrvo
44 // CHECK:  br i1 %[[NRVO]], label %{{.+}}, label %[[DTOR:.+]]
45 
46 // CHECK: [[DTOR]]:
47 // CHECK:  call void @"??1coro_t@@QEAA@XZ"(
48