Skip to content

Commit 9139d72

Browse files
committed
do not add prolog for variadic naked functions
fixes #99858
1 parent 8df7e72 commit 9139d72

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

compiler/rustc_codegen_ssa/src/mir/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::base;
22
use crate::traits::*;
33
use rustc_index::bit_set::BitSet;
44
use rustc_index::IndexVec;
5+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
56
use rustc_middle::mir;
67
use rustc_middle::mir::traversal;
78
use rustc_middle::mir::UnwindTerminateReason;
@@ -290,6 +291,12 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
290291

291292
let mut num_untupled = None;
292293

294+
let codegen_fn_attrs = bx.tcx().codegen_fn_attrs(fx.instance.def_id());
295+
let naked = codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED);
296+
if naked {
297+
return vec![];
298+
}
299+
293300
let args = mir
294301
.args_iter()
295302
.enumerate()
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ needs-asm-support
2+
//@ only-x86_64
3+
4+
// tests that `va_start` is not injected into naked functions
5+
6+
#![crate_type = "lib"]
7+
#![feature(c_variadic)]
8+
#![feature(naked_functions)]
9+
#![no_std]
10+
11+
#[naked]
12+
pub unsafe extern "C" fn c_variadic(_: usize, _: ...) {
13+
// CHECK-NOT: va_start
14+
// CHECK-NOT: alloca
15+
core::arch::asm! {
16+
"ret",
17+
options(noreturn),
18+
}
19+
}

tests/codegen/naked-fn/naked-functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub unsafe extern "C" fn naked_empty() {
1919
}
2020

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

0 commit comments

Comments
 (0)