Bug 105574 - coroutines: ICE when co_yield a r-value vector of non-POD type
Summary: coroutines: ICE when co_yield a r-value vector of non-POD type
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: C++-coroutines
Depends on:
Blocks:
 
Reported: 2022-05-12 00:19 UTC by Ruihan Wang
Modified: 2023-10-01 21:08 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 12.1.0, 13.0
Known to fail:
Last reconfirmed: 2022-05-12 00:00:00


Attachments
Preprocessed source file (163.59 KB, text/plain)
2022-05-12 00:24 UTC, Ruihan Wang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ruihan Wang 2022-05-12 00:19:43 UTC
* System Info
Distributor ID:	Ubuntu
Description:	Ubuntu 21.10
Release:	21.10
Codename:	impish

* GCC Version
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-7ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2)

* Build Command
g++ -std=c++20 -fcoroutines -save-temps ../src/bug.cpp

* Description
The following code snippet (bug.cpp) will trigger an internal compiler error:

#include <coroutine>
#include <exception>
#include <iterator>
#include <iostream>
#include <optional>
#include <vector>

template<std::movable T>
class generator {
public:
    struct promise_type {
        generator<T> get_return_object() {
            return generator{Handle::from_promise(*this)};
        }
        static std::suspend_always initial_suspend() noexcept {
            return {}; 
        }
        static std::suspend_always final_suspend() noexcept { 
            return {}; 
        }
        std::suspend_always yield_value(T value) noexcept {
            current_value = std::move(value);
            return {};
        }
        // Disallow co_await in generator coroutines.
        void await_transform() = delete;
        [[noreturn]]
        static void unhandled_exception() {
            throw;
        }
 
        std::optional<T> current_value;
    };
 
    using Handle = std::coroutine_handle<promise_type>;
 
    explicit generator(const Handle coroutine) : 
        m_coroutine{coroutine}
    {}
 
    generator() = default;
    ~generator() { 
        if (m_coroutine) {
            m_coroutine.destroy(); 
        }
    }
 
    generator(const generator&) = delete;
    generator& operator=(const generator&) = delete;
 
    generator(generator&& other) noexcept : 
        m_coroutine{other.m_coroutine}
    { 
        other.m_coroutine = {}; 
    }
    generator& operator=(generator&& other) noexcept {
        if (this != &other) {
            if (m_coroutine) {
                m_coroutine.destroy();
            }
            m_coroutine = other.m_coroutine;
            other.m_coroutine = {};
        }
        return *this;
    }
 
private:
    Handle m_coroutine;
};

struct Foo {
    Foo() { }
};

generator<std::vector<Foo>> bug() {
    /* This one compiled fine */
    // auto v = std::vector<Foo>{ Foo() };
    // co_yield v;

    /* This one hit internal compiler error */
    co_yield std::vector<Foo>{ Foo() };
}

int main() {
    bug();
    return 0;
}


The error message is the following:

../src/bug.cpp: In function ‘generator<std::vector<Foo> > bug()’:
../src/bug.cpp:82:1: internal compiler error: in build_special_member_call, at cp/call.c:10188
   82 | }
      | ^
0x7d7a1e build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, int)
	../../src/gcc/cp/call.c:10188
0x9c3758 flatten_await_stmt
	../../src/gcc/cp/coroutines.cc:3023
0x9c38b0 flatten_await_stmt
	../../src/gcc/cp/coroutines.cc:3055
0x9c38b0 flatten_await_stmt
	../../src/gcc/cp/coroutines.cc:3055
0x9c38b0 flatten_await_stmt
	../../src/gcc/cp/coroutines.cc:3055
0x9c756e maybe_promote_temps
	../../src/gcc/cp/coroutines.cc:3241
0x9c756e await_statement_walker
	../../src/gcc/cp/coroutines.cc:3879
0xf49a8a walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
	../../src/gcc/tree.c:12108
0x9c6d93 await_statement_walker
	../../src/gcc/cp/coroutines.cc:3557
0xf49a8a walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
	../../src/gcc/tree.c:12108
0xf49c21 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
	../../src/gcc/tree.c:12456
0x9c6d93 await_statement_walker
	../../src/gcc/cp/coroutines.cc:3557
0xf49a8a walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
	../../src/gcc/tree.c:12108
0x9c6d49 await_statement_walker
	../../src/gcc/cp/coroutines.cc:3545
0xf49a8a walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
	../../src/gcc/tree.c:12108
0x9e60b5 morph_fn_to_coro(tree_node*, tree_node**, tree_node**)
	../../src/gcc/cp/coroutines.cc:4547
0x6b9a6d finish_function(bool)
	../../src/gcc/cp/decl.c:17326
0xff88d6 cp_parser_function_definition_after_declarator
	../../src/gcc/cp/parser.c:30093
0xfa785e cp_parser_function_definition_from_specifiers_and_declarator
	../../src/gcc/cp/parser.c:30006
0xfa785e cp_parser_init_declarator
	../../src/gcc/cp/parser.c:21667
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.
Comment 1 Ruihan Wang 2022-05-12 00:24:31 UTC
Created attachment 52958 [details]
Preprocessed source file
Comment 2 Martin Liška 2022-05-12 08:45:14 UTC
Fixed with r12-618-g14ed21f8749ae359.
Comment 3 Andrew Pinski 2023-08-05 16:42:31 UTC
*** Bug 110913 has been marked as a duplicate of this bug. ***