From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E582D3858C60; Wed, 29 Sep 2021 16:52:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E582D3858C60 From: "redbeard0531 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102528] Unused out-of-line functions emitted for trivial coroutines Date: Wed, 29 Sep 2021 16:52:46 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redbeard0531 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: Wed, 29 Sep 2021 16:52:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102528 --- Comment #1 from Mathias Stearn --- Sorry, there was a typo in the initial code. I forgot the trivial implementation of await_resume(). (D'oh!) Now I can see that test() is just a ret instruction, but there is still a l= ot of dead code emitted for the coroutine functions. While it isn't too much f= or the trivial functions, for a real use case it would be. And it seems like a= bug anyway that unused code makes it to the obj file in -O3: https://godbolt.org/z/bTncofrzd #include struct simple { struct promise_type { void return_void() {} std::suspend_never initial_suspend() { return {}; } std::suspend_never final_suspend() noexcept { return {}; } void unhandled_exception() { throw; } simple get_return_object() { return {}; } }; std::true_type await_ready() {return {}; } void await_suspend(std::coroutine_handle<>) {} void await_resume() {} }; inline simple test1() { co_return; } inline simple test2() { co_await test1(); co_return; } void test() { test2(); } test1(test1()::_Z5test1v.frame*) [clone .actor]: movzx eax, WORD PTR [rdi+18] test al, 1 je .L2 cmp ax, 5 ja .L3 mov edx, 42 bt rdx, rax jnc .L3 .L4: cmp BYTE PTR [rdi+17], 0 jne .L14 .L1: ret .L2: cmp ax, 2 je .L5 cmp ax, 4 je .L4 test ax, ax jne .L3 mov QWORD PTR [rdi+24], rdi .L5: cmp BYTE PTR [rdi+17], 0 mov BYTE PTR [rdi+32], 1 mov QWORD PTR [rdi], 0 je .L1 .L14: jmp operator delete(void*) test1(test1()::_Z5test1v.frame*) [clone .actor] [clone .cold]: .L3: ud2 test2(test2()::_Z5test2v.frame*) [clone .actor]: movzx eax, WORD PTR [rdi+18] test al, 1 je .L16 cmp ax, 7 ja .L17 mov edx, 170 bt rdx, rax jnc .L17 .L18: cmp BYTE PTR [rdi+17], 0 jne .L33 .L15: ret .L16: cmp ax, 4 je .L19 ja .L20 test ax, ax jne .L34 mov QWORD PTR [rdi+24], rdi .L22: mov BYTE PTR [rdi+32], 1 .L19: cmp BYTE PTR [rdi+17], 0 mov QWORD PTR [rdi], 0 je .L15 .L33: jmp operator delete(void*) .L34: cmp ax, 2 je .L22 jmp .L17 .L20: cmp ax, 6 je .L18 jmp .L17 test2(test2()::_Z5test2v.frame*) [clone .actor] [clone .cold]: .L17: ud2 test1(test1()::_Z5test1v.frame*) [clone .destroy]: movzx eax, WORD PTR [rdi+18] or eax, 1 mov WORD PTR [rdi+18], ax cmp ax, 5 ja .L36 mov edx, 42 bt rdx, rax jnc .L36 cmp BYTE PTR [rdi+17], 0 jne .L39 ret .L39: jmp operator delete(void*) test1(test1()::_Z5test1v.frame*) [clone .destroy] [clone .cold]: .L36: ud2 test2(test2()::_Z5test2v.frame*) [clone .destroy]: movzx eax, WORD PTR [rdi+18] or eax, 1 mov WORD PTR [rdi+18], ax cmp ax, 7 ja .L41 mov edx, 170 bt rdx, rax jnc .L41 cmp BYTE PTR [rdi+17], 0 jne .L44 ret .L44: jmp operator delete(void*) test2(test2()::_Z5test2v.frame*) [clone .destroy] [clone .cold]: .L41: ud2 test(): ret=