Skip to content

Commit c955add

Browse files
committed
Disable coverage instrumentation for naked functions
1 parent 32e613b commit c955add

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,10 @@ 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+
}
2079+
20762080
// Weak lang items have the same semantics as "std internal" symbols in the
20772081
// sense that they're preserved through all our LTO passes and only
20782082
// strippable by the linker.

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)