From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 48FA2385802D; Thu, 18 Feb 2021 14:45:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48FA2385802D From: "sebastian.huber@embedded-brains.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/99151] New: Missed optimization: Superfluous stack frame and code with noreturn or __builtin_unreachable() Date: Thu, 18 Feb 2021 14:45:57 +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: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sebastian.huber@embedded-brains.de 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 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: Thu, 18 Feb 2021 14:45:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99151 Bug ID: 99151 Summary: Missed optimization: Superfluous stack frame and code with noreturn or __builtin_unreachable() Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: sebastian.huber@embedded-brains.de Target Milestone: --- The following test code: _Noreturn void r(void); void u(void); void g(void) { r(); } void f(void) { u(); __builtin_unreachable(); } Produces code the following code on a sample set of architectures. There sh= ould be no stack frame set up. There should be no instructions after the no-retu= rn function calls (for example sparc). sparc-rtems6-gcc -O2 -o - -S unreachable.c=20 .file "unreachable.c" .section ".text" .align 4 .global g .type g, #function .proc 020 g: save %sp, -96, %sp call r, 0 nop nop .size g, .-g .align 4 .global f .type f, #function .proc 020 f: save %sp, -96, %sp call u, 0 nop nop .size f, .-f .ident "GCC: (GNU) 10.2.1 20210205 (RTEMS 6, RSB 61dcadee0825867ebe51f9f367430ef75b8fe9c0, Newlib d4a756f)" arm-rtems6-gcc -O2 -o - -S unreachable.c=20 .cpu arm7tdmi .eabi_attribute 20, 1 .eabi_attribute 21, 1 .eabi_attribute 23, 3 .eabi_attribute 24, 1 .eabi_attribute 25, 1 .eabi_attribute 26, 2 .eabi_attribute 30, 2 .eabi_attribute 34, 0 .eabi_attribute 18, 4 .file "unreachable.c" .text .align 2 .global g .arch armv4t .syntax unified .arm .fpu softvfp .type g, %function g: @ Function supports interworking. @ Volatile: function does not return. @ args =3D 0, pretend =3D 0, frame =3D 0 @ frame_needed =3D 0, uses_anonymous_args =3D 0 push {r4, lr} bl r .size g, .-g .align 2 .global f .syntax unified .arm .fpu softvfp .type f, %function f: @ Function supports interworking. @ Volatile: function does not return. @ args =3D 0, pretend =3D 0, frame =3D 0 @ frame_needed =3D 0, uses_anonymous_args =3D 0 push {r4, lr} bl u .size f, .-f .ident "GCC: (GNU) 10.2.1 20210205 (RTEMS 6, RSB 61dcadee0825867ebe51f9f367430ef75b8fe9c0, Newlib d4a756f)" powerpc-rtems6-gcc -O2 -o - -S unreachable.c=20 .file "unreachable.c" .machine ppc .section ".text" .align 2 .globl g .type g, @function g: .LFB0: .cfi_startproc stwu 1,-16(1) .cfi_def_cfa_offset 16 mflr 0 stw 0,20(1) .cfi_offset 65, 4 bl r .cfi_endproc .LFE0: .size g,.-g .align 2 .globl f .type f, @function f: .LFB1: .cfi_startproc stwu 1,-16(1) .cfi_def_cfa_offset 16 mflr 0 stw 0,20(1) .cfi_offset 65, 4 bl u .cfi_endproc .LFE1: .size f,.-f .ident "GCC: (GNU) 10.2.1 20210205 (RTEMS 6, RSB 61dcadee0825867ebe51f9f367430ef75b8fe9c0, Newlib d4a756f)" .section .note.GNU-stack,"",@progbits=