llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang++] Crash Report

Open ConnectionFailedd opened this issue 6 months ago • 3 comments

I was trying to compile my decorator.cpp when clang++ crashed.

$ clang++ -std=c++23 ./decorator.cpp                                       
clang++: error: unable to execute command: Illegal instruction: 4
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Homebrew clang version 22.1.1
Target: arm64-apple-darwin25.3.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/22.1.1/bin
Configuration file: /opt/homebrew/etc/clang/arm64-apple-darwin25.cfg
clang++: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /var/folders/rr/3_9jzgyd7vv9p2q_1ckmy7jw0000gn/T/decorator-26abb7.cpp
clang++: note: diagnostic msg: /var/folders/rr/3_9jzgyd7vv9p2q_1ckmy7jw0000gn/T/decorator-26abb7.sh
clang++: note: diagnostic msg: Crash backtrace is located in
clang++: note: diagnostic msg: /Users/*******/Library/Logs/DiagnosticReports/clang-22_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
clang++: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang++: note: diagnostic msg: 

********************

The source file content is shown below. Lines start with // ! is where caused this crash (I think).

// assume some callable f
// we want to add logic to f in a Python scheme `@decorator`
// `auto decorated = Decorated<decorator>(f)` or `decorator(f)`

// a decorator that time decorated function
#include <chrono>
#include <concepts>
#include <print>
#include <type_traits>
#include <utility>

auto timed = [](auto && f) {
// !        v Here, if rename captured variable `f` to any other name, the crash will not happen
    return [f = std::forward<decltype(f)>(f)]<typename... Args>(
               Args &&... args) -> std::invoke_result_t<decltype(f), Args &&...>
           requires std::invocable<decltype(f), Args &&...>
    {
        if constexpr (std::is_void_v<std::invoke_result_t<decltype(f), Args &&...>>) {
            auto start = std::chrono::steady_clock::now();
            std::invoke(f, std::forward<Args>(args)...);
            auto end = std::chrono::steady_clock::now();
            std::println(stdout, "runtime: {}", end - start);
            return;
        }
        else {
            auto start = std::chrono::steady_clock::now();
            decltype(auto) ret = std::invoke(f, std::forward<Args>(args)...);
            auto end = std::chrono::steady_clock::now();
            std::println(stdout, "runtime: {}", end - start);
            return ret;
        }
    };
};

using namespace std::chrono_literals;

class Foo {
public:
    void test() const & { std::println(stdout, "call void Foo::test() const &;"); }
    void test() & { std::println(stdout, "call void Foo::test() &;"); }
    void test() && { std::println(stdout, "call void Foo::test() &&;"); }
};

// void f(Foo bar) { bar.test(); }
// void f(const Foo & bar) { bar.test(); }
// void f(Foo && bar) { std::move(bar).test(); }
void f(Foo bar) { bar.test(); }

int main() {
    const Foo bar1;
    Foo bar2;
    auto timed_f = timed(f);
    timed_f(bar1);
    timed_f(bar2);
    timed_f(Foo{});
// !             v However this is OK
    auto ff = [bar2 = std::forward<Foo>(bar2)] (){};
}

Required files are attached except /Users/*******/Library/Logs/DiagnosticReports/clang-22_<YYYY-MM-DD-HHMMSS>_<hostname>.crash not found. In the folder I find clang-22-2026-05-16-231352.ips and no *.crash file. Since the .ips is not supported by GitHub file uploading, it is renamed as .txt and uploaded.

decorator-3c6a2a.cpp decorator-3c6a2a.sh clang-22-2026-05-16-231352.txt

ConnectionFailedd avatar May 16 '26 15:05 ConnectionFailedd

Looks like #194068 fixed this. Could you try the latest trunk?

eiytoq avatar May 16 '26 21:05 eiytoq

Oh, the armv8-a clang (trunk) in Compiler Explorer can compile. Sorry for not trying before creating issue. 😭😭

ConnectionFailedd avatar May 18 '26 01:05 ConnectionFailedd

@llvm/issue-subscribers-clang-frontend

Author: NYA (ConnectionFailedd)

I was trying to compile my decorator.cpp when clang++ crashed.
$ clang++ -std=c++23 ./decorator.cpp                                       
clang++: error: unable to execute command: Illegal instruction: 4
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Homebrew clang version 22.1.1
Target: arm64-apple-darwin25.3.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/22.1.1/bin
Configuration file: /opt/homebrew/etc/clang/arm64-apple-darwin25.cfg
clang++: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /var/folders/rr/3_9jzgyd7vv9p2q_1ckmy7jw0000gn/T/decorator-26abb7.cpp
clang++: note: diagnostic msg: /var/folders/rr/3_9jzgyd7vv9p2q_1ckmy7jw0000gn/T/decorator-26abb7.sh
clang++: note: diagnostic msg: Crash backtrace is located in
clang++: note: diagnostic msg: /Users/*******/Library/Logs/DiagnosticReports/clang-22_&lt;YYYY-MM-DD-HHMMSS&gt;_&lt;hostname&gt;.crash
clang++: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang++: note: diagnostic msg: 

********************

The source file content is shown below. Lines start with // ! is where caused this crash (I think).

// assume some callable f
// we want to add logic to f in a Python scheme `@<!-- -->decorator`
// `auto decorated = Decorated&lt;decorator&gt;(f)` or `decorator(f)`

// a decorator that time decorated function
#include &lt;chrono&gt;
#include &lt;concepts&gt;
#include &lt;print&gt;
#include &lt;type_traits&gt;
#include &lt;utility&gt;

auto timed = [](auto &amp;&amp; f) {
// !        v Here, if rename captured variable `f` to any other name, the crash will not happen
    return [f = std::forward&lt;decltype(f)&gt;(f)]&lt;typename... Args&gt;(
               Args &amp;&amp;... args) -&gt; std::invoke_result_t&lt;decltype(f), Args &amp;&amp;...&gt;
           requires std::invocable&lt;decltype(f), Args &amp;&amp;...&gt;
    {
        if constexpr (std::is_void_v&lt;std::invoke_result_t&lt;decltype(f), Args &amp;&amp;...&gt;&gt;) {
            auto start = std::chrono::steady_clock::now();
            std::invoke(f, std::forward&lt;Args&gt;(args)...);
            auto end = std::chrono::steady_clock::now();
            std::println(stdout, "runtime: {}", end - start);
            return;
        }
        else {
            auto start = std::chrono::steady_clock::now();
            decltype(auto) ret = std::invoke(f, std::forward&lt;Args&gt;(args)...);
            auto end = std::chrono::steady_clock::now();
            std::println(stdout, "runtime: {}", end - start);
            return ret;
        }
    };
};

using namespace std::chrono_literals;

class Foo {
public:
    void test() const &amp; { std::println(stdout, "call void Foo::test() const &amp;;"); }
    void test() &amp; { std::println(stdout, "call void Foo::test() &amp;;"); }
    void test() &amp;&amp; { std::println(stdout, "call void Foo::test() &amp;&amp;;"); }
};

// void f(Foo bar) { bar.test(); }
// void f(const Foo &amp; bar) { bar.test(); }
// void f(Foo &amp;&amp; bar) { std::move(bar).test(); }
void f(Foo bar) { bar.test(); }

int main() {
    const Foo bar1;
    Foo bar2;
    auto timed_f = timed(f);
    timed_f(bar1);
    timed_f(bar2);
    timed_f(Foo{});
// !             v However this is OK
    auto ff = [bar2 = std::forward&lt;Foo&gt;(bar2)] (){};
}

Required files are attached except /Users/*******/Library/Logs/DiagnosticReports/clang-22_&lt;YYYY-MM-DD-HHMMSS&gt;_&lt;hostname&gt;.crash not found. In the folder I find clang-22-2026-05-16-231352.ips and no *.crash file. Since the .ips is not supported by GitHub file uploading, it is renamed as .txt and uploaded.

decorator-3c6a2a.cpp decorator-3c6a2a.sh clang-22-2026-05-16-231352.txt