Skip to content

Commit ed9a21e

Browse files
authored
Rollup merge of #105193 - tmiasko:naked-nocoverage, r=wesleywiser
Disable coverage instrumentation for naked functions Fixes #105170.
2 parents a739fc8 + b740cdc commit ed9a21e

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,12 @@ pub fn from_fn_attrs<'ll, 'tcx>(
258258
OptimizeAttr::Speed => {}
259259
}
260260

261-
let inline = if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
262-
InlineAttr::Never
263-
} else if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
264-
InlineAttr::Hint
265-
} else {
266-
codegen_fn_attrs.inline
267-
};
261+
let inline =
262+
if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
263+
InlineAttr::Hint
264+
} else {
265+
codegen_fn_attrs.inline
266+
};
268267
to_add.extend(inline_attr(cx, inline));
269268

270269
// The `uwtable` attribute according to LLVM is:

compiler/rustc_hir_analysis/src/collect.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,11 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
20732073
}
20742074
}
20752075

2076+
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
2077+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE;
2078+
codegen_fn_attrs.inline = InlineAttr::Never;
2079+
}
2080+
20762081
// Weak lang items have the same semantics as "std internal" symbols in the
20772082
// sense that they're preserved through all our LTO passes and only
20782083
// strippable by the linker.

compiler/rustc_mir_transform/src/inline.rs

-4
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,6 @@ impl<'tcx> Inliner<'tcx> {
363363
return Err("C variadic");
364364
}
365365

366-
if callee_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
367-
return Err("naked");
368-
}
369-
370366
if callee_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
371367
return Err("cold");
372368
}

src/test/codegen/naked-nocoverage.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Checks that naked functions are not instrumented by -Cinstrument-coverage.
2+
// Regression test for issue #105170.
3+
//
4+
// needs-asm-support
5+
// needs-profiler-support
6+
// compile-flags: -Cinstrument-coverage
7+
#![crate_type = "lib"]
8+
#![feature(naked_functions)]
9+
use std::arch::asm;
10+
11+
#[naked]
12+
#[no_mangle]
13+
pub unsafe extern "C" fn f() {
14+
// CHECK: define void @f()
15+
// CHECK-NEXT: start:
16+
// CHECK-NEXT: call void asm
17+
// CHECK-NEXT: unreachable
18+
asm!("", options(noreturn));
19+
}

0 commit comments

Comments
 (0)