Rollup merge of #123249 - goolmoos:naked_variadics, r=pnkfelix

do not add prolog for variadic naked functions

fixes #99858
This commit is contained in:
Matthias Krüger 2024-04-12 17:41:33 +02:00 committed by GitHub
commit 4a0e9e0deb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

View File

@ -2,6 +2,7 @@ use crate::base;
use crate::traits::*;
use rustc_index::bit_set::BitSet;
use rustc_index::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir;
use rustc_middle::mir::traversal;
use rustc_middle::mir::UnwindTerminateReason;
@ -289,6 +290,12 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
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
.args_iter()
.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 @@ pub unsafe extern "C" fn naked_empty() {
}
// 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]
#[naked]
pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {