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: [email protected]
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