From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 89DF3385743E; Wed, 7 Jul 2021 01:30:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89DF3385743E From: "daklishch at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: daklishch at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jul 2021 01:30:26 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101355 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=3D51111&action=3Dedit preprocessed source Compiling the following program with UBSan emits -Wmaybe-uninitialized on `' 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 a= nd makes the program crash with `member call on null pointer of type 'struct a= ''. $ cat testcode.cc #include 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 void await_suspend(U &) {} }; struct b { ~b() {} }; struct a { a(b) {} ~a() {} }; coro f(b obj) { auto obj2 =3D a{obj}; co_return; } int main() { f({}); } $ ~/gcc-dev/bin/gccdev -O2 -std=3Dc++20 -Wall -fsanitize=3Dundefined testco= de.cc -lstdc++ testcode.cc: In function =E2=80=98void _Z1f1b.actor(f(b)::_Z1f1b.frame*)=E2= =80=99: testcode.cc:30:1: warning: =E2=80=98=E2=80=99 may be used uninit= ialized [-Wmaybe-uninitialized] 30 | } | ^ testcode.cc:30:1: note: =E2=80=98=E2=80=99 was declared here 30 | } | ^ In function =E2=80=98void _Z1f1b.actor(f(b)::_Z1f1b.frame*)=E2=80=99, inlined from =E2=80=98coro f(b)=E2=80=99 at testcode.cc:27:6: testcode.cc:30:1: warning: =E2=80=98=E2=80=99 is used uninitiali= zed [-Wuninitialized] 30 | } | ^ testcode.cc: In function =E2=80=98coro f(b)=E2=80=99: testcode.cc:30:1: note: =E2=80=98=E2=80=99 was declared here 30 | } | ^ $ ./a.out testcode.cc:30:1: runtime error: member call on null pointer of type 'struc= t a'=