public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99151] New: Missed optimization: Superfluous stack frame and code with noreturn or __builtin_unreachable()
@ 2021-02-18 14:45 sebastian.huber@embedded-brains.de
  2021-02-18 14:52 ` [Bug c/99151] " jakub at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: sebastian.huber@embedded-brains.de @ 2021-02-18 14:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99151

            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 should
be no stack frame set up. There should be no instructions after the no-return
function calls (for example sparc).

sparc-rtems6-gcc -O2 -o - -S unreachable.c 
        .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 
        .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 = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 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 = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 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 
        .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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-03-01 13:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-18 14:45 [Bug c/99151] New: Missed optimization: Superfluous stack frame and code with noreturn or __builtin_unreachable() sebastian.huber@embedded-brains.de
2021-02-18 14:52 ` [Bug c/99151] " jakub at gcc dot gnu.org
2021-02-18 14:56 ` sebastian.huber@embedded-brains.de
2021-02-18 19:15 ` pinskia at gcc dot gnu.org
2021-02-19  6:46 ` [Bug middle-end/99151] " sebastian.huber@embedded-brains.de
2021-03-01 11:17 ` ebotcazou at gcc dot gnu.org
2021-03-01 12:36 ` sebastian.huber@embedded-brains.de
2021-03-01 12:53 ` ebotcazou at gcc dot gnu.org
2021-03-01 13:04 ` sebastian.huber@embedded-brains.de
2021-03-01 13:21 ` jakub at gcc dot gnu.org

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).