Skip to content

Commit 7a2047a

Browse files
committed
Never inline naked functions
1 parent 114924a commit 7a2047a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/librustc_codegen_llvm/attributes.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,23 @@ pub fn from_fn_attrs(
245245
}
246246
}
247247

248-
// FIXME(eddyb) consolidate these two `inline` calls (and avoid overwrites).
249-
if instance.def.requires_inline(cx.tcx) {
250-
inline(cx, llfn, attributes::InlineAttr::Hint);
251-
}
248+
// Naked functions must never be inlined and must not contain any prologue
249+
// or epilogue.
250+
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
251+
naked(llfn, true);
252+
inline(cx, llfn, attributes::InlineAttr::Never);
253+
} else {
254+
set_frame_pointer_elimination(cx, llfn);
255+
set_instrument_function(cx, llfn);
256+
set_probestack(cx, llfn);
252257

253-
inline(cx, llfn, codegen_fn_attrs.inline);
258+
// FIXME(eddyb) consolidate these two `inline` calls (and avoid overwrites).
259+
if instance.def.requires_inline(cx.tcx) {
260+
inline(cx, llfn, attributes::InlineAttr::Hint);
261+
}
262+
263+
inline(cx, llfn, codegen_fn_attrs.inline);
264+
}
254265

255266
// The `uwtable` attribute according to LLVM is:
256267
//
@@ -272,19 +283,12 @@ pub fn from_fn_attrs(
272283
attributes::emit_uwtable(llfn, true);
273284
}
274285

275-
set_frame_pointer_elimination(cx, llfn);
276-
set_instrument_function(cx, llfn);
277-
set_probestack(cx, llfn);
278-
279286
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
280287
Attribute::Cold.apply_llfn(Function, llfn);
281288
}
282289
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_RETURNS_TWICE) {
283290
Attribute::ReturnsTwice.apply_llfn(Function, llfn);
284291
}
285-
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
286-
naked(llfn, true);
287-
}
288292
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR) {
289293
Attribute::NoAlias.apply_llfn(llvm::AttributePlace::ReturnValue, llfn);
290294
}

0 commit comments

Comments
 (0)