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

Segmentation Fault: Stack dump without symbol names #628

Closed
SaeedKeshavarzi opened this issue Apr 7, 2024 · 1 comment
Closed

Segmentation Fault: Stack dump without symbol names #628

SaeedKeshavarzi opened this issue Apr 7, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@SaeedKeshavarzi
Copy link

Here is how you can regenerate the segmentation fault:

first set this flags:

C++ Standard:
  C++ 2c
More Transformations:
  Use libc++
  Show coroutine transformation
  Show C++ to C transformation 

and the code:

#include <iostream>
#include <coroutine>
#include <thread>
#include <queue>
#include <functional>

std::queue<std::function<bool()>> task_queue;

struct sleep {
    sleep(int n) : delay{n} {}

    constexpr bool await_ready() const noexcept { return false; }

    void await_suspend(std::coroutine_handle<> h) const noexcept {
        auto start = std::chrono::steady_clock::now();
        task_queue.push([start, h, d = delay] {
            if (decltype(start)::clock::now() - start > d) {
                h.resume();
                return true;
            } else {
                return false;
            }
        });
    }

    void await_resume() const noexcept {}

    std::chrono::milliseconds delay;
};


struct Task {
    struct promise_type {
        promise_type() = default;
        Task get_return_object() { return {}; }
        std::suspend_never initial_suspend() { return {}; } 
        std::suspend_always final_suspend() noexcept { return {}; }
        void unhandled_exception() {}
    };
};

Task foo() noexcept {
    std::cout << "1. hello from foo1" << std::endl;
    for (int i = 0; i < 10; ++i) {
        co_await sleep{10};
        std::cout << "2. hello from foo1" << std::endl;
    }
}

//call foo
int main() {
    foo();
}

and the error message is:

insights: /usr/lib/llvm-18/include/clang/AST/Type.h:753: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type 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):
Segmentation fault (core dumped)

Thanks for your good project cppInsights

@andreasfertig andreasfertig added the bug Something isn't working label Apr 8, 2024
@andreasfertig
Copy link
Owner

Hello @SaeedKeshavarzi,

thanks for reporting this issue!

I have a fix for the crash. However, please note that the two transformations don't play well together. The reason is the design of the CodeGenerator. The CoroutineCodeGenerator and the CFrontCodeGenerator both derive from CodeGenerator, so parts of the CoroutineCodeGenerator do not properly transform to C code.

Andreas

andreasfertig added a commit that referenced this issue Apr 8, 2024
Fixed #628: Cfront mode and coroutines.
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