https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96517
Bug ID: 96517 Summary: ICE in is_this_parameter when accessing constexpr method of a field inside coroutine lambda (with optimization) Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: przemekmirek at gmail dot com Target Milestone: --- Created attachment 49017 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49017&action=edit preprocessed source Compiling the following code with any level of optimization enabled (anything except O0) causes gcc to exit with an ICE. I'm using GCC 10.2.0 from MSYS2 MinGW, however the same error occurs on any GCC > 10.0 available in Compiler Explorer, including trunk. See https://godbolt.org/z/h7bjKG I've been trying to reduce it to a less-specific example, the original code failed when accessing std::optional. I don't think I can shorten it any further. Making get() non-constexpr, making _data static, making coroutine a member function instead of a lambda, all stop the error from appearing. --- #include <coroutine> struct coroutine { struct promise_type { coroutine get_return_object() { return {}; } void return_void() {} void unhandled_exception() {} auto initial_suspend() noexcept { return std::suspend_never{}; } auto final_suspend() noexcept { return std::suspend_never{}; } }; }; struct data { constexpr int get() { return 5; } }; struct test { data _data; void foo() { [this]() -> coroutine { _data.get(); co_return; }; } }; int main() {} --- The full commandline and output is attached below: $ g++ -v -std=c++20 -fcoroutines -O1 -save-temps main.cpp Using built-in specs. COLLECT_GCC=C:\msys64\mingw32\bin\g++.exe COLLECT_LTO_WRAPPER=C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/lto-wrapper.exe Target: i686-w64-mingw32 Configured with: ../gcc-10.2.0/configure --prefix=/mingw32 --with-local-prefix=/mingw32/local --build=i686-w64-mingw32 --host=i686-w64-mingw32 --target=i686-w64-mingw32 --with-native-system-header-dir=/mingw32/i686-w64-mingw32/include --libexecdir=/mingw32/lib --enable-bootstrap --with-arch=i686 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --disable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw32 --with-mpfr=/mingw32 --with-mpc=/mingw32 --with-isl=/mingw32 --with-pkgversion='Rev1, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-sjlj-exceptions --with-dwarf2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.2.0 (Rev1, Built by MSYS2 project) COLLECT_GCC_OPTIONS='-v' '-std=c++2a' '-fcoroutines' '-O1' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=i686' C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/cc1plus.exe -E -quiet -v -iprefix C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/ -D_REENTRANT main.cpp -mtune=generic -march=i686 -std=c++2a -fcoroutines -O1 -fpch-preprocess -o main.ii ignoring duplicate directory "C:/msys64/mingw32/lib/gcc/../../lib/gcc/i686-w64-mingw32/10.2.0/../../../../include/c++/10.2.0" ignoring duplicate directory "C:/msys64/mingw32/lib/gcc/../../lib/gcc/i686-w64-mingw32/10.2.0/../../../../include/c++/10.2.0/i686-w64-mingw32" ignoring duplicate directory "C:/msys64/mingw32/lib/gcc/../../lib/gcc/i686-w64-mingw32/10.2.0/../../../../include/c++/10.2.0/backward" ignoring duplicate directory "C:/msys64/mingw32/lib/gcc/../../lib/gcc/i686-w64-mingw32/10.2.0/include" ignoring nonexistent directory "D:/msys64/mingw32/include" ignoring nonexistent directory "/mingw32/include" ignoring duplicate directory "C:/msys64/mingw32/lib/gcc/../../lib/gcc/i686-w64-mingw32/10.2.0/include-fixed" ignoring duplicate directory "C:/msys64/mingw32/lib/gcc/../../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/include" ignoring nonexistent directory "D:/msys64/mingw32/i686-w64-mingw32/include" #include "..." search starts here: #include <...> search starts here: C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../include/c++/10.2.0 C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../include/c++/10.2.0/i686-w64-mingw32 C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../include/c++/10.2.0/backward C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/include C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../include C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/include-fixed C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/include End of search list. COLLECT_GCC_OPTIONS='-v' '-std=c++2a' '-fcoroutines' '-O1' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=i686' C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/cc1plus.exe -fpreprocessed main.ii -quiet -dumpbase main.cpp -mtune=generic -march=i686 -auxbase main -O1 -std=c++2a -version -fcoroutines -o main.s GNU C++17 (Rev1, Built by MSYS2 project) version 10.2.0 (i686-w64-mingw32) compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++17 (Rev1, Built by MSYS2 project) version 10.2.0 (i686-w64-mingw32) compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: b383ad3e7b4fa535de44ee60f873a45a main.cpp: In function 'void test::foo()::<lambda()>::_ZZN4test3fooEvENKUlvE_clEv.actor(test::foo()::<lambda()>::_ZZN4test3fooEvENKUlvE_clEv.frame*)': main.cpp:24:9: internal compiler error: in is_this_parameter, at cp/semantics.c:10206 24 | }; | ^ main.cpp:24:9: internal compiler error: Aborted g++.exe: internal compiler error: Aborted signal terminated program cc1plus