1 // Tests that the combination of -fcoro-aligned-allocation and -fsized-deallocation works well.
2 // Test the compiler will chose sized deallocation correctly.
3 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
4 // RUN: -fcoro-aligned-allocation -emit-llvm %s -o - -disable-llvm-passes \
7 #include "Inputs/coroutine.h"
10 typedef __SIZE_TYPE__
size_t;
11 enum class align_val_t
: size_t {};
16 auto initial_suspend() { return std::suspend_always
{}; }
17 auto final_suspend() noexcept
{ return std::suspend_always
{}; }
18 auto get_return_object() { return task
{}; }
19 void unhandled_exception() {}
20 void return_value(int) {}
24 // CHECK: define{{.*}}@_Z1fv
26 // CHECK: %[[coro_size:.+]] = call{{.*}}@llvm.coro.size
27 // CHECK: %[[coro_align:.+]] = call{{.*}}@llvm.coro.align
28 // CHECK: call{{.*}}void @_ZdlPvmSt11align_val_t(ptr{{.*}}, i64{{.*}}%[[coro_size]], i64{{.*}}%[[coro_align]])
36 auto initial_suspend() { return std::suspend_always
{}; }
37 auto final_suspend() noexcept
{ return std::suspend_always
{}; }
38 auto get_return_object() { return task2
{}; }
39 void unhandled_exception() {}
40 void return_value(int) {}
41 void operator delete(void *ptr
);
45 // CHECK: define{{.*}}@_Z2f2v
46 // CHECK: %[[FREE_HANDLE:.+]] = call{{.*}}ptr @llvm.coro.free(
48 // CHECK: call{{.*}}void @_ZN5task212promise_typedlEPv(ptr{{.*}} %[[FREE_HANDLE]])
56 auto initial_suspend() { return std::suspend_always
{}; }
57 auto final_suspend() noexcept
{ return std::suspend_always
{}; }
58 auto get_return_object() { return task3
{}; }
59 void unhandled_exception() {}
60 void return_value(int) {}
61 void operator delete(void *ptr
, std::size_t);
62 void operator delete(void *ptr
);
66 // CHECK: define{{.*}}@_Z2f3v
67 // CHECK: %[[FREE_HANDLE:.+]] = call{{.*}}ptr @llvm.coro.free(
69 // CHECK: %[[coro_size:.+]] = call{{.*}}@llvm.coro.size
70 // CHECK: call{{.*}}void @_ZN5task312promise_typedlEPvm(ptr{{.*}} %[[FREE_HANDLE]], i64{{.*}}%[[coro_size]]
78 auto initial_suspend() { return std::suspend_always
{}; }
79 auto final_suspend() noexcept
{ return std::suspend_always
{}; }
80 auto get_return_object() { return task4
{}; }
81 void unhandled_exception() {}
82 void return_value(int) {}
83 void operator delete(void *ptr
, std::size_t);
84 void operator delete(void *ptr
, std::align_val_t
);
85 void operator delete(void *ptr
);
89 // CHECK: define{{.*}}@_Z2f4v
90 // CHECK: %[[FREE_HANDLE:.+]] = call{{.*}}ptr @llvm.coro.free(
92 // CHECK: %[[coro_align:.+]] = call{{.*}}@llvm.coro.align
93 // CHECK: call{{.*}}void @_ZN5task412promise_typedlEPvSt11align_val_t(ptr{{.*}} %[[FREE_HANDLE]], i64{{.*}}%[[coro_align]])
100 struct promise_type
{
101 auto initial_suspend() { return std::suspend_always
{}; }
102 auto final_suspend() noexcept
{ return std::suspend_always
{}; }
103 auto get_return_object() { return task5
{}; }
104 void unhandled_exception() {}
105 void return_value(int) {}
106 void operator delete(void *ptr
, std::size_t);
107 void operator delete(void *ptr
, std::size_t, std::align_val_t
);
108 void operator delete(void *ptr
);
112 // CHECK: define{{.*}}@_Z2f5v
113 // CHECK: %[[FREE_HANDLE:.+]] = call{{.*}}ptr @llvm.coro.free(
115 // CHECK: %[[coro_size:.+]] = call{{.*}}@llvm.coro.size
116 // CHECK: %[[coro_align:.+]] = call{{.*}}@llvm.coro.align
117 // CHECK: call{{.*}}void @_ZN5task512promise_typedlEPvmSt11align_val_t(ptr{{.*}} %[[FREE_HANDLE]], i64{{.*}}%[[coro_size]], i64{{.*}}%[[coro_align]])