From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D86FA3858C2C; Mon, 27 Sep 2021 21:58:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D86FA3858C2C From: "delleyves at gmx dot ch" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: delleyves at gmx dot ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Sep 2021 21:58:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102508 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=3D51513&action=3Dedit Preprocessed source. The following code ICEs with a segmentation fault (release-checking) / asse= rt (all-checking): ``` #include #include #include namespace outcome =3D OUTCOME_V2_NAMESPACE; template using result =3D outcome::experimental::status_result; template struct CoroAwaiter { template explicit CoroAwaiter(LazyAsync &&lazy_async) { (void)std::forward(lazy_async)(); } bool await_ready() noexcept; void await_suspend(std::coroutine_handle<> awaiting_coroutine) noexcept; result_type &&await_resume() noexcept; }; template struct CoroBase { using result_type =3D R; struct promise_type { template auto await_transform( LazyAsync &&lazy_async) { using nested_result_type =3D typename std::invoke_result_t::result_type; return CoroAwaiter(std::forward(lazy_async)); } #ifdef __cpp_exceptions void unhandled_exception() noexcept; #endif template 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() =3D default; CoroBase(CoroBase &&) =3D default; CoroBase(const CoroBase &) =3D delete; }; template using Coro =3D CoroBase>; [[nodiscard]] Coro bar() noexcept; [[nodiscard]] Coro foo() noexcept { #if true bool ok =3D OUTCOME_CO_TRYX(co_await [&]() { return bar(); }); #else auto res =3D co_await [&]() { return bar(); }; if(!res.has_value()) { co_return outcome::failure(std::move(res).error()); } bool ok =3D 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 t= he 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 wi= th "--std=3Dc++20 -fcoroutines" and the outcome library enabled. The preproces= sed sources are from a local, checking GCC build of current master (11.2.1), wh= ere 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=3D/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=3D/Users/yves/SDKs/gcc-11-20210926 --enable-bootstrap --enable-checking=3Dyes --enable-languages=3Dc,c++,lto --with-default-libstdcxx-abi=3Dnew --enable-libstdcxx-debug --enable-plugin --disable-multilib --with-sysroot=3D/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk --with-pkgversion=3Dyves-Yves-MBookPro15 --program-suffix=3D-11-20210926 Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.2.1 20210926 (yves-Yves-MBookPro15)=20 COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-D' 'EMBCPP_OUTCOME_SINGLE_HEADER= ' '-D' 'OUTCOME_DISABLE_EXECINFO' '-I' '/Users/yves/epymetrics/core-fw/compiler-crash-evaluation/../deps/outcome/s= ingle-header' '-Wall' '-Wextra' '-fno-rtti' '-fno-exceptions' '-O0' '-g3' '-fcoroutines' '-std=3Dc++20' '-o' 'test.o' '-c' '-mmacosx-version-min=3D11.5.0' '-asm_macosx_version_min=3D11.5' '-shared-libgcc' '-mtune=3Dcore2' /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/si= ngle-header -dD -D__DYNAMIC__ -D EMBCPP_OUTCOME_SINGLE_HEADER -D OUTCOME_DISABLE_EXECIN= FO /Users/yves/epymetrics/core-fw/compiler-crash-evaluation/test-case.cpp -fPIC -mmacosx-version-min=3D11.5.0 -mtune=3Dcore2 -std=3Dc++20 -Wall -Wextra -fn= o-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/si= ngle-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/i= nclude /Users/yves/SDKs/gcc-11-20210926/lib/gcc/x86_64-apple-darwin20.6.0/11.2.1/i= nclude-fixed /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Framewo= rks End of search list. COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-D' 'EMBCPP_OUTCOME_SINGLE_HEADER= ' '-D' 'OUTCOME_DISABLE_EXECINFO' '-I' '/Users/yves/epymetrics/core-fw/compiler-crash-evaluation/../deps/outcome/s= ingle-header' '-Wall' '-Wextra' '-fno-rtti' '-fno-exceptions' '-O0' '-g3' '-fcoroutines' '-std=3Dc++20' '-o' 'test.o' '-c' '-mmacosx-version-min=3D11.5.0' '-asm_macosx_version_min=3D11.5' '-shared-libgcc' '-mtune=3Dcore2' /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=3D11.5.0 -mtune=3Dcore2 -g3 -O0 -Wall -Wextra -std=3Dc= ++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=3D30 --param ggc-min-heapsize=3D4096 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=3D30 --param ggc-min-heapsize=3D4096 Compiler executable checksum: cd23c6af9953d6c303dd89c0d734e2b7 /Users/yves/epymetrics/core-fw/compiler-crash-evaluation/test-case.cpp: In function =E2=80=98Coro foo()=E2=80=99: /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:2= 102 72 | } | ^ Please submit a full bug report, with preprocessed source if appropriate. See for instructions. ```=