Skip to content

Commit

Permalink
Disable coverage instrumentation for naked functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Dec 3, 2022
1 parent 32e613b commit c955add
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
}
}

if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE;
}

// Weak lang items have the same semantics as "std internal" symbols in the
// sense that they're preserved through all our LTO passes and only
// strippable by the linker.
Expand Down
19 changes: 19 additions & 0 deletions src/test/codegen/naked-nocoverage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Checks that naked functions are not instrumented by -Cinstrument-coverage.
// Regression test for issue #105170.
//
// needs-asm-support
// needs-profiler-support
// compile-flags: -Cinstrument-coverage
#![crate_type = "lib"]
#![feature(naked_functions)]
use std::arch::asm;

#[naked]
#[no_mangle]
pub unsafe extern "C" fn f() {
// CHECK: define void @f()
// CHECK-NEXT: start:
// CHECK-NEXT: call void asm
// CHECK-NEXT: unreachable
asm!("", options(noreturn));
}

0 comments on commit c955add

Please sign in to comment.