public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "delleyves at gmx dot ch" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102508] New: ICE on coroutine when awaiting inside a statement expression (in transform_local_var_uses, at cp/coroutines.cc:2102) Date: Mon, 27 Sep 2021 21:58:01 +0000 [thread overview] Message-ID: <bug-102508-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102508 Bug ID: 102508 Summary: ICE on coroutine when awaiting inside a statement expression (in transform_local_var_uses, at cp/coroutines.cc:2102) Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: delleyves at gmx dot ch Target Milestone: --- Created attachment 51513 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51513&action=edit Preprocessed source. The following code ICEs with a segmentation fault (release-checking) / assert (all-checking): ``` #include <coroutine> #include <stdexcept> #include <outcome-experimental.hpp> namespace outcome = OUTCOME_V2_NAMESPACE; template <typename T> using result = outcome::experimental::status_result<T>; template <typename result_type> struct CoroAwaiter { template <typename LazyAsync> explicit CoroAwaiter(LazyAsync &&lazy_async) { (void)std::forward<LazyAsync>(lazy_async)(); } bool await_ready() noexcept; void await_suspend(std::coroutine_handle<> awaiting_coroutine) noexcept; result_type &&await_resume() noexcept; }; template <typename R> struct CoroBase { using result_type = R; struct promise_type { template <typename LazyAsync> auto await_transform( LazyAsync &&lazy_async) { using nested_result_type = typename std::invoke_result_t<LazyAsync &&>::result_type; return CoroAwaiter<nested_result_type>(std::forward<LazyAsync>(lazy_async)); } #ifdef __cpp_exceptions void unhandled_exception() noexcept; #endif template <typename V> void return_value(V &&value) noexcept; std::suspend_never initial_suspend() noexcept; std::suspend_always final_suspend() noexcept; static CoroBase get_return_object_on_allocation_failure() noexcept; CoroBase get_return_object() noexcept; }; CoroBase() = default; CoroBase(CoroBase &&) = default; CoroBase(const CoroBase &) = delete; }; template <typename T> using Coro = CoroBase<result<T>>; [[nodiscard]] Coro<bool> bar() noexcept; [[nodiscard]] Coro<void> foo() noexcept { #if true bool ok = OUTCOME_CO_TRYX(co_await [&]() { return bar(); }); #else auto res = co_await [&]() { return bar(); }; if(!res.has_value()) { co_return outcome::failure(std::move(res).error()); } bool ok = res.value(); #endif (void)ok; co_return outcome::success(); } ``` Replace the `#if true` with `#if false` and the code compiles fine - despite the two branches roughly having the same effect, though `OUTCOME_CO_TRYX` utilises a Statement Expression (GCC / Clang extension). Unfortunately, I haven't been able to reproduce the ICE without involving the outcome library. This issue seems to exist since as long as coroutines are available in GCC. In particular, the code provided above ICEs on godbolt.org with a segfault on all GCC 10.1 through 11.2 as well as (trunk) and (coroutines), when compiled with "--std=c++20 -fcoroutines" and the outcome library enabled. The preprocessed sources are from a local, checking GCC build of current master (11.2.1), where instead of segfaulting it ICEs in an assert at `in transform_local_var_uses, at cp/coroutines.cc:2102`. The full compilation output is: ``` Using built-in specs. COLLECT_GCC=/Users/yves/SDKs/gcc-11-20210926/bin/g++-11-20210926 Target: x86_64-apple-darwin20.6.0 Configured with: /var/tmp/yves/gcc-11-20210926_source/configure --prefix=/Users/yves/SDKs/gcc-11-20210926 --enable-bootstrap --enable-checking=yes --enable-languages=c,c++,lto --with-default-libstdcxx-abi=new --enable-libstdcxx-debug --enable-plugin --disable-multilib --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk --with-pkgversion=yves-Yves-MBookPro15 --program-suffix=-11-20210926 Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.2.1 20210926 (yves-Yves-MBookPro15) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-D' 'EMBCPP_OUTCOME_SINGLE_HEADER' '-D' 'OUTCOME_DISABLE_EXECINFO' '-I' '/Users/yves/epymetrics/core-fw/compiler-crash-evaluation/../deps/outcome/single-header' '-Wall' '-Wextra' '-fno-rtti' '-fno-exceptions' '-O0' '-g3' '-fcoroutines' '-std=c++20' '-o' 'test.o' '-c' '-mmacosx-version-min=11.5.0' '-asm_macosx_version_min=11.5' '-shared-libgcc' '-mtune=core2' /Users/yves/SDKs/gcc-11-20210926/libexec/gcc/x86_64-apple-darwin20.6.0/11.2.1/cc1plus -E -quiet -v -I /Users/yves/epymetrics/core-fw/compiler-crash-evaluation/../deps/outcome/single-header -dD -D__DYNAMIC__ -D EMBCPP_OUTCOME_SINGLE_HEADER -D OUTCOME_DISABLE_EXECINFO /Users/yves/epymetrics/core-fw/compiler-crash-evaluation/test-case.cpp -fPIC -mmacosx-version-min=11.5.0 -mtune=core2 -std=c++20 -Wall -Wextra -fno-rtti -fno-exceptions -fcoroutines -g3 -fworking-directory -O0 -fpch-preprocess -o test.ii ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include" ignoring nonexistent directory "/Users/yves/SDKs/gcc-11-20210926/lib/gcc/x86_64-apple-darwin20.6.0/11.2.1/../../../../x86_64-apple-darwin20.6.0/include" ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks" #include "..." search starts here: #include <...> search starts here: /Users/yves/epymetrics/core-fw/compiler-crash-evaluation/../deps/outcome/single-header /Users/yves/SDKs/gcc-11-20210926/lib/gcc/x86_64-apple-darwin20.6.0/11.2.1/../../../../include/c++/11.2.1 /Users/yves/SDKs/gcc-11-20210926/lib/gcc/x86_64-apple-darwin20.6.0/11.2.1/../../../../include/c++/11.2.1/x86_64-apple-darwin20.6.0 /Users/yves/SDKs/gcc-11-20210926/lib/gcc/x86_64-apple-darwin20.6.0/11.2.1/../../../../include/c++/11.2.1/backward /Users/yves/SDKs/gcc-11-20210926/lib/gcc/x86_64-apple-darwin20.6.0/11.2.1/include /Users/yves/SDKs/gcc-11-20210926/lib/gcc/x86_64-apple-darwin20.6.0/11.2.1/include-fixed /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-D' 'EMBCPP_OUTCOME_SINGLE_HEADER' '-D' 'OUTCOME_DISABLE_EXECINFO' '-I' '/Users/yves/epymetrics/core-fw/compiler-crash-evaluation/../deps/outcome/single-header' '-Wall' '-Wextra' '-fno-rtti' '-fno-exceptions' '-O0' '-g3' '-fcoroutines' '-std=c++20' '-o' 'test.o' '-c' '-mmacosx-version-min=11.5.0' '-asm_macosx_version_min=11.5' '-shared-libgcc' '-mtune=core2' /Users/yves/SDKs/gcc-11-20210926/libexec/gcc/x86_64-apple-darwin20.6.0/11.2.1/cc1plus -fpreprocessed test.ii -fPIC -quiet -dumpbase test.cpp -dumpbase-ext .cpp -mmacosx-version-min=11.5.0 -mtune=core2 -g3 -O0 -Wall -Wextra -std=c++20 -version -fno-rtti -fno-exceptions -fcoroutines -o test.s GNU C++20 (yves-Yves-MBookPro15) version 11.2.1 20210926 (x86_64-apple-darwin20.6.0) compiled by GNU C version 11.2.1 20210926, GMP version 6.1.0, MPFR version 3.1.6, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 GNU C++20 (yves-Yves-MBookPro15) version 11.2.1 20210926 (x86_64-apple-darwin20.6.0) compiled by GNU C version 11.2.1 20210926, GMP version 6.1.0, MPFR version 3.1.6, MPC version 1.0.3, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 Compiler executable checksum: cd23c6af9953d6c303dd89c0d734e2b7 /Users/yves/epymetrics/core-fw/compiler-crash-evaluation/test-case.cpp: In function ‘Coro<void> foo()’: /Users/yves/epymetrics/core-fw/compiler-crash-evaluation/test-case.cpp:72:1: internal compiler error: in transform_local_var_uses, at cp/coroutines.cc:2102 72 | } | ^ Please submit a full bug report, with preprocessed source if appropriate. See <https://gcc.gnu.org/bugs/> for instructions. ```
next reply other threads:[~2021-09-27 21:58 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-27 21:58 delleyves at gmx dot ch [this message] 2021-09-30 9:55 ` [Bug c++/102508] " marxin at gcc dot gnu.org 2021-10-21 23:52 ` kacper.slominski72 at gmail dot com 2021-10-22 20:11 ` iains at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102508-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).