about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-11-20 06:01:49 +0000
committerbors <bors@rust-lang.org>2020-11-20 06:01:49 +0000
commit5c45969502b9e13f3b536aa0e94a3b059e18b95c (patch)
treef02012d2178970395a50031fd82c7c38847599f1 /compiler/rustc_codegen_llvm/src
parent74285eb3a83eac639f9c54ba8c4ccf9879b3b00a (diff)
parentc2fb99984c2ed4b54f5b8baff26fcc04af71d032 (diff)
downloadrust-5c45969502b9e13f3b536aa0e94a3b059e18b95c.tar.gz
rust-5c45969502b9e13f3b536aa0e94a3b059e18b95c.zip
Auto merge of #79192 - tmiasko:naked-noinline, r=oli-obk
Never inline naked functions

The `#[naked]` attribute disabled prologue / epilogue emission for the
function and it is responsibility of a developer to provide them. The
compiler is no position to inline such functions correctly.

Disable inlining of naked functions at LLVM and MIR level.

Closes #60919.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/attributes.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs
index 9a2fbf359ea..62a7986c194 100644
--- a/compiler/rustc_codegen_llvm/src/attributes.rs
+++ b/compiler/rustc_codegen_llvm/src/attributes.rs
@@ -25,7 +25,7 @@ use crate::value::Value;
 
 /// Mark LLVM function to use provided inline heuristic.
 #[inline]
-fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr, requires_inline: bool) {
+fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr) {
     use self::InlineAttr::*;
     match inline {
         Hint => Attribute::InlineHint.apply_llfn(Function, val),
@@ -35,7 +35,6 @@ fn inline(cx: &CodegenCx<'ll, '_>, val: &'ll Value, inline: InlineAttr, requires
                 Attribute::NoInline.apply_llfn(Function, val);
             }
         }
-        None if requires_inline => Attribute::InlineHint.apply_llfn(Function, val),
         None => {}
     };
 }
@@ -226,7 +225,14 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
         }
     }
 
-    inline(cx, llfn, codegen_fn_attrs.inline.clone(), instance.def.requires_inline(cx.tcx));
+    let inline_attr = if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
+        InlineAttr::Never
+    } else if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
+        InlineAttr::Hint
+    } else {
+        codegen_fn_attrs.inline
+    };
+    inline(cx, llfn, inline_attr);
 
     // The `uwtable` attribute according to LLVM is:
     //