Skip to content

Naked functions contain a trailing ret insn #32487

Closed
@nagisa

Description

@nagisa
#[naked]
fn naked(){
    unsafe {
    asm!("ret");
    }
}

results in

; Function Attrs: naked uwtable
define internal void @_ZN5naked20hb8640283bf863d54eaaE() unnamed_addr #0 {
entry-block:
  call void asm "ret", "~{dirflag},~{fpsr},~{flags}"(), !srcloc !0
  ret void
}
    .section    .text._ZN5naked20hb8640283bf863d54eaaE,"ax",@progbits
    .align  16, 0x90
    .type   _ZN5naked20hb8640283bf863d54eaaE,@function
_ZN5naked20hb8640283bf863d54eaaE:
    .cfi_startproc
    #APP
    retq
    #NO_APP
    retq
.Lfunc_end0:
    .size   _ZN5naked20hb8640283bf863d54eaaE, .Lfunc_end0-_ZN5naked20hb8640283bf863d54eaaE
    .cfi_endproc

note the trailing retq instruction that shouldn’t otherwise be here.

An equivalent function compiled by clang looks like this:

; Function Attrs: naked noinline nounwind uwtable
define void @naked() #0 {
  call void asm sideeffect "ret", "~{dirflag},~{fpsr},~{flags}"() #1, !srcloc !1
  unreachable
}
    .globl  naked
    .align  16, 0x90
    .type   naked,@function
naked:                                  # @naked
    .cfi_startproc
# BB#0:
    #APP
    retq
    #NO_APP
.Lfunc_end0:
    .size   naked, .Lfunc_end0-naked
    .cfi_endproc

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions