https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101355
Bug ID: 101355 Summary: compiling coroutines with ubsan emits bogus -Wmaybe-uninitialized warnings Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: daklishch at gmail dot com Target Milestone: --- Created attachment 51111 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51111&action=edit preprocessed source Compiling the following program with UBSan emits -Wmaybe-uninitialized on `<anonymous>' variables. The compiler and runtime behavior is somewhat inconsistent. Normally, there is only one warning per function and the program is not affected. However, for example, compiling provided program with -O2 emits two identical warnings and makes the program crash with `member call on null pointer of type 'struct a''. $ cat testcode.cc #include <coroutine> struct coro { struct promise_type { coro get_return_object() { return {}; } std::suspend_never initial_suspend() noexcept { return {}; } std::suspend_never final_suspend() noexcept { return {}; } void unhandled_exception() {} void return_void() {} }; bool await_ready() { return true; } void await_resume() {} template <typename U> void await_suspend(U &) {} }; struct b { ~b() {} }; struct a { a(b) {} ~a() {} }; coro f(b obj) { auto obj2 = a{obj}; co_return; } int main() { f({}); } $ ~/gcc-dev/bin/gccdev -O2 -std=c++20 -Wall -fsanitize=undefined testcode.cc -lstdc++ testcode.cc: In function ‘void _Z1f1b.actor(f(b)::_Z1f1b.frame*)’: testcode.cc:30:1: warning: ‘<anonymous>’ may be used uninitialized [-Wmaybe-uninitialized] 30 | } | ^ testcode.cc:30:1: note: ‘<anonymous>’ was declared here 30 | } | ^ In function ‘void _Z1f1b.actor(f(b)::_Z1f1b.frame*)’, inlined from ‘coro f(b)’ at testcode.cc:27:6: testcode.cc:30:1: warning: ‘<anonymous>’ is used uninitialized [-Wuninitialized] 30 | } | ^ testcode.cc: In function ‘coro f(b)’: testcode.cc:30:1: note: ‘<anonymous>’ was declared here 30 | } | ^ $ ./a.out testcode.cc:30:1: runtime error: member call on null pointer of type 'struct a'