Under GCC 12 a non-trivial temporary inside a co_await expression is destroyed twice
Symptom#
Tests crash or report a bad free at run time in the dftracer-gcc12 container. Clang on the dev Mac builds and runs the same code correctly. A site was co_await f(ChunkPrunerInput{...}) in src/dftracer/utils/index/plan/prune.cpp. A braced init list in a co_await expression can also make GCC 12 fail inside the compiler (build_special_member_call); another site was the co_await near line 315 of src/dftracer/utils/trace/genesis/discover.cpp, an internal compiler error that moving loops around did not fix.
Cause#
GCC 12 destroys the temporary built inside the co_await expression twice, or crashes on it.
Fix#
Bind every non-trivial temporary passed to co_await to a named local first, then pass the local (with a one-line comment saying why). To find other sites, grep for co_await calls that take a braced or constructed argument inline.
Evidence#
An ASan build of one failing test in the dftracer-gcc12 container pointed at the double destroy. Fixed in 5a12a75a (fix(build): build and test on GCC 12).
Also found by searching
- bad free or crash only under GCC 12, Clang passes, in a coroutine test
- temporary passed to co_await destroyed twice
- how do I pass a braced init argument to a co_await call on GCC 12
- internal compiler error GCC 12 coroutine co_await expression passes input inline