Summary: Now in libcxx and clang, all the coroutine components are defined in std::experimental namespace. And now the coroutine TS is merged into C++20. So in the working draft like N4892, we could find the coroutine components is defined in std namespace instead of std::experimental namespace. And the coroutine support in clang seems to be relatively stable. So I think it may be suitable to move the coroutine component into the experiment namespace now. But move the coroutine component into the std namespace may be an break change. So I planned to split this change into two patch. One in clang and other in libcxx. This patch would make clang lookup coroutine_traits in std namespace first. For the compatibility consideration, clang would lookup in std::experimental namespace if it can't find definitions in std namespace and emit a warning in this case. So the existing codes wouldn't be break after update compiler. Test Plan: check-clang, check-libcxx Reviewed By: lxfind Differential Revision: https://reviews.llvm.org/D108696
51 lines
1.9 KiB
C++
51 lines
1.9 KiB
C++
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fcoroutines-ts \
|
|
// RUN: -fexperimental-new-pass-manager -O0 %s -o - | FileCheck %s
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fcoroutines-ts \
|
|
// RUN: -fexperimental-new-pass-manager -fno-inline -O0 %s -o - | FileCheck %s
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fcoroutines-ts \
|
|
// RUN: -O0 %s -o - | FileCheck %s
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fcoroutines-ts \
|
|
// RUN: -fno-inline -O0 %s -o - | FileCheck %s
|
|
|
|
namespace std {
|
|
|
|
struct handle {};
|
|
|
|
struct awaitable {
|
|
bool await_ready() noexcept { return true; }
|
|
// CHECK-NOT: await_suspend
|
|
inline void __attribute__((__always_inline__)) await_suspend(handle) noexcept {}
|
|
bool await_resume() noexcept { return true; }
|
|
};
|
|
|
|
template <typename T>
|
|
struct coroutine_handle {
|
|
static handle from_address(void *address) noexcept { return {}; }
|
|
};
|
|
|
|
template <typename T = void>
|
|
struct coroutine_traits {
|
|
struct promise_type {
|
|
awaitable initial_suspend() { return {}; }
|
|
awaitable final_suspend() noexcept { return {}; }
|
|
void return_void() {}
|
|
T get_return_object() { return T(); }
|
|
void unhandled_exception() {}
|
|
};
|
|
};
|
|
} // namespace std
|
|
|
|
// CHECK-LABEL: @_Z3foov
|
|
// CHECK-LABEL: entry:
|
|
// CHECK: [[CAST0:%[0-9]+]] = bitcast %"struct.std::awaitable"* %ref.tmp{{.*}} to i8*
|
|
// CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* [[CAST0]])
|
|
// CHECK: [[CAST1:%[0-9]+]] = bitcast %"struct.std::awaitable"* %ref.tmp{{.*}} to i8*
|
|
// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* [[CAST1]])
|
|
|
|
// CHECK: [[CAST2:%[0-9]+]] = bitcast %"struct.std::awaitable"* %ref.tmp{{.*}} to i8*
|
|
// CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* [[CAST2]])
|
|
// CHECK: [[CAST3:%[0-9]+]] = bitcast %"struct.std::awaitable"* %ref.tmp{{.*}} to i8*
|
|
// CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* [[CAST3]])
|
|
void foo() { co_return; }
|