Skip to content

Commit 23b8f59

Browse files
authored
[lldb] Gracefully down TestCoroutineHandle test in case the 'coroutine' feature is missing (#94903)
Do not let the compiler gets failed in case the target platform does not support the 'coroutine' C++ features. Just compile without it and let lldb know about missed/unsupported feature.
1 parent a0faf79 commit 23b8f59

File tree

2 files changed

+32
-3
lines changed
  • lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle

2 files changed

+32
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
CXX_SOURCES := main.cpp
22
CFLAGS_EXTRAS := -std=c++20
33

4+
ifeq "1" "$(USE_LIBSTDCPP)"
5+
CFLAGS_EXTRAS += -DUSE_LIBSTDCPP
6+
endif
7+
8+
ifeq "1" "$(USE_LIBCPP)"
9+
CFLAGS_EXTRAS += -DUSE_LIBCPP
10+
endif
11+
412
include Makefile.rules

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1+
#if defined(USE_LIBSTDCPP)
2+
#include <bits/c++config.h>
3+
// glibc++ >= 11 and c++20
4+
#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 11
15
#include <coroutine>
6+
#define HAS_CPP_COROUTINES 1
7+
#endif
8+
#endif
9+
10+
// libc++ always has 'coroutine' feature.
11+
#if defined(USE_LIBCPP)
12+
#include <coroutine>
13+
#define HAS_CPP_COROUTINES 1
14+
#endif
215

316
bool is_implementation_supported() {
4-
#ifdef _GLIBCXX_RELEASE
5-
return _GLIBCXX_RELEASE >= 11;
6-
#else
17+
#ifdef HAS_CPP_COROUTINES
718
return true;
19+
#else
20+
return false;
821
#endif
922
}
1023

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

56+
#endif // HAS_CPP_COROUTINES
57+
4258
int main() {
4359
bool is_supported = is_implementation_supported();
60+
#ifdef HAS_CPP_COROUTINES
4461
int_generator gen = my_generator_func();
4562
std::coroutine_handle<> type_erased_hdl = gen.hdl;
4663
std::coroutine_handle<int> incorrectly_typed_hdl =
4764
std::coroutine_handle<int>::from_address(gen.hdl.address());
4865
gen.hdl.resume(); // Break at initial_suspend
4966
gen.hdl.resume(); // Break after co_yield
5067
empty_function_so_we_can_set_a_breakpoint(); // Break at final_suspend
68+
return 0;
69+
#else
70+
return 0; // Break at initial_suspend
71+
#endif // HAS_CPP_COROUTINES
5172
}

0 commit comments

Comments
 (0)