diff options
| author | bors <bors@rust-lang.org> | 2024-06-27 07:54:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-06-27 07:54:44 +0000 |
| commit | 127fa2261b730a42e6d98b7927c3888ecd08f3e0 (patch) | |
| tree | 4d5e70c87614e62e7b6ff51b5d376f95fbe257c1 /compiler/rustc_mir_transform/src | |
| parent | 536235f07e57c9108c6c3b1eacb323164e0f4cfb (diff) | |
| parent | 73016dc8a41a494ddacf1b7e5b3b6a7852b3a74a (diff) | |
| download | rust-127fa2261b730a42e6d98b7927c3888ecd08f3e0.tar.gz rust-127fa2261b730a42e6d98b7927c3888ecd08f3e0.zip | |
Auto merge of #127014 - jhpratt:rollup-45ic8f5, r=jhpratt
Rollup of 6 pull requests Successful merges: - #126571 (Less `maybe_whole_expr`, take 2) - #126721 (coverage: Make `#[coverage(..)]` apply recursively to nested functions) - #126928 (Some `Nonterminal` removal precursors) - #126929 (Remove `__rust_force_expr`.) - #126980 (set self.is_known_utf8 to false in extend_from_slice) - #126983 (Remove `f16` and `f128` ICE paths from smir) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/query.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/query.rs b/compiler/rustc_mir_transform/src/coverage/query.rs index 25744009be8..1fce2abbbbf 100644 --- a/compiler/rustc_mir_transform/src/coverage/query.rs +++ b/compiler/rustc_mir_transform/src/coverage/query.rs @@ -6,11 +6,13 @@ use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::util::Providers; use rustc_span::def_id::LocalDefId; +use rustc_span::sym; /// Registers query/hook implementations related to coverage. pub(crate) fn provide(providers: &mut Providers) { providers.hooks.is_eligible_for_coverage = |TyCtxtAt { tcx, .. }, def_id| is_eligible_for_coverage(tcx, def_id); + providers.queries.coverage_attr_on = coverage_attr_on; providers.queries.coverage_ids_info = coverage_ids_info; } @@ -38,7 +40,12 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { return false; } - if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_COVERAGE) { + if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NAKED) { + trace!("InstrumentCoverage skipped for {def_id:?} (`#[naked]`)"); + return false; + } + + if !tcx.coverage_attr_on(def_id) { trace!("InstrumentCoverage skipped for {def_id:?} (`#[coverage(off)]`)"); return false; } @@ -46,6 +53,30 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { true } +/// Query implementation for `coverage_attr_on`. +fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { + // Check for annotations directly on this def. + if let Some(attr) = tcx.get_attr(def_id, sym::coverage) { + match attr.meta_item_list().as_deref() { + Some([item]) if item.has_name(sym::off) => return false, + Some([item]) if item.has_name(sym::on) => return true, + Some(_) | None => { + // Other possibilities should have been rejected by `rustc_parse::validate_attr`. + tcx.dcx().span_bug(attr.span, "unexpected value of coverage attribute"); + } + } + } + + match tcx.opt_local_parent(def_id) { + // Check the parent def (and so on recursively) until we find an + // enclosing attribute or reach the crate root. + Some(parent) => tcx.coverage_attr_on(parent), + // We reached the crate root without seeing a coverage attribute, so + // allow coverage instrumentation by default. + None => true, + } +} + /// Query implementation for `coverage_ids_info`. fn coverage_ids_info<'tcx>( tcx: TyCtxt<'tcx>, |
