do not add prolog for variadic naked functions

fixes #99858
This commit is contained in:
Guy Shefy 2024-03-30 16:33:18 +03:00
parent 8df7e723ea
commit 9139d7252d
3 changed files with 27 additions and 1 deletions

View File

@ -2,6 +2,7 @@
use crate::traits::*; use crate::traits::*;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::mir::traversal; use rustc_middle::mir::traversal;
use rustc_middle::mir::UnwindTerminateReason; use rustc_middle::mir::UnwindTerminateReason;
@ -290,6 +291,12 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let mut num_untupled = None; let mut num_untupled = None;
let codegen_fn_attrs = bx.tcx().codegen_fn_attrs(fx.instance.def_id());
let naked = codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED);
if naked {
return vec![];
}
let args = mir let args = mir
.args_iter() .args_iter()
.enumerate() .enumerate()

View File

@ -0,0 +1,19 @@
//@ needs-asm-support
//@ only-x86_64
// tests that `va_start` is not injected into naked functions
#![crate_type = "lib"]
#![feature(c_variadic)]
#![feature(naked_functions)]
#![no_std]
#[naked]
pub unsafe extern "C" fn c_variadic(_: usize, _: ...) {
// CHECK-NOT: va_start
// CHECK-NOT: alloca
core::arch::asm! {
"ret",
options(noreturn),
}
}

View File

@ -19,7 +19,7 @@
} }
// CHECK: Function Attrs: naked // CHECK: Function Attrs: naked
// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_args_and_return(i64 %a, i64 %b) // CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_args_and_return(i64 %0, i64 %1)
#[no_mangle] #[no_mangle]
#[naked] #[naked]
pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize { pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {