about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNathaniel McCallum <npmccallum@redhat.com>2020-08-11 14:09:39 -0400
committerNathaniel McCallum <npmccallum@redhat.com>2020-08-11 15:02:03 -0400
commit050fb380aaa5f95ca27d6365cea06ea614c4cbf7 (patch)
tree7e441eb0b6a51c9d17cc1d028c44509a84348597
parent0356bb9fbba55f0a8fbe38731d41f57048f2e00b (diff)
downloadrust-050fb380aaa5f95ca27d6365cea06ea614c4cbf7.tar.gz
rust-050fb380aaa5f95ca27d6365cea06ea614c4cbf7.zip
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 https://github.com/rust-lang/rust/issues/42779
cc https://github.com/rust-lang/rust/issues/32408
-rw-r--r--src/librustc_codegen_ssa/mir/debuginfo.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/librustc_codegen_ssa/mir/debuginfo.rs b/src/librustc_codegen_ssa/mir/debuginfo.rs
index d166a27b5a9..d8a530d98fa 100644
--- a/src/librustc_codegen_ssa/mir/debuginfo.rs
+++ b/src/librustc_codegen_ssa/mir/debuginfo.rs
@@ -1,6 +1,7 @@
 use crate::traits::*;
 use rustc_hir::def_id::CrateNum;
 use rustc_index::vec::IndexVec;
+use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
 use rustc_middle::mir;
 use rustc_middle::ty;
 use rustc_session::config::DebugInfo;
@@ -216,6 +217,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
             LocalRef::Operand(None) => return,
 
             LocalRef::Operand(Some(operand)) => {
+                // Don't spill operands onto the stack in naked functions.
+                // See: https://github.com/rust-lang/rust/issues/42779
+                let attrs = bx.tcx().codegen_fn_attrs(self.instance.def_id());
+                if attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
+                    return;
+                }
+
                 // "Spill" the value onto the stack, for debuginfo,
                 // without forcing non-debuginfo uses of the local
                 // to also load from the stack every single time.