https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116880
Bug ID: 116880
Summary: [15 Regression] too early coroutine destruction of
co_await on nix-2.24.8
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: slyfox at gcc dot gnu.org
Target Milestone: ---
Initially observed the failure as a SIGSEGV on a nix-2.24.8 testsuite. The test
runs on gcc-14 and fails on gcc-15 from r15-3941-g2531f014fb2364.
I think I managed to convert it to a build failure that complains about use of
a destroyed object:
// $ substitution-goal.cc
#include <coroutine>
struct promise_type;
using handle_type = std::coroutine_handle<promise_type>;
struct Co {
handle_type handle;
using promise_type = ::promise_type;
explicit Co(handle_type handle) : handle(handle) {}
bool await_ready() { return false; }
std::coroutine_handle<> await_suspend(handle_type handle);
void await_resume() {}
};
struct Done {};
struct promise_type {
Co get_return_object();
std::suspend_always initial_suspend() { return {}; };
std::suspend_always final_suspend() noexcept { return {}; };
void return_value(Done) {}
void return_value(Co&&);
void unhandled_exception() { throw; };
Co&& await_transform(Co&& co) { return static_cast<Co&&>(co); }
};
Co tryToRun();
Co init()
{
co_await tryToRun();
co_return Done{};
}
Good gcc-14:
$ g++-14 -o bug.o -c substitution-goal.cc -std=c++2a -Werror=dangling-pointer
-Wall
Bad gcc-15:
$ g++-15 -o bug.o -c substitution-goal.cc -std=c++2a -Werror=dangling-pointer
-Wall
substitution-goal.cc: In function 'void init(_Z4initv.Frame*)':
substitution-goal.cc:36:23: error: using a dangling pointer to an unnamed
temporary [-Werror=dangling-pointer=]
36 | co_await tryToRun();
| ^
substitution-goal.cc:36:22: note: unnamed temporary defined here
36 | co_await tryToRun();
| ~~~~~~~~^~
cc1plus: some warnings being treated as errors
$ g++-15 -v
Using built-in specs.
COLLECT_GCC=/<<NIX>>/gcc-15.0.0/bin/g++
COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-15.0.0/libexec/gcc/x86_64-unknown-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../source/configure --prefix=/<<NIX>>/gcc-15.0.0
--with-gmp-include=/<<NIX>>/gmp-6.3.0-dev/include
--with-gmp-lib=/<<NIX>>/gmp-6.3.0/lib
--with-mpfr-include=/<<NIX>>/mpfr-4.2.1-dev/include
--with-mpfr-lib=/<<NIX>>/mpfr-4.2.1/lib --with-mpc=/<<NIX>>/libmpc-1.3.1
--with-native-system-header-dir=/<<NIX>>/glibc-2.40-36-dev/include
--with-build-sysroot=/
--with-gxx-include-dir=/<<NIX>>/gcc-15.0.0/include/c++/15.0.0/
--program-prefix= --enable-lto --disable-libstdcxx-pch
--without-included-gettext --with-system-zlib --enable-checking=release
--enable-static --enable-languages=c,c++ --disable-multilib --enable-plugin
--disable-libcc1 --with-isl=/<<NIX>>/isl-0.20 --disable-bootstrap
--build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu
--target=x86_64-unknown-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 99999999 (experimental) (GCC)