https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100127
Bug ID: 100127 Summary: [coroutines] internal compiler error compiling promise with custom awaiter Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: riki--b at hotmail dot it Target Milestone: --- Created attachment 50621 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50621&action=edit Preprocessed source The following code (preprocessed source in attachments) does not compile and causes a compiler segfault: ``` #include <coroutine> #include <optional> struct future { using value_type = int; struct promise_type; using handle_type = std::coroutine_handle<promise_type>; handle_type _coroutine; future(handle_type h) : _coroutine{h} {} ~future() noexcept{ if (_coroutine) { _coroutine.destroy(); } } value_type get() { auto ptr = _coroutine.promise()._value; return *ptr; } struct promise_type { std::optional<value_type> _value = std::nullopt; future get_return_object() { return future{handle_type::from_promise(*this)}; } void return_value(value_type val) { _value = static_cast<value_type &&>(val); } auto initial_suspend() noexcept { class awaiter { std::optional<value_type> & value; public: explicit awaiter(std::optional<value_type> & val) noexcept : value{val} {} bool await_ready() noexcept { return value.has_value(); } void await_suspend(handle_type) noexcept { } value_type & await_resume() noexcept { return *value; } }; return awaiter{_value}; } std::suspend_always final_suspend() noexcept { return {}; } void return_void() {} void unhandled_exception() {} }; }; future create_future() { co_return 2021; } int main() { auto f = create_future(); } ``` Returning `std::suspend_never{}` instead of the awaiter compiles correctly. Output of g++ -v -save-temps -std=c++20 -fcoroutines ${source}.cpp: ``` Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --ma ndir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languag es=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl --with-linker-hash-style=gnu --with-system-zlib -- enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pi e --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libibe rty --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-thr eads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_ include_dir=/usr/include/dlang/gdc Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.2.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++2a' '-fcoroutines' '-shared-libgcc' '-mtune=generic' '-m arch=x86-64' /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/cc1plus -E -quiet -v -D_GNU_SOURCE test_bug.cpp -mtune=generic -march=x86-64 -std=c++2a -fcoroutines -fpch-preprocess -o test_bug.ii ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/ include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0 /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/x86_64-pc-linux-gnu /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/backward /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include /usr/local/include /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++2a' '-fcoroutines' '-shared-libgcc' '-mtune=generic' '-m arch=x86-64' /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/cc1plus -fpreprocessed test_bug.ii -quiet -dumpbase test_bug.cp p -mtune=generic -march=x86-64 -auxbase test_bug -std=c++2a -version -fcoroutines -o test_bug.s GNU C++17 (GCC) version 10.2.0 (x86_64-pc-linux-gnu) compiled by GNU C version 10.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.21-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++17 (GCC) version 10.2.0 (x86_64-pc-linux-gnu) compiled by GNU C version 10.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.21-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: f27fb68878a84470810fd2057eccecc9 test_bug.cpp: In function ‘future create_future()’: test_bug.cpp:55:19: internal compiler error: Segmentation fault 55 | { co_return 2021; } | ^ Please submit a full bug report, with preprocessed source if appropriate. See <https://bugs.archlinux.org/> for instructions. ```