[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / CodeGenCoroutines / coro-gro2-exp-namespace.cpp
blob5b73ec083ff73ac51eaac9ed434dd082e5dbaafb
1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s
3 #include "Inputs/coroutine-exp-namespace.h"
5 using namespace std::experimental;
7 namespace std {
9 struct nothrow_t {};
10 constexpr nothrow_t nothrow = {};
12 } // end namespace std
14 // Required when get_return_object_on_allocation_failure() is defined by
15 // the promise.
16 void *operator new(__SIZE_TYPE__ __sz, const std::nothrow_t &) noexcept;
17 void operator delete(void *__p, const std::nothrow_t &)noexcept;
19 template <class RetObject>
20 struct promise_type {
21 RetObject get_return_object();
22 suspend_always initial_suspend();
23 suspend_never final_suspend() noexcept;
24 void return_void();
25 static void unhandled_exception();
28 struct coro {
29 using promise_type = promise_type<coro>;
30 coro(coro const &);
31 struct Impl;
32 Impl *impl;
35 // Verify that the RVO is applied.
36 // CHECK-LABEL: define{{.*}} void @_Z1fi(%struct.coro* noalias sret(%struct.coro) align 8 %agg.result, i32 noundef %0)
37 coro f(int) {
38 // CHECK: %call = call noalias noundef nonnull i8* @_Znwm(
39 // CHECK-NEXT: br label %[[CoroInit:.*]]
41 // CHECK: {{.*}}[[CoroInit]]:
42 // CHECK: call void @{{.*get_return_objectEv}}(%struct.coro* sret(%struct.coro) align 8 %agg.result
43 co_return;
46 template <class RetObject>
47 struct promise_type_with_on_alloc_failure {
48 static RetObject get_return_object_on_allocation_failure();
49 RetObject get_return_object();
50 suspend_always initial_suspend();
51 suspend_never final_suspend() noexcept;
52 void return_void();
53 static void unhandled_exception();
56 struct coro_two {
57 using promise_type = promise_type_with_on_alloc_failure<coro_two>;
58 coro_two(coro_two const &);
59 struct Impl;
60 Impl *impl;
63 // Verify that the NRVO is applied to the Gro object.
64 // CHECK-LABEL: define{{.*}} void @_Z1hi(%struct.coro_two* noalias sret(%struct.coro_two) align 8 %agg.result, i32 noundef %0)
65 coro_two h(int) {
67 // CHECK: %call = call noalias noundef i8* @_ZnwmRKSt9nothrow_t
68 // CHECK-NEXT: %[[CheckNull:.*]] = icmp ne i8* %call, null
69 // CHECK-NEXT: br i1 %[[CheckNull]], label %[[InitOnSuccess:.*]], label %[[InitOnFailure:.*]]
71 // CHECK: {{.*}}[[InitOnFailure]]:
72 // CHECK-NEXT: call void @{{.*get_return_object_on_allocation_failureEv}}(%struct.coro_two* sret(%struct.coro_two) align 8 %agg.result
73 // CHECK-NEXT: br label %[[RetLabel:.*]]
75 // CHECK: {{.*}}[[InitOnSuccess]]:
76 // CHECK: call void @{{.*get_return_objectEv}}(%struct.coro_two* sret(%struct.coro_two) align 8 %agg.result
78 // CHECK: [[RetLabel]]:
79 // CHECK-NEXT: ret void
80 co_return;