Skip to content
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

CppInsights crash with stack dump #526

Closed
eoan-ermine opened this issue Apr 22, 2023 · 2 comments
Closed

CppInsights crash with stack dump #526

eoan-ermine opened this issue Apr 22, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@eoan-ermine
Copy link

eoan-ermine commented Apr 22, 2023

Code (environment: C++23, show coroutine transformation):

#include <coroutine>
#include <iostream>
#include <exception>

template <typename T, typename U>
struct executable { static U execute() { co_await T{}; } };
struct hello_logic  {
    bool await_ready() const noexcept { return true; }
    void await_suspend(std::coroutine_handle<>) const noexcept { }
    void await_resume() const noexcept { std::cout << "Hello, world" << std::endl; }
};
struct hello_world : executable<hello_logic, hello_world> {
    struct promise_type {
        auto get_return_object() { return hello_world(this); }
        std::suspend_never initial_suspend() noexcept { return {}; }
        std::suspend_never final_suspend() noexcept { return {}; }
        void return_void() { }
        void unhandled_exception() { }
    };
    using coro_handle = std::coroutine_handle<promise_type>;
    hello_world(promise_type* promise) : handle_(coro_handle::from_promise(*promise)) { }
private:
    coro_handle handle_;
};

int main() { hello_world::execute(); }

Console:

insights: /usr/include/llvm-15/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = clang::Expr; From = clang::Stmt]: Assertion `Val && "isa<> used on a null pointer"' failed.
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
[0x1daef61]
[0x1dacc7c]
[0x1daf486]
[0x1ea4460]
[0x1ec41dc]
[0x1ea43e6]
[0x40390a]
[0x403832]
[0x1e9e036]
[0x502110]
[0x4cb2a0]
[0x4ac72c]
[0x496383]
[0x473fed]
[0x4568ed]
[0x42abd6]
[0x42be84]
[0x40e0b7]
[0x4186e2]
[0x40acc9]
[0x5670a5]
[0x40b643]
[0x4122c1]
[0x4123f3]
[0x417e4d]
[0x415df6]
[0x40c7bf]
[0x5aebc3]
[0x60a06c]
[0x63dd0c]
[0x609a9e]
[0x60c6c1]
[0x614f4b]
[0x60c6f9]
[0x5dc401]
[0x58b0ba]
[0xab157b]
[0x6f2ba7]
[0x664ce6]
[0x5cd071]
[0x5ccddf]
[0x5cbd1f]
[0x5ce90e]
[0x5882f9]
[0x1e8bdda]
[0x1e8d637]
[0x406d55]
Aborted (core dumped)
@eoan-ermine
Copy link
Author

eoan-ermine commented Apr 22, 2023

Seems that the root of evil here is CRTP, cause code below compiles without any issues:

#include <coroutine>
#include <iostream>
#include <exception>

struct hello_logic  {
    bool await_ready() const noexcept { return true; }
    void await_suspend(std::coroutine_handle<>) const noexcept { }
    void await_resume() const noexcept { std::cout << "Hello, world" << std::endl; }
};
struct hello_world {
    struct promise_type {
        auto get_return_object() { return hello_world(this); }
        std::suspend_never initial_suspend() noexcept { return {}; }
        std::suspend_never final_suspend() noexcept { return {}; }
        void return_void() { }
        void unhandled_exception() { }
    };
    using coro_handle = std::coroutine_handle<promise_type>;
    hello_world(promise_type* promise) : handle_(coro_handle::from_promise(*promise)) { }
    static hello_world execute() { co_await hello_logic{}; }
private:
    coro_handle handle_;
};

int main() { hello_world::execute(); }

@andreasfertig
Copy link
Owner

Hello @PatriotRossii,

thanks for reporting this! Very interesting test code. Aside from the crash, it also contains a DependentCoawaitExpr, which isn't handled at the moment.

The issue at hand seems to come from the code I create for the coroutine. I need more time to look into this and how to fix it.

Andreas

@andreasfertig andreasfertig added the bug Something isn't working label Apr 27, 2023
andreasfertig added a commit that referenced this issue Jun 27, 2023
Fixed #526: Don't try to expand a primary class template with coroutine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants