public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "daklishch at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101355] New: compiling coroutines with ubsan emits bogus -Wmaybe-uninitialized warnings Date: Wed, 07 Jul 2021 01:30:26 +0000 [thread overview] Message-ID: <bug-101355-4@http.gcc.gnu.org/bugzilla/> (raw) 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'
next reply other threads:[~2021-07-07 1:30 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-07 1:30 daklishch at gmail dot com [this message] 2021-07-07 1:30 ` [Bug c++/101355] " daklishch at gmail dot com 2021-07-16 7:29 ` daklishch at gmail dot com 2021-08-30 19:02 ` [Bug c++/101355] incorrect `this' in destructor calls when compiling coroutines with ubsan iains at gcc dot gnu.org 2021-08-30 19:04 ` iains at gcc dot gnu.org 2021-09-04 16:39 ` daklishch at gmail dot com 2021-09-30 14:42 ` mpolacek at gcc dot gnu.org 2021-09-30 14:59 ` iains at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-101355-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).