[Bug c++/104777] gcc crashes while compiling a custom coroutine library sample since r10-5137-g43aae289866f5ea5
marxin at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 4 15:44:37 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104777
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|gcc crashes while compiling |gcc crashes while compiling
|a custom coroutine library |a custom coroutine library
|sample |sample since
| |r10-5137-g43aae289866f5ea5
CC| |iains at gcc dot gnu.org,
| |mpolacek at gcc dot gnu.org
Keywords|needs-reduction |
--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
Reduced test-case:
$ cat ice.ii
namespace std {
class tuple;
template <typename> auto declval() -> decltype(0);
template <typename> using remove_reference_t = int;
} // namespace std
extern "C" void abort();
namespace std {
template <int, typename _Tp> using tuple_element_t = _Tp;
template <typename _Fn> void __invoke_impl(_Fn __f) { __f(); }
template <typename, typename _Callable> void __invoke_r(_Callable __fn) {
__invoke_impl(__fn);
}
template <typename> class function;
template <typename _Functor> struct _Base_manager {
static _Functor *_M_get_pointer(int) { return 0; }
};
template <typename, typename> class _Function_handler;
template <typename _Res, typename _Functor, typename... _ArgTypes>
struct _Function_handler<_Res(_ArgTypes...), _Functor> {
using _Base = _Base_manager<_Functor>;
static _Res _M_invoke(const int &__functor) {
auto __trans_tmp_1 = _Base::_M_get_pointer(__functor);
__invoke_r<_Res>(*__trans_tmp_1);
return _Res();
}
};
template <typename _Res, typename... _ArgTypes>
struct function<_Res(_ArgTypes...)> {
template <typename _Functor>
using _Handler = _Function_handler<_Res(), _Functor>;
function() {}
template <typename _Functor> function(_Functor) {
using _My_handler = _Handler<_Functor>;
_M_invoker = _My_handler::_M_invoke;
}
using _Invoker_type = _Res (*)(const int &);
_Invoker_type _M_invoker;
};
} // namespace std
bool savestate_r;
int savestate_ssb;
template <typename T> struct list {
using value_type = T;
struct node {
value_type v_;
} * last_;
void emplace_back(auto... a) { last_ = new node(a...); }
};
namespace cr {
namespace detail {
template <long I> using at_t = std::tuple_element_t<I, std::tuple>;
}
struct task {
std::function<void()> f_;
void *r_;
task(auto f) { f_ = f; }
template <typename> auto return_ref() {
return *static_cast<std::remove_reference_t<int> *>(r_);
}
};
struct {
task *pt_;
list<task> l_;
auto previous_task() { return pt_; }
auto run(auto... f) -> decltype(std::declval<detail::at_t<sizeof...(f)>>()) {
(l_.emplace_back(f), ...);
return 0;
}
} thread_local loop;
auto await(auto f) {
using R = decltype(f);
asm("" : "=m"(savestate_ssb), "=r"(savestate_r));
if (savestate_r) {
auto pt(loop.previous_task());
return pt->return_ref<R>();
}
asm("" : : ""(loop));
abort();
}
} // namespace cr
int
main() {
cr::loop.run([] { cr::await([] {}) << cr::await([] {}); });
return 0;
}
Started with -O2 -std=c++2a since r10-5137-g43aae289866f5ea5.
More information about the Gcc-bugs
mailing list