llvm-project/clang/test/SemaCXX/thread-safety-coro.cpp
Nathan Sidwell 65b34b78f8 [clang][pr55896]:co_yield/co_await thread-safety
co_await and co_yield are represented by (classes derived from)
CoroutineSuspendExpr.  That has a number of child nodes, not all of
which are used for code-generation.  In particular the operand is
represented multiple times, and, like the problem with co_return
(55406) it must only be emitted in the CFG exactly once.  The operand
also appears inside OpaqueValueExprs, but that's ok.

This adds a visitor for SuspendExprs to emit the required children in
the correct order.  Note that this CFG is pre-coro xform.  We don't
have initial or final suspend points.

Reviewed By: bruno

Differential Revision: https://reviews.llvm.org/D127236
2022-06-09 04:42:10 -07:00

52 lines
1.2 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++17 -fcoroutines-ts %s
// expected-no-diagnostics
namespace std {
template <typename _Result, typename...>
struct coroutine_traits {
using promise_type = typename _Result::promise_type;
};
template <typename _Promise = void>
struct coroutine_handle;
template <>
struct coroutine_handle<void> {
static coroutine_handle from_address(void *__a) noexcept;
void resume() const noexcept;
void destroy() const noexcept;
};
template <typename _Promise>
struct coroutine_handle : coroutine_handle<> {};
struct suspend_always {
bool await_ready() const noexcept;
void await_suspend(coroutine_handle<>) const noexcept;
void await_resume() const noexcept;
};
} // namespace std
class Task {
public:
struct promise_type {
public:
std::suspend_always initial_suspend() noexcept;
std::suspend_always final_suspend() noexcept;
Task get_return_object() noexcept;
void unhandled_exception() noexcept;
void return_value(int value) noexcept;
std::suspend_always yield_value(int value) noexcept;
};
};
Task Foo() noexcept {
// ICE'd
co_yield({ int frame = 0; 0; });
co_await({ int frame = 0; std::suspend_always(); });
co_return({ int frame = 0; 0; });
}