Skip to content

Commit 4a0e9e0

Browse files
authored
Rollup merge of #123249 - goolmoos:naked_variadics, r=pnkfelix
do not add prolog for variadic naked functions fixes #99858
2 parents 68359e2 + 9139d72 commit 4a0e9e0

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;
@@ -289,6 +290,12 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
289290

290291
let mut num_untupled = None;
291292

293+
let codegen_fn_attrs = bx.tcx().codegen_fn_attrs(fx.instance.def_id());
294+
let naked = codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED);
295+
if naked {
296+
return vec![];
297+
}
298+
292299
let args = mir
293300
.args_iter()
294301
.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)