Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6554086
Add u128 and i128 integer tests
CDirkx Nov 14, 2020
69477f5
Clarify availability of atomic operations
Nov 17, 2020
b491587
Extract write_srclink to its own method
aDotInTheVoid Nov 18, 2020
1094f97
Test drop order for (destructuring) assignments
fanzier Nov 18, 2020
ae644a2
add [src] links to methods on a trait's page
aDotInTheVoid Nov 18, 2020
c711833
Qualify `panic!` as `core::panic!` in non-built-in `core` macros
camelid Oct 25, 2020
50b34c4
Clean up `core` macros documentation
camelid Oct 25, 2020
c48ed78
Add two more test cases
camelid Oct 29, 2020
a050c55
Remove unused `use std::panic;`s
camelid Oct 30, 2020
566e877
Make compiletest testing use the local sysroot
cuviper Nov 18, 2020
8afa22d
Never inline naked functions
tmiasko Nov 19, 2020
8247223
Revert "Always use param_env_reveal_all_normalized in validator"
tmiasko Nov 19, 2020
0ab4458
Revert "Normalize function type during validation"
tmiasko Nov 19, 2020
de08df2
Make as{_mut,}_slice on array::IntoIter public
est31 Nov 19, 2020
0510fd3
Update 32 bit mir-opt test output.
m-ou-se Nov 19, 2020
54588c8
Add jyn514 email alias to mailmap
pickfire Nov 19, 2020
b49fbc9
expand: Tell built-in macros whether we are currently in forced expan…
petrochenkov Nov 14, 2020
e7ee4d6
expand: Move `fully_configure` to `config.rs`
petrochenkov Nov 18, 2020
69894ce
resolve: Introduce a separate `NonMacroAttrKind` for legacy derive he…
petrochenkov Nov 18, 2020
68f94e9
resolve: Centralize some error reporting for unexpected macro resolut…
petrochenkov Nov 18, 2020
dfb690e
resolve/expand: Misc cleanup
petrochenkov Nov 18, 2020
ec54720
expand: Cleanup attribute collection in invocation collector
petrochenkov Nov 18, 2020
cd2177f
expand: Stop derive expansion un unexpected targets early
petrochenkov Nov 18, 2020
d575aa4
expand: Mark some dead code in derive expansion as unreachable
petrochenkov Nov 18, 2020
78c16cf
Rollup merge of #78343 - camelid:macros-qualify-panic, r=m-ou-se
Dylan-DPC Nov 19, 2020
3778485
Rollup merge of #79119 - jamesmunns:patch-1, r=Mark-Simulacrum
Dylan-DPC Nov 19, 2020
5a23e4a
Rollup merge of #79123 - CDirkx:128-bits, r=Mark-Simulacrum
Dylan-DPC Nov 19, 2020
34c9af1
Rollup merge of #79177 - fanzier:drop-order-test, r=RalfJung
Dylan-DPC Nov 19, 2020
ab648d1
Rollup merge of #79181 - aDotInTheVoid:provided-method-source-link, r…
Dylan-DPC Nov 19, 2020
7def739
Rollup merge of #79183 - cuviper:compiletest-test-sysroot, r=Mark-Sim…
Dylan-DPC Nov 19, 2020
cf82316
Rollup merge of #79185 - petrochenkov:derattr2, r=Aaron1011
Dylan-DPC Nov 19, 2020
b152b83
Rollup merge of #79192 - tmiasko:naked-noinline, r=oli-obk
Dylan-DPC Nov 19, 2020
cdff7bd
Rollup merge of #79193 - tmiasko:revert-78969-normalize, r=davidtwco
Dylan-DPC Nov 19, 2020
7acbc89
Rollup merge of #79194 - est31:array_into_iter_slice, r=scottmcm
Dylan-DPC Nov 19, 2020
822b420
Rollup merge of #79204 - pickfire:patch-3, r=jyn514
Dylan-DPC Nov 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
tmiasko committed Nov 19, 2020
commit 8afa22d24bf3c9bc7a5f5994eaf72017c6adcd61
2 changes: 1 addition & 1 deletion compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
}
}

#[derive(Clone, PartialEq, Encodable, Decodable)]
#[derive(Copy, Clone, PartialEq, Encodable, Decodable)]
pub enum InlineAttr {
None,
Hint,
Expand Down
12 changes: 9 additions & 3 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 => {}
};
}
Expand Down Expand Up @@ -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:
//
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_mir/src/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ impl Inliner<'tcx> {
self.tcx.sess.opts.debugging_opts.inline_mir_threshold
};

if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
debug!("#[naked] present - not inlining");
return false;
}

if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
debug!("#[cold] present - not inlining");
return false;
Expand Down
29 changes: 29 additions & 0 deletions src/test/codegen/naked-inline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Checks that naked functions are never inlined.
// compile-flags: -O -Zmir-opt-level=2
#![crate_type = "lib"]
#![feature(asm)]
#![feature(naked_functions)]

#[inline(always)]
#[naked]
#[no_mangle]
pub unsafe fn f() {
// Check that f has naked and noinline attributes.
//
// CHECK: define void @f() unnamed_addr [[ATTR:#[0-9]+]]
// CHECK-NEXT: start:
// CHECK-NEXT: call void asm
asm!("", options(noreturn));
}

#[no_mangle]
pub unsafe fn g() {
// Check that call to f is not inlined.
//
// CHECK-LABEL: define void @g()
// CHECK-NEXT: start:
// CHECK-NEXT: call void @f()
f();
}

// CHECK: attributes [[ATTR]] = { naked noinline{{.*}} }