Алексей Фет
Алексей Фет

Reputation: 51

GCC interrupts compiling with this message "internal compiler error: in instantiate_type" on simple coroutine

I get GCC compiler internal error message when compile my code. But MSVC and Clang compile it fine.

This is reduced to example one simple "yield coroutine". I use x86-64 gcc 13.2 compiler and additional compilers flags is -std=c++20 -O2. The link to "Compiler Explorer"

#include <coroutine>

struct state_seq {
    struct promise_type
    {        
        struct _p_awaiter
        {
            bool await_ready() const { return false; }
            void await_suspend(std::coroutine_handle<> handle) {}
            int await_resume() const { return 42; }
        };

        [[noreturn]]
        static void unhandled_exception() { throw; };

        std::suspend_never initial_suspend() noexcept { return {}; }
        std::suspend_always final_suspend() noexcept { return {};}

        void return_value(int) { }
        _p_awaiter yield_value(int) { return {}; }

        state_seq get_return_object() {
            return state_seq {
                ._handle = std::coroutine_handle<promise_type>::from_promise(*this)
            };
        }
    };
    
    std::coroutine_handle<promise_type> _handle;
};

template<int TUnused = 0>  // If comment this line both cases compiled fine.
state_seq parse() 
{
    auto i = co_yield 5;
    // const auto& r_i = co_yield 45; // OK: This line is compiled.
    i = co_yield 45; // ERROR: internal compiler error: in instantiate_type, at cp/class.cc:8792
    co_return i;
}

void  test() { auto seq = parse(); }

Compiling result:


<source>: In instantiation of 'state_seq parse() [with int TUnused = 0]':
<source>:41:32:   required from here
<source>:37:7: internal compiler error: in instantiate_type, at cp/class.cc:8792
   37 |     i = co_yield 45; // ERROR: internal compiler error: in instantiate_type, at cp/class.cc:8792
      |     ~~^~~~~~~~~~
0x1ce7bde internal_error(char const*, ...)
    ???:0
0x7290fc fancy_abort(char const*, int, char const*)
    ???:0
0x92701d cp_build_modify_expr(unsigned int, tree_node*, tree_code, tree_node*, int)
    ???:0
0x927ae2 build_x_modify_expr(unsigned int, tree_node*, tree_code, tree_node*, tree_node*, int)
    ???:0
0x8beb17 instantiate_decl(tree_node*, bool, bool)
    ???:0
0x8d993b instantiate_pending_templates(int)

If not uses template for function state_seq parse() GCC compile it fine or if result of co_yield are assignmented to const r_ref compile it fine too.

Probably some one meet this problem and knows the sources of this problem. Could you post some link to bug report or article which investigate this problem.

Upvotes: 0

Views: 648

Answers (1)

康桓瑋
康桓瑋

Reputation: 43066

Probably some one meet this problem and knows the sources of this problem. Could you post some link to bug report or article which investigate this problem.

An internal compiler error always indicates a compiler bug regardless of whether the user's code is well-formed, and this has been tracked in PR108620.

Upvotes: 0

Related Questions