Skip to content

Commit 050fb38

Browse files
committed
Don't spill operands onto the stack in naked functions
Currently, the code spills operands onto the stack for the purpose of debuginfo. However, naked functions can only contain an asm block. Therefore, attempting to spill the operands on the stack is undefined behavior. Fixes rust-lang#42779 cc rust-lang#32408
1 parent 0356bb9 commit 050fb38

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/librustc_codegen_ssa/mir/debuginfo.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::traits::*;
22
use rustc_hir::def_id::CrateNum;
33
use rustc_index::vec::IndexVec;
4+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
45
use rustc_middle::mir;
56
use rustc_middle::ty;
67
use rustc_session::config::DebugInfo;
@@ -216,6 +217,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
216217
LocalRef::Operand(None) => return,
217218

218219
LocalRef::Operand(Some(operand)) => {
220+
// Don't spill operands onto the stack in naked functions.
221+
// See: https://github.com/rust-lang/rust/issues/42779
222+
let attrs = bx.tcx().codegen_fn_attrs(self.instance.def_id());
223+
if attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
224+
return;
225+
}
226+
219227
// "Spill" the value onto the stack, for debuginfo,
220228
// without forcing non-debuginfo uses of the local
221229
// to also load from the stack every single time.

0 commit comments

Comments
 (0)