From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D273B385801E; Fri, 16 Jul 2021 07:29:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D273B385801E From: "daklishch at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101355] compiling coroutines with ubsan emits bogus -Wmaybe-uninitialized warnings Date: Fri, 16 Jul 2021 07:29:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: Message-ID: In-Reply-To: References: 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: Fri, 16 Jul 2021 07:29:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101355 --- Comment #2 from Dan Klishch --- GCC incorrectly gimplifies the program. The code that is causing the warnin= g is in the coroutine's actor function: try { D.9829 =3D &frame_ptr->__p; .UBSAN_NULL (D.9829, 4B, 0); coro::promise_type::return_void (D.9829); goto final.suspend; } finally { .UBSAN_NULL (D.9828, 4B, 0); // here a::~a (D.9828); } Obviously, an assignment to D.9828 is missing. However, a little bit earlie= r a similar destruction of `struct a' is handled correctly: try { b::~b (&D.9562); } catch { D.9828 =3D &frame_ptr->__obj.2.3; .UBSAN_NULL (D.9828, 4B, 0); a::~a (D.9828); } I guess one of this destructor calls is a copy of another and this might be= the root of the problem. After ubsan instrumentation the call to the destructor looks like this: a::~a (.UBSAN_NULL (SAVE_EXPR <&frame_ptr->__obj.2.3>, 4B, 0);, SAVE_EXPR <&frame_ptr->__obj.2.3>;); I believe the same SAVE_EXPR is copied to the second invocation of the destructor but the enclosed expression evaluation is placed only before the first use of SAVE_EXPR and the control flow does not reach it before a call= to the actual (second) destructor. I guess this can be fixed by instrumenting the calls to the destructors usi= ng temporary variable and not SAVE_EXPR, like this: void *ptr =3D &frame_ptr->__obj.2.3; .UBSAN_NULL (ptr, 4B, 0); a::~a (ptr); But I don't have a solid understanding of GCC internals, so I'm not sure if= it is right.=