Skip to content

[lldb] Gracefully down TestCoroutineHandle test in case the 'coroutine' feature is missing #94903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
CXX_SOURCES := main.cpp
CFLAGS_EXTRAS := -std=c++20

ifeq "1" "$(USE_LIBSTDCPP)"
CFLAGS_EXTRAS += -DUSE_LIBSTDCPP
endif

ifeq "1" "$(USE_LIBCPP)"
CFLAGS_EXTRAS += -DUSE_LIBCPP
endif

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#if defined(USE_LIBSTDCPP)
#include <bits/c++config.h>
// glibc++ >= 11 and c++20
#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 11
#include <coroutine>
#define HAS_CPP_COROUTINES 1
#endif
#endif

// libc++ always has 'coroutine' feature.
#if defined(USE_LIBCPP)
#include <coroutine>
#define HAS_CPP_COROUTINES 1
#endif

bool is_implementation_supported() {
#ifdef _GLIBCXX_RELEASE
return _GLIBCXX_RELEASE >= 11;
#else
#ifdef HAS_CPP_COROUTINES
return true;
#else
return false;
#endif
}

#ifdef HAS_CPP_COROUTINES
// `int_generator` is a stripped down, minimal coroutine generator
// type.
struct int_generator {
Expand Down Expand Up @@ -39,13 +53,20 @@ int_generator my_generator_func() { co_yield 42; }
// a place to reliably set a breakpoint on.
void empty_function_so_we_can_set_a_breakpoint() {}

#endif // HAS_CPP_COROUTINES

int main() {
bool is_supported = is_implementation_supported();
#ifdef HAS_CPP_COROUTINES
int_generator gen = my_generator_func();
std::coroutine_handle<> type_erased_hdl = gen.hdl;
std::coroutine_handle<int> incorrectly_typed_hdl =
std::coroutine_handle<int>::from_address(gen.hdl.address());
gen.hdl.resume(); // Break at initial_suspend
gen.hdl.resume(); // Break after co_yield
empty_function_so_we_can_set_a_breakpoint(); // Break at final_suspend
return 0;
#else
return 0; // Break at initial_suspend
#endif // HAS_CPP_COROUTINES
}
Loading